Unescape inline code blocks

This commit is contained in:
oobabooga 2023-08-24 21:01:09 -07:00
parent 26c5e5e878
commit feecd8190f

View File

@ -54,9 +54,6 @@ def convert_to_markdown(string):
if line.lstrip(' ').startswith('```'): if line.lstrip(' ').startswith('```'):
is_code = not is_code is_code = not is_code
if is_code:
line = html.unescape(line)
result += line result += line
if is_code or line.startswith('|'): # Don't add an extra \n for tables or code if is_code or line.startswith('|'): # Don't add an extra \n for tables or code
result += '\n' result += '\n'
@ -85,6 +82,10 @@ def convert_to_markdown(string):
else: else:
html_output = markdown.markdown(result, extensions=['fenced_code', 'tables']) html_output = markdown.markdown(result, extensions=['fenced_code', 'tables'])
# Unescape code blocks
pattern = re.compile(r'<code[^>]*>(.*?)</code>', re.DOTALL)
html_output = pattern.sub(lambda x: html.unescape(x.group()), html_output)
return html_output return html_output