Improve katex markdown

This commit is contained in:
cuom1999 2024-02-05 18:32:08 -06:00
parent 08d2437d49
commit c87566673a
4 changed files with 16 additions and 19 deletions

View file

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

View file

@ -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,
]

View file

@ -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});
}
}
}

View file

@ -1,4 +1,4 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css" integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js" integrity="sha384-XjKyOOlGwcjNTAIQHIpgOno0Hl1YQqzUOEleOLALmuqehneUG+vnGctmUb0ZY0l8" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"
onload="renderMathInElement(document.body, window.KatexOptions);"></script>
onload="renderKatex();"></script>