Skip to content

Commit 9c94380

Browse files
committed
🐛 FIX: attrs: span with end of inline before attrs
1 parent 881dcdc commit 9c94380

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

mdit_py_plugins/attrs/index.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def attrs_plugin(
1212
*,
1313
after=("image", "code_inline", "link_close", "span_close"),
1414
spans=False,
15+
span_after="link",
1516
):
1617
"""Parse inline attributes that immediately follow certain inline elements::
1718
@@ -42,7 +43,7 @@ def attrs_plugin(
4243
which all require post-parse processing.
4344
:param spans: If True, also parse attributes after spans of text, encapsulated by `[]`.
4445
Note Markdown link references take precedence over this syntax.
45-
46+
:param span_after: The name of an inline rule after which spans may be specified.
4647
"""
4748

4849
def _attr_rule(state: StateInline, silent: bool):
@@ -67,7 +68,7 @@ def _attr_rule(state: StateInline, silent: bool):
6768
return True
6869

6970
if spans:
70-
md.inline.ruler.after("link", "span", _span_rule)
71+
md.inline.ruler.after(span_after, "span", _span_rule)
7172
md.inline.ruler.push("attr", _attr_rule)
7273

7374

@@ -98,6 +99,10 @@ def _span_rule(state: StateInline, silent: bool):
9899

99100
pos = labelEnd + 1
100101

102+
# check not at end of inline
103+
if pos >= maximum:
104+
return False
105+
101106
try:
102107
new_pos, attrs = parse(state.src[pos:])
103108
except ParseError:

tests/fixtures/attrs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ spans: simple
6868
<p><span id="id" class="b">a</span>c</p>
6969
.
7070

71+
spans: end of inline before attrs
72+
.
73+
[a]
74+
.
75+
<p>[a]</p>
76+
.
77+
7178
spans: space between brace and attrs
7279
.
7380
[a] {.b}

0 commit comments

Comments
 (0)