• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1title: Legacy Attributes Extension
2
3# Legacy Attributes
4
5## Summary
6
7The Legacy Attributes extension restores Python-Markdown's original attribute
8setting syntax. Older versions of Python Markdown (prior to 3.0) included
9built-in and undocumented support for defining attributes on elements. Most
10users have never made use of the syntax and it has been deprecated in favor of
11[Attribute Lists](attr_list.md). This extension restores the legacy behavior for
12users who have existing documents which use the syntax.
13
14## Syntax
15
16Attributes are defined by including the following within the element you wish to
17assign the attributes to:
18
19```md
20{@key=value}
21```
22
23For example, to define a class to a paragraph:
24
25```md
26A paragraph with the attribute defined {@class=foo}anywhere within.
27```
28
29Which results in the following output:
30
31```html
32<p class="foo">A paragraph with the attribute defined anywhere within.</p>
33```
34
35The same applies for inline elements:
36
37```md
38Some *emphasized{@id=bar}* text.
39```
40
41```html
42<p>Some <em id="bar">emphasized</em> text.</p>
43```
44
45You can also define attributes in images:
46
47```md
48![Alt text{@id=baz}](path/to/image.jpg)
49```
50
51```html
52<p><img alt="Alt text" id="baz" src="path/to/image.jpg" /></p>
53```
54
55## Usage
56
57See [Extensions](index.md) for general extension usage. Use `legacy_attrs` as the
58name of the extension.
59
60This extension does not accept any special configuration options.
61
62A trivial example:
63
64```python
65markdown.markdown(some_text, extensions=['legacy_attrs'])
66```
67