Unescape HTML inside code blocks

This commit is contained in:
oobabooga 2023-08-16 21:08:01 -07:00
parent 46408465ce
commit cebe07f29c

View file

@ -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):