Skip to content

Commit

Permalink
Fix lxml adding extra tags (DMOJ#1428)
Browse files Browse the repository at this point in the history
Fixes DMOJ#955.
  • Loading branch information
quantum5 authored and outloudvi committed Sep 28, 2020
1 parent 135b04d commit 8f2248a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions judge/jinja2/markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ def markdown(value, style, math_engine=None, lazy_load=False):
result = markdown(value)

if post_processors:
tree = html.Element('div')
try:
tree = html.fromstring(result, parser=html.HTMLParser(recover=True))
tree.extend(html.fragments_fromstring(result, parser=html.HTMLParser(recover=True)))
except (XMLSyntaxError, ParserError) as e:
if result and (not isinstance(e, ParserError) or e.args[0] != 'Document is empty'):
logger.exception('Failed to parse HTML string')
tree = html.Element('div')
for processor in post_processors:
processor(tree)
result = html.tostring(tree, encoding='unicode')
result = html.tostring(tree, encoding='unicode')[len('<div>'):-len('</div>')]
if bleach_params:
result = get_cleaner(style, bleach_params).clean(result)
return Markup(result)

0 comments on commit 8f2248a

Please sign in to comment.