From cebe07f29c6ade45ba9c169c304dceabea1e278e Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 16 Aug 2023 21:08:01 -0700 Subject: [PATCH] Unescape HTML inside code blocks --- modules/html_generator.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/html_generator.py b/modules/html_generator.py index 3d9f758b..0026ba4e 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -54,6 +54,9 @@ def convert_to_markdown(string): if line.lstrip(' ').startswith('```'): is_code = not is_code + if is_code: + line = html.unescape(line) + result += line if is_code or line.startswith('|'): # Don't add an extra \n for tables or code result += '\n' @@ -75,14 +78,14 @@ def convert_to_markdown(string): result = re.sub(r'(\d+\.)$', r'\g<1> ' + delete_str, result) - html = markdown.markdown(result, extensions=['fenced_code', 'tables']) - pos = html.rfind(delete_str) + html_output = markdown.markdown(result, extensions=['fenced_code', 'tables']) + pos = html_output.rfind(delete_str) if pos > -1: - html = html[:pos] + html[pos + len(delete_str):] + html_output = html_output[:pos] + html_output[pos + len(delete_str):] else: - html = markdown.markdown(result, extensions=['fenced_code', 'tables']) + html_output = markdown.markdown(result, extensions=['fenced_code', 'tables']) - return html + return html_output def generate_basic_html(string):