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