Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

**Requires markdown-it-py >= 4.1.0.**

- 🐛 FIX: `myst_role` no longer mis-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)

## 0.6.1 - 2026-05-13

- 🐛 FIX: Nested field lists incorrectly nesting inside parent containers (#139)
Expand Down
11 changes: 3 additions & 8 deletions mdit_py_plugins/myst_role/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ def myst_role_plugin(md: MarkdownIt) -> None:


def myst_role(state: StateInline, silent: bool) -> bool:
# note ``\{`` escaping is handled by the core ``escape`` rule,
# which runs before this rule

# check name
match = VALID_NAME_PATTERN.match(state.src[state.pos :])
if not match:
return False
name = match.group(1)

# check for starting backslash escape
try:
if state.src[state.pos - 1] == "\\":
# escaped (this could be improved in the case of edge case '\\{')
return False
except IndexError:
pass

# scan opening tick length
start = pos = state.pos + match.end()
try:
Expand Down
21 changes: 21 additions & 0 deletions tests/fixtures/myst_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,24 @@ Escaped:
.
<p>{abc}<code>xyz</code></p>
.

Role at start with trailing backslash (#62):
.
{foo}`ar`\
.
<p><code class="myst role">{foo}[ar]</code>\</p>
.

Escaped role backslash:
.
\{foo}`x`
.
<p>{foo}<code>x</code></p>
.

Escaped double backslash before role (#62):
.
\\{foo}`x`
.
<p>\<code class="myst role">{foo}[x]</code></p>
.
Loading