Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 .spell-dict
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Treeprocessors
tuple
tuples
unescape
unescaping
unittest
unordered
untrusted
Expand Down
1 change: 1 addition & 0 deletions docs/change_log/release-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The following bug fixes are included in the 3.3 release:

* Fix issues with complex emphasis (#979).
* Limitations of `attr_list` extension are Documented (#965).
* Fix unescaping of HTML characters `<>` in CodeHilite (#990).

[spec]: https://www.w3.org/TR/html5/text-level-semantics.html#the-code-element
[fenced_code]: ../extensions/fenced_code_blocks.md
Expand Down
4 changes: 3 additions & 1 deletion markdown/extensions/codehilite.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ class HiliteTreeprocessor(Treeprocessor):

def code_unescape(self, text):
"""Unescape code."""
text = text.replace("&amp;", "&")
text = text.replace("&lt;", "<")
text = text.replace("&gt;", ">")
# Escaped '&' should be replaced at the end to avoid
# conflicting with < and >.
text = text.replace("&amp;", "&")
return text

def run(self, root):
Expand Down
23 changes: 23 additions & 0 deletions tests/test_syntax/extensions/test_code_hilite.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,29 @@ def testDoubleEscape(self):
extensions=['codehilite']
)

def testEntitiesIntact(self):
if has_pygments:
expected = (
'<div class="codehilite"><pre>'
'<span></span>'
'<code>&lt; &amp;lt; and &gt; &amp;gt;'
'\n</code></pre></div>'
)
else:
expected = (
'<pre class="codehilite"><code class="language-text">'
'&lt; &amp;lt; and &gt; &amp;gt;\n'
'</code></pre>'
)
self.assertMarkdownRenders(
(
'\t:::text\n'
'\t< &lt; and > &gt;'
),
expected,
extensions=['codehilite']
)

def testHighlightAmps(self):
if has_pygments:
expected = (
Expand Down