Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0ad5b0a

Browse files
Abbr should respect AtomicStrings
Fixes #1512
1 parent 6347c57 commit 0ad5b0a

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

‎.pyspelling.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ matrix:
2020
- alt
2121
ignores:
2222
- 'code, pre'
23+
- '.autorefs-internal[title]'
2324
captures:
2425
- '[role=main] *|*:not(script,style)'
2526
- pyspelling.filters.context:

‎docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
* `md_in_html` handle tags within inline code blocks better (#1075).
2626
* `md_in_html` fix handling of one-liner block HTML handling (#1074).
2727
* Ensure `<center>` is treated like a block-level element (#1481).
28+
* Ensure that `abbr` extension respects `AtomicString` and does not process
29+
perceived abbreviations in these strings (#1512).
2830

2931
## [3.7] -- 2024年08月16日
3032

‎markdown/extensions/abbr.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,22 @@ def iter_element(self, el: etree.Element, parent: etree.Element | None = None) -
9898
for child in reversed(el):
9999
self.iter_element(child, el)
100100
if text := el.text:
101-
for m in reversed(list(self.RE.finditer(text))):
102-
if self.abbrs[m.group(0)]:
103-
abbr = self.create_element(self.abbrs[m.group(0)], m.group(0), text[m.end():])
104-
el.insert(0, abbr)
105-
text = text[:m.start()]
106-
el.text = text
101+
if not isinstance(text, AtomicString):
102+
for m in reversed(list(self.RE.finditer(text))):
103+
if self.abbrs[m.group(0)]:
104+
abbr = self.create_element(self.abbrs[m.group(0)], m.group(0), text[m.end():])
105+
el.insert(0, abbr)
106+
text = text[:m.start()]
107+
el.text = text
107108
if parent is not None and el.tail:
108109
tail = el.tail
109110
index = list(parent).index(el) + 1
110-
for m in reversed(list(self.RE.finditer(tail))):
111-
abbr = self.create_element(self.abbrs[m.group(0)], m.group(0), tail[m.end():])
112-
parent.insert(index, abbr)
113-
tail = tail[:m.start()]
114-
el.tail = tail
111+
if not isinstance(tail, AtomicString):
112+
for m in reversed(list(self.RE.finditer(tail))):
113+
abbr = self.create_element(self.abbrs[m.group(0)], m.group(0), tail[m.end():])
114+
parent.insert(index, abbr)
115+
tail = tail[:m.start()]
116+
el.tail = tail
115117

116118
def run(self, root: etree.Element) -> etree.Element | None:
117119
''' Step through tree to find known abbreviations. '''

‎tests/test_syntax/extensions/test_abbr.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ class TestAbbr(TestCase):
3030

3131
default_kwargs = {'extensions': ['abbr']}
3232

33+
def test_ignore_atomic(self):
34+
self.assertMarkdownRenders(
35+
self.dedent(
36+
"""
37+
This <https://example.com/{YAFR}>
38+
39+
*[YAFR]: Yet Another Feature Request
40+
"""
41+
),
42+
'<p>This <a href="https://example.com/{YAFR}">https://example.com/{YAFR}</a></p>'
43+
)
44+
3345
def test_abbr_upper(self):
3446
self.assertMarkdownRenders(
3547
self.dedent(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /