Skip to content
Open
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 #778] Fix backslash-escaped quotes in link and image titles being rendered as a literal `"`
- [pull #762] Speed up documents with many links by skipping the backslash-escape scan for text without a backslash
- [pull #748] Speed up `_unescape_special_chars` by skipping text with no hashes and dropping the full-text comparison per pass (#635)
- [pull #749] URL-encode destinations generated by the `link-patterns` extra (#55)
Expand Down
3 changes: 3 additions & 0 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3423,6 +3423,9 @@ def run(self, text: str):
if self.md.safe_mode:
# expose span contents for escaping - fix #691, #703
title = self.md._unhash_html_spans(title, spans=True, code=True)
# A backslash-escaped quote is just a quote. Left in, `\"` becomes `\"`, which the
# escaped-ampersand handling then turns into a literal `"` in the title.
title = title.replace('\\"', '"').replace("\\'", "'")
title = (
_xml_escape_attr(title)
.replace('*', self.md._escape_table['*'])
Expand Down
7 changes: 7 additions & 0 deletions test/tm-cases/link_title_escaped_quotes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p><a href="http://example.com" title="Say &quot;hi&quot;">Inline</a></p>

<p><a href="http://example.com" title="It's here">Single</a></p>

<p><a href="http://example.com" title="Say &quot;hi&quot;">Reference</a></p>

<p><img src="a.png" alt="Image" title="A &quot;quoted&quot; title" /></p>
9 changes: 9 additions & 0 deletions test/tm-cases/link_title_escaped_quotes.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Inline](http://example.com "Say \"hi\"")

[Single](http://example.com 'It\'s here')

[Reference][ref]

![Image](a.png "A \"quoted\" title")

[ref]: http://example.com "Say \"hi\""
Loading