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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## python-markdown2 2.5.6 (not yet released)

- [pull #762] Speed up documents with many links by skipping the backslash-escape scan for text without a backslash
- [pull #746] Preserve query strings and fragments in `markdown-file-links` conversions, including reference-link targets.
- [pull #739] Fix `header-ids` extra putting sanitized HTML into header ids in safe mode, which allowed attribute injection (#649)
- [pull #732] Fix excessive CPU use in the inline HTML tokenizer on repeated unclosed tag fragments (#707)
Expand Down
3 changes: 3 additions & 0 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,9 @@ def incomplete_tags_sub(match):
return text

def _encode_backslash_escapes(self, text: str) -> str:
# Every search string below starts with a backslash.
if '\\' not in text:
return text
for ch, escape in list(self._escape_table.items()):
text = text.replace("\\"+ch, escape)
return text
Expand Down
11 changes: 11 additions & 0 deletions test/test_markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ def test_many_distinct_code_spans(self):
expected = '\n\n'.join('<p><code>value_%s</code></p>' % i for i in range(1000)) + '\n'
self.assertEqual(markdown2.markdown(source), expected)

def test_many_links_with_backslash_escapes(self):
link = 'Paragraph %s has [a link](https://example.com/%s).'
html = ('<p>Paragraph %s has '
'<a href="https://example.com/%s">a link</a>.</p>')
escaped = r'An \*escaped\* star and a C:\dir path.'
source = '\n\n'.join([link % (i, i) for i in range(1000)] + [escaped])
expected = '\n\n'.join(
[html % (i, i) for i in range(1000)]
+ [r'<p>An *escaped* star and a C:\dir path.</p>']) + '\n'
self.assertEqual(markdown2.markdown(source), expected)

def test_unescape_nested_tokens(self):
md = markdown2.Markdown()
md.reset()
Expand Down
Loading