diff --git a/judge/markdown.py b/judge/markdown.py index ba594c1..5260f85 100644 --- a/judge/markdown.py +++ b/judge/markdown.py @@ -6,7 +6,7 @@ from pymdownx import superfences EXTENSIONS = [ - # "pymdownx.arithmatex", + "pymdownx.arithmatex", "pymdownx.magiclink", "pymdownx.betterem", "pymdownx.details", @@ -25,6 +25,9 @@ EXTENSIONS = [ ] EXTENSION_CONFIGS = { + "pymdownx.arithmatex": { + "generic": True, + }, "pymdownx.superfences": { "custom_fences": [ { @@ -83,7 +86,6 @@ def markdown(value, lazy_load=False): value, extensions=extensions, extension_configs=EXTENSION_CONFIGS ) - soup = BeautifulSoup(html, "html.parser") html = bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS) if not html: diff --git a/judge/signals.py b/judge/signals.py index 74ae833..7987bbd 100644 --- a/judge/signals.py +++ b/judge/signals.py @@ -46,7 +46,6 @@ def problem_update(sender, instance, **kwargs): cache.delete_many( [ make_template_fragment_key("submission_problem", (instance.id,)), - make_template_fragment_key("problem_feed", (instance.id,)), "problem_tls:%s" % instance.id, "problem_mls:%s" % instance.id, ] diff --git a/resources/katex_config.js b/resources/katex_config.js index 0a18883..a87b1ee 100644 --- a/resources/katex_config.js +++ b/resources/katex_config.js @@ -1,17 +1,13 @@ -window.KatexOptions = { - delimiters: [ - {left: '$$', right: '$$', display: true}, - {left: '$', right: '$', display: false}, - {left: '\\[', right: '\\]', display: true}, - {left: "\\(", right: "\\)", display: false}, - {left: "\\begin{equation}", right: "\\end{equation}", display: true}, - {left: "\\begin{align}", right: "\\end{align}", display: true}, - {left: "\\begin{alignat}", right: "\\end{alignat}", display: true}, - {left: "\\begin{gather}", right: "\\end{gather}", display: true}, - {left: "\\begin{CD}", right: "\\end{CD}", display: true}, - ], - throwOnError : false -}; window.renderKatex = (elem=document.body) => { - renderMathInElement(elem, window.KatexOptions); + var maths = document.querySelectorAll('.arithmatex'), + tex; + console.log(maths); + for (var i = 0; i < maths.length; i++) { + tex = maths[i].textContent || maths[i].innerText; + if (tex.startsWith('\\(') && tex.endsWith('\\)')) { + katex.render(tex.slice(2, -2), maths[i], {'displayMode': false, 'throwOnError': false}); + } else if (tex.startsWith('\\[') && tex.endsWith('\\]')) { + katex.render(tex.slice(2, -2), maths[i], {'displayMode': true, 'throwOnError': false}); + } + } } \ No newline at end of file diff --git a/templates/katex-load.html b/templates/katex-load.html index 017e574..d87ce4d 100644 --- a/templates/katex-load.html +++ b/templates/katex-load.html @@ -1,4 +1,4 @@ \ No newline at end of file + onload="renderKatex();"> \ No newline at end of file