diff --git a/tildes/tildes/lib/markdown.py b/tildes/tildes/lib/markdown.py index 2c97d00..8c5a48c 100644 --- a/tildes/tildes/lib/markdown.py +++ b/tildes/tildes/lib/markdown.py @@ -198,6 +198,17 @@ def escape_accidental_ordered_lists(markdown: str) -> str: def postprocess_markdown_html(html: str) -> str: """Apply post-processing to HTML generated by markdown parser.""" + # cmark (and cmark-gfm) replaces double-quote characters with the " entity. + # This is almost always unnecessary, and is causing issues with some of the HTML + # processing, since (for example) BeautifulSoup will convert them back, which causes + # the string-replacement in apply_syntax_highlighting() to fail if a code block + # contains any double-quote characters. + # + # We'll just do a full replacement here - this has a possibility of being dangerous, + # but it should be extremely unlikely and the sanitization function should make sure + # that nothing malicious can happen regardless. + html = html.replace(""", '"') + # apply syntax highlighting to code blocks html = apply_syntax_highlighting(html)