Improve katex markdown
This commit is contained in:
parent
08d2437d49
commit
c87566673a
4 changed files with 16 additions and 19 deletions
|
@ -6,7 +6,7 @@ from pymdownx import superfences
|
||||||
|
|
||||||
|
|
||||||
EXTENSIONS = [
|
EXTENSIONS = [
|
||||||
# "pymdownx.arithmatex",
|
"pymdownx.arithmatex",
|
||||||
"pymdownx.magiclink",
|
"pymdownx.magiclink",
|
||||||
"pymdownx.betterem",
|
"pymdownx.betterem",
|
||||||
"pymdownx.details",
|
"pymdownx.details",
|
||||||
|
@ -25,6 +25,9 @@ EXTENSIONS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
EXTENSION_CONFIGS = {
|
EXTENSION_CONFIGS = {
|
||||||
|
"pymdownx.arithmatex": {
|
||||||
|
"generic": True,
|
||||||
|
},
|
||||||
"pymdownx.superfences": {
|
"pymdownx.superfences": {
|
||||||
"custom_fences": [
|
"custom_fences": [
|
||||||
{
|
{
|
||||||
|
@ -83,7 +86,6 @@ def markdown(value, lazy_load=False):
|
||||||
value, extensions=extensions, extension_configs=EXTENSION_CONFIGS
|
value, extensions=extensions, extension_configs=EXTENSION_CONFIGS
|
||||||
)
|
)
|
||||||
|
|
||||||
soup = BeautifulSoup(html, "html.parser")
|
|
||||||
html = bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS)
|
html = bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS)
|
||||||
|
|
||||||
if not html:
|
if not html:
|
||||||
|
|
|
@ -46,7 +46,6 @@ def problem_update(sender, instance, **kwargs):
|
||||||
cache.delete_many(
|
cache.delete_many(
|
||||||
[
|
[
|
||||||
make_template_fragment_key("submission_problem", (instance.id,)),
|
make_template_fragment_key("submission_problem", (instance.id,)),
|
||||||
make_template_fragment_key("problem_feed", (instance.id,)),
|
|
||||||
"problem_tls:%s" % instance.id,
|
"problem_tls:%s" % instance.id,
|
||||||
"problem_mls:%s" % instance.id,
|
"problem_mls:%s" % instance.id,
|
||||||
]
|
]
|
||||||
|
|
|
@ -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) => {
|
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});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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">
|
<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/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"
|
<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>
|
Loading…
Reference in a new issue