From 2a0276d0fd707948694d666d3af6b2e33322aab5 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Tue, 25 Oct 2022 18:07:45 -0500 Subject: [PATCH] Update markdown --- judge/jinja2/markdown/__init__.py | 37 ++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/judge/jinja2/markdown/__init__.py b/judge/jinja2/markdown/__init__.py index 3c01de2..ba006dd 100644 --- a/judge/jinja2/markdown/__init__.py +++ b/judge/jinja2/markdown/__init__.py @@ -6,6 +6,7 @@ from django.utils.html import escape EXTENSIONS = [ "pymdownx.magiclink", + "pymdownx.betterem", "pymdownx.details", "pymdownx.emoji", "pymdownx.inlinehilite", @@ -16,12 +17,38 @@ EXTENSIONS = [ "markdown.extensions.def_list", "markdown.extensions.tables", "markdown.extensions.admonition", - "pymdownx.arithmatex", ] -ALLOWED_TAGS = bleach.sanitizer.ALLOWED_TAGS + ["img", "center", "iframe"] +ALLOWED_TAGS = bleach.sanitizer.ALLOWED_TAGS + [ + "img", + "center", + "iframe", + "div", + "span", + "table", + "tr", + "td", + "th", + "tr", + "pre", + "code", + "p", + "hr", + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + "thead", + "tbody", + "sup", + "dl", + "dt", + "dd", +] -ALLOWED_ATTRS = ["src", "width", "height", "href"] +ALLOWED_ATTRS = ["src", "width", "height", "href", "class"] @registry.filter @@ -29,8 +56,8 @@ def markdown(value, hard_wrap=False): extensions = EXTENSIONS if hard_wrap: extensions = EXTENSIONS + ["nl2br"] - html = bleach.clean(value, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS) - html = _markdown.markdown(html, extensions=extensions) + html = _markdown.markdown(value, extensions=extensions) + html = bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS) if not html: html = escape(value) return '
%s
' % html