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 docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ See the [Contributing Guide](contributing.md) for details.

* Fix quadratic-time id generation in the `toc` extension when many headers
share the same text.
* Ignore glossary abbreviations with empty definitions after inline elements,
consistently with abbreviations before inline elements.
* Strip complete HTML tags with quoted `>` characters from `toc` labels and
generated heading IDs.
* Fix quadratic-time regex backtracking in `attr_list` when a block ends with an
Expand Down
7 changes: 4 additions & 3 deletions markdown/extensions/abbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ def iter_element(self, el: etree.Element, parent: etree.Element | None = None) -
index = list(parent).index(el) + 1
if not isinstance(tail, AtomicString):
for m in reversed(list(self.RE.finditer(tail))):
abbr = self.create_element(self.abbrs[m.group(0)], m.group(0), tail[m.end():])
parent.insert(index, abbr)
tail = tail[:m.start()]
if self.abbrs[m.group(0)]:
abbr = self.create_element(self.abbrs[m.group(0)], m.group(0), tail[m.end():])
parent.insert(index, abbr)
tail = tail[:m.start()]
el.tail = tail

def run(self, root: etree.Element) -> etree.Element | None:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_syntax/extensions/test_abbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ def test_abbr_glossary(self):
extensions=[AbbrExtension(glossary=glossary)]
)

def test_abbr_glossary_empty_definition(self):
self.assertMarkdownRenders(
'HTML W3C HTML *word* HTML W3C HTML',
'<p>HTML <abbr title="World Wide Web Consortium">W3C</abbr> HTML '
'<em>word</em> HTML <abbr title="World Wide Web Consortium">W3C</abbr> HTML</p>',
extensions=[AbbrExtension(glossary={'HTML': '', 'W3C': 'World Wide Web Consortium'})]
)

def test_abbr_glossary_2(self):

glossary = {
Expand Down
Loading