A security and bug-fix release.
Plugin renderers now escape user content in HTML attribute, label and math positions,
attrs drops event-handler attributes by default and validates URL-valued attributes,
and the regular expressions in texmath ```math blocks and admon headers no longer backtrack polynomially (#143).
It also fixes parser hangs in gfm_autolink (#160) and texmath (#156),
and adds the section_ref plugin.
The release requires markdown-it-py >= 3.0 and supports Python 3.10 to 3.14.
Several fixes change rendered output: see Upgrade notes below.
- Requires markdown-it-py >= 3.0 (#170).
The declared floor was 2.0, but 0.5.0 and later already failed to import
subscriptwith markdown-it-py 2.x.section_ref,gfmandgfm_autolinkstill need markdown-it-py >= 4.1 and raiseRuntimeErroron older versions. Python 3.10 to 3.14 are supported. attrs_plugin/attrs_block_plugindefaults are stricter (#150). With noallowedlist, event-handler attributes (any key starting withon, in any case) are removed and moved totoken.meta["insecure_attrs"];styleis kept. Whateverallowedsays,href,src,action,formactionandxlink:hrefare removed whenmd.validateLinkrejects their value, so[a](https://x){href="javascript:alert(1)"}keepshref="https://x". Text spans ([text]{...}) now honourallowed, which they used to bypass. This is a baseline, not a sanitiser: for untrusted input, pass an explicit list such asallowed=("id", "class").- Renderers escape their output (#150, #165).
The
texmathdefault renderer HTML-escapes the math source ($a<b$now renders<eq>a<b</eq>), and thedollarmathequation label, themyst_blocktarget label, thecolon_fenceclass name and thetasklistslabel_afterlabel are escaped too. Benign text containing&,<,>or"in these positions is now emitted as entities. anchors_pluginids can change (#159). An explicit heading id (such as{#custom}fromattrs_block_plugin) is now kept instead of being overwritten, and generated slugs avoid it. The default slug function no longer strips whitespace from the title, matching MyST-Parser'sgithub_slugify: a title that starts or ends with a space next to an image, raw HTML or an entity gets a different id (# Foo now givesfoo-, it wasfoo). To keep the old ids, passslug_func=lambda title: slugify(title.strip()), withslugifyfrommdit_py_plugins.anchors.index.mdit_py_plugins.attrs.parse.parse()raises on an unterminated attribute group, instead of succeeding at the end of the string (#153). Every plugin call site declines the group, so`a`{.anow renders<code>a</code>{.a; it used to drop the{.a.- The
section_reftoken shape is public API (#169): see its entry below.
Thanks to @KrisKennawayDD for reporting these issues in #143, and to @KyleKing for the ReDoS analysis and fixes.
-
π FIX: Escape plugin renderer output and harden the
attrsdefaults, thanks to @KyleKing for the cross-plugin XSS test (#150, folding in #151)With markdown-it-py's
htmloption off, untrusted Markdown could still inject HTML or script through: thetexmathdefault renderer (math source), thedollarmathequation label (idand permalinkhref), themyst_block(name)=target label, andattrs/attrs_blockevent-handler andjavascript:URL attributes. All of these are now escaped or filtered (see Upgrade notes), andtests/test_xss.pyrenders injection probes through each plugin's default renderer. -
π FIX: Escape the
colon_fenceclass name and thetasklistslabel_afterlabel (#165):::a"onmouseover="alert(1)rendered an attribute-breakingclass="block-a"onmouseover="alert(1)", and- [ ] <img src=x onerror=alert(1)>withlabel=True, label_after=Truerendered a raw<img>. -
π FIX: ReDoS in
texmath```mathblocks andadmonheaders, thanks to @KyleKing (#148)The
texmath```mathpatterns (thegitlabandjuliadelimiters) backtracked cubically on a fence followed by a long whitespace run with no closing fence, and theadmonmulti-tag title pattern backtracked quadratically on a header with a long run of spaces or double quotes. Both now run in linear time and match what they matched before, so output is unchanged.
-
β¨ NEW: Add the section reference plugin (
section_ref) (#144, #168, #169)The
section_refplugin captures section-sign references, the syntax LLMs commonly use to point at numbered headings, into dedicatedsection_reftokens, so downstream renderers (e.g. MyST-Parser) can resolve them to heading cross-references:See Β§1, Β§1.1 and Β§2.3.4 for details.
A
Β§must be immediately followed by one or more.-separated levels of 1 to 9 ASCII digits, with no spaces. A trailing.is not part of the reference, and a reference directly followed by an ASCII letter (Β§1a), or with a level longer than nine digits, stays literal text. Each reference is asection_refleaf token whosecontentis the text as written and whosemeta["numbers"]lists each level as an int (e.g.[1, 1]forΒ§1.1). The grammar and the token shape are documented in the plugin docstring and are public API from this release. It renders as<span class="section-ref">Β§1.1</span>by default.Requires markdown-it-py >= 4.1.0.
-
π FIX:
gfm_autolinkno longer hangs on autolink-like text in link labels (#160), thanks to @AryanRG (#161) -
π FIX:
texmathno longer loops forever on block math opened in a blockquote and closed after it (#156), thanks to @acaprino (#157) -
π FIX:
dollarmath: a same-line$$β¦$$followed by text no longer swallows the following lines (#147), thanks to @KyleKing (#149) -
π FIX:
dollarmath: multi-line$$blocks in a blockquote no longer keep the>prefixes in their content (#125), thanks to @BetterAndBetterII (#152) -
π FIX:
front_matter: parse front matter closed by the YAML...document-end marker, thanks to @feiiiiii5 (#158)A block closed by
...used to leak into the document as text when the...was the document's last line or had trailing spaces, and otherwise kept the...intoken.content. The marker must be at column 0 and may be followed by spaces only. -
π FIX:
footnote: reserve an inline footnote's id before parsing its content, thanks to @civilwarinfrance (#162)A
[^named]reference or a nested^[...]inside an inline footnote no longer loses the inner note, duplicates an id, or raisesKeyError: 'count'. -
π FIX:
anchors: keep explicit heading ids, and do not strip slug titles, thanks to @muneikh (#159) -
π FIX:
attrs: unterminated groups, class accumulation and closing-token merge (#153)An unterminated attribute group no longer swallows the text after it. Classes from adjacent attribute groups are combined on spans and links (
[a]{.x}{.y}givesclass="x y"), as they already were on inline code and images. An attributes block at the end of a container is no longer merged onto the closing token (> {.a}rendered</blockquote class="a">). -
π FIX:
myst_roleno longer rejects a role at the start of inline content when the content ends with a backslash, and\\{name}`x`(an escaped backslash before a role) now parses the role (#62) (#145)
- π DOCS: Explain front matter extraction and HTML rendering (#133), thanks to @Gonghan-Princess (#154)
- π DOCS: A runnable usage example (#44), the
dollarmathrendering contract and a "Rendering dollarmath output" guide (#111), and Read the Docs builds on Python 3.13 (#166)
- π§ Require markdown-it-py >= 3.0, test the floor and Python 3.14 in CI, and update the classifiers (#170)
- π§ Releases are published to PyPI with trusted publishing (#141), with attestations (#142),
from distributions built with
python -m buildand checked on every pull request (#164) - π§ pre-commit autoupdate (ruff 0.17, mypy 2.4) with a pinned ruff base rule set (#138), and a non-blocking Codecov upload (#167)
Full Changelog: https://github.com/executablebooks/mdit-py-plugins/compare/v0.6.1...v0.7.0
-
π FIX: Nested field lists incorrectly nesting inside parent containers (#139)
Field lists inside list items (or other indented containers) would recursively nest each field inside the previous one, instead of being siblings.
-
β¨ NEW: Add GFM autolink and composite GFM plugins (#135)
The
gfm_autolinkplugin implements GFM autolink literals, auto-linking URLs and email addresses without requiring angle brackets:Visit www.example.com or contact user@example.com
The
gfmcomposite plugin enables a full Github Flavored Markdown (GFM)-like configuration in a single call (tables, strikethrough, autolinks, task lists, alerts, and footnotes).See the GitHub docs for more information.
Requires markdown-it-py >= 4.1.0.
-
β¨ NEW: Add superscript plugin and tests, thanks to @elijahgreenstein (#128)
Ported from markdown-it-sup. Renders superscript text using
^..^syntax:29^th^ of May
- β¬οΈ Drop Python 3.9, which is EoL next month https://devguide.python.org/versions and allow for the, soon to be released, markdown-it-py v4.
- β¨ NEW: Add plugin & tests to render subscripts, thanks to @miteshashar
-
π Improve parsing of nested amsmath
The previous logic was problematic for amsmath blocks nested in other blocs (such as blockquotes)
The new parsing code now principally follows the logic in
markdown_it/rules_block/fence.py(see also https://spec.commonmark.org/0.30/#fenced-code-blocks), except that:- it allows for a closing tag on the same line as the opening tag, and
- it does not allow for an opening tag without closing tag (i.e. no auto-closing)
-
β¨ Add
allowedoption for inline/block attributesThe
allowedoption accepts a list of allowed attribute names. If notNone, any attributes not in this list will be removed and placed in the token's meta under the key"insecure_attrs".
-
π Add option for footnotes references to always be matched
Usually footnote references are only matched when a footnote definition of the same label has already been found. If
always_match_refs=True, any[^...]syntax will be treated as a footnote.
-
β¬οΈ UPGRADE: Drop python 3.7 and support 3.11 (#77)
-
β¬οΈ UPGRADE: Allow markdown-it-py v3 (#85)
- π Make field_list compatible with latest upstream (#75)
- π§ Convert
state.srcCharCode->state.src(#84) - π§ Remove unnecessary method arg by @chrisjsewell in( #76)
- π Centralise code block test (#83 and #87)
- This means that disabling the
codeblock rule in markdown-it-py v3+ will now allow all syntax blocks to be indented by any amount of whitespace.
- This means that disabling the
-
π Improve
dollarmathplugin: Addallow_blank_linesoption, thanks to @eric-wieser (#46) -
π Improve
admonplugin: Add???support, thanks to @KyleKing (#58) -
π§ MAINTAIN: Make type checking strict (#86)
Full Changelog: https://github.com/executablebooks/mdit-py-plugins/compare/v0.3.5...v0.4.0
- π FIX: Regression in dollarmath by @chrisjsewell in #69
- π Fix regression in amsmath by @chrisjsewell in #70
- π§ Correct project documentation link by @andersk in #73
- β¨ NEW: Add attrs_block_plugin by @chrisjsewell in #66
- π Improve field lists by @chrisjsewell in #65
- π§ Update pre-commit by @chrisjsewell in #64 (moving from flake8 to ruff)
Full Changelog: v0.3.3...v0.3.
π FIX: span with end of inline before attrs
- β¨ NEW: Port
admonplugin by @KyleKing (#53) - β¨ NEW: Add span parsing to inline attributes plugin by @chrisjsewell (#55)
- π FIX: Task list item marker can be followed by any GFM whitespace by @hukkin in (#42)
Full Changelog: v0.3.1...v0.4.0
- β¬οΈ UPGRADE: Drop Python 3.6, support Python 3.10
- π FIX: Parsing when newline is between footnote ID and first paragraph
- π FIX: Anchor ids in separate renders no longer affect each other.
- β¨ NEW: Add
attrs_plugin - π§ MAINTAIN: Use flit PEP 621 package build
- β¬οΈ UPGRADE: Compatible with markdown-it-py
v2. - β¨ NEW: Add field list plugin, Based on the restructuredtext syntax
- β»οΈ REFACTOR: dollarmath plugin,
math_block_eqno->math_block_labeltoken - β»οΈ REFACTOR: Remove AttrDict usage from texmath
- π IMPROVE: Default HTML rendering for dollarmath and amsmath plugins
- π IMPROVE: Add render options for dollarmath and amsmath plugins
- π IMPROVE: MyST parsing of target blocks (allow whitespace) and roles (allow for new lines)
π FIX: wordcount update of minutes
- β¬οΈ UPDATE: markdown-it-py~=1.0
- β¨ NEW: Add
wordcount_plugin - π IMPROVE:
dollarmath: Allow inline double-dollar - π IMPROVE:
myst_blocks: Parse multiline comments - π IMPROVE: Replace use of
envas anAttrDict - π FIX:
front_matter: don't duplicate content storage inToken.meta
π IMPROVE: Remove direct use of Token.attrs
π FIX: front-matter: IndexError if first line is single dash
β¨ NEW: Add substitution_plugin (improvements in 0.2.3 and 0.2.4)
Add mypy type-checking, code taken from: https://github.com/executablebooks/markdown-it-py/commit/2eb1fe6b47cc0ad4ebe954cabd91fb8e52a2f03d
First release, code taken from: https://github.com/executablebooks/markdown-it-py/commit/3a5bdcc98e67de9df26ebb8bc7cd0221a0d6b51b