| 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 |
!!! Note |
| 15 |
|
| 16 |
This extension is in __maintenance mode__. We will continue to fix bugs |
| 17 |
and keep it up-to-date with the core parser, but no new features or |
| 18 |
changes in behavior will be made. If you need a feature that this |
| 19 |
extension does not offer, then you have three options (1) find an |
| 20 |
existing [third-party extension] which meets your needs, (2) [build your |
| 21 |
own extension], or (3) fork this extension (pursuant to its licensing |
| 22 |
requirements) and maintain it as a third-party extension. |
| 23 |
|
| 24 |
[third-party extension]: index.md#third-party-extensions |
| 25 |
[build your own extension]: api.md |
| 26 |
|
| 27 |
## Syntax |
| 28 |
|
| 29 |
Attributes are defined by including the following within the element you wish to |
| 30 |
assign the attributes to: |
| 31 |
|
| 32 |
```md |
| 33 |
{@key=value} |
| 34 |
``` |
| 35 |
|
| 36 |
For example, to define a class to a paragraph: |
| 37 |
|
| 38 |
```md |
| 39 |
A paragraph with the attribute defined {@class=foo}anywhere within. |
| 40 |
``` |
| 41 |
|
| 42 |
Which results in the following output: |
| 43 |
|
| 44 |
```html |
| 45 |
<p class="foo">A paragraph with the attribute defined anywhere within.</p> |
| 46 |
``` |
| 47 |
|
| 48 |
The same applies for inline elements: |
| 49 |
|
| 50 |
```md |
| 51 |
Some *emphasized{@id=bar}* text. |
| 52 |
``` |
| 53 |
|
| 54 |
```html |
| 55 |
<p>Some <em id="bar">emphasized</em> text.</p> |
| 56 |
``` |
| 57 |
|
| 58 |
You can also define attributes in images: |
| 59 |
|
| 60 |
```md |
| 61 |
 |
| 62 |
``` |
| 63 |
|
| 64 |
```html |
| 65 |
<p><img alt="Alt text" id="baz" src="path/to/image.jpg" /></p> |
| 66 |
``` |
| 67 |
|
| 68 |
## Usage |
| 69 |
|
| 70 |
See [Extensions](index.md) for general extension usage. Use `legacy_attrs` as the |
| 71 |
name of the extension. |
| 72 |
|
| 73 |
This extension does not accept any special configuration options. |
| 74 |
|
| 75 |
A trivial example: |
| 76 |
|
| 77 |
```python |
| 78 |
markdown.markdown(some_text, extensions=['legacy_attrs']) |
| 79 |
``` |