You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of storing `attrs` as `[["key1", "value1"], ["key2", "value2"]]`,
use `{"key1": "value1", "key2": "value2"}`.
Upstream the list format is only used to guarantee order: markdown-it/markdown-it#142,
but in Python 3.7+ dictionary order is now guaranteed by the specification
(in Python 3.6 it is also preserved as an implementation detail).
This change improves typing and performance.
One should anyhow generally use the `attrGet`, `attrSet`, `attrPush` and `attrJoin` methods
to manipulate `Token.attrs`, which all have an identical signature to those upstream.
To minimize how breaking this change is,
auto-conversion is done on `Token` initiation,
i.e. you can still use `Token("type", "tag", 0, attrs=[["key", "value"]])`,
and also `Token.as_dict(as_upstream=True)` converts the dict back to `null`/`list`,
o that they can still be directly compared to those produced in the `debug` tab of https://markdown-it.github.io/.
The `meta_serializer` option has also been added to `Token.as_dict`,
which now ensures that this method is always able to produce valid JSON.
The `linkify` component requires that [linkify-it-py](https://github.com/tsutsu3/linkify-it-py) be installed (e.g. *via*`pip install markdown-it-py[linkify]`).
152
152
This allows URI autolinks to be identified, without the need for enclosing in `<>` brackets:
153
153
154
-
```{code-cell}
154
+
```{code-cell} python
155
155
md = MarkdownIt("commonmark", {"linkify": True})
156
156
md.enable(["linkify"])
157
157
md.render("github.com")
@@ -161,7 +161,7 @@ md.render("github.com")
161
161
162
162
Plugins load collections of additional syntax rules and render methods into the parser
163
163
164
-
```{code-cell}
164
+
```{code-cell} python
165
165
from markdown_it import MarkdownIt
166
166
from markdown_it.extensions.front_matter import front_matter_plugin
167
167
from markdown_it.extensions.footnote import footnote_plugin
@@ -194,7 +194,7 @@ md.render(text)
194
194
195
195
Before rendering, the text is parsed to a flat token stream of block level syntax elements, with nesting defined by opening (1) and closing (-1) attributes:
196
196
197
-
```{code-cell}
197
+
```{code-cell} python
198
198
md = MarkdownIt("commonmark")
199
199
tokens = md.parse("""
200
200
Here's some *text*
@@ -208,37 +208,37 @@ Here's some *text*
208
208
Naturally all openings should eventually be closed,
209
209
such that:
210
210
211
-
```{code-cell}
211
+
```{code-cell} python
212
212
sum([t.nesting for t in tokens]) == 0
213
213
```
214
214
215
215
All tokens are the same class, which can also be created outside the parser:
0 commit comments