~tsileo/microblog.pub-devel

Fix escaping of < and > in code highlighting v1 PROPOSED

João Costa: 1
 Fix escaping of < and > in code highlighting

 1 files changed, 2 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~tsileo/microblog.pub-devel/patches/40216/mbox | git am -3
Learn more about email & git

[PATCH] Fix escaping of < and > in code highlighting Export this patch

Handles the < an > substitution with &lt; and &gt; in a more generic way.
I tested this in my production instance and found no problems.
---
 app/utils/highlight.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/utils/highlight.py b/app/utils/highlight.py
index 2e60a36..4f22a92 100644
--- a/app/utils/highlight.py
+++ b/app/utils/highlight.py
@@ -39,8 +39,8 @@ def highlight(html: str) -> str:
                lexer = guess_lexer(code_content)

            # Replace the code with Pygment output
            # XXX: the HTML escaping causes issue with Python type annotations
            code_content = code_content.replace(") -&gt; ", ") -> ")
            code_content = code_content.replace("&gt;", ">")
            code_content = code_content.replace("&lt;", "<")
            code.parent.replaceWith(
                BeautifulSoup(
                    phighlight(code_content, lexer, _FORMATTER), "html5lib"
-- 
2.40.0.windows.1