Skip to content

Commit

Permalink
Merge pull request #1194 from Benbb96/fix-double-escaping-of-block-code
Browse files Browse the repository at this point in the history
Fix double escaping of block code
  • Loading branch information
benjaoming committed Jun 27, 2022
2 parents 4a0c5e3 + f38943b commit 2434e8c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/wiki/core/markdown/mdx/codehilite.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,24 @@ def run(self, lines):
class HiliteTreeprocessor(Treeprocessor):
"""Hilight source code in code blocks."""

def code_unescape(self, text):
"""Unescape &, <, > and " characters."""
text = text.replace("&amp;", "&")
text = text.replace("&lt;", "<")
text = text.replace("&gt;", ">")
text = text.replace("&quot;", '"')
return text

def run(self, root):
"""Find code blocks and store in htmlStash."""
blocks = root.iter("pre")
for block in blocks:
if len(block) == 1 and block[0].tag == "code":
html = highlight(block[0].text, self.config, self.markdown.tab_length)
html = highlight(
self.code_unescape(block[0].text),
self.config,
self.markdown.tab_length,
)
placeholder = self.markdown.htmlStash.store(html)
# Clear codeblock in etree instance
block.clear()
Expand Down

0 comments on commit 2434e8c

Please sign in to comment.