Move from mathjax to katex

This commit is contained in:
cuom1999 2024-02-05 17:02:49 -06:00
parent b2c9be7bda
commit 08d2437d49
35 changed files with 64 additions and 214 deletions

View file

@ -43,7 +43,6 @@ from judge.models import (
from judge.widgets import (
HeavyPreviewPageDownWidget,
MathJaxPagedownWidget,
PagedownWidget,
Select2MultipleWidget,
Select2Widget,
@ -412,7 +411,7 @@ class NewMessageForm(ModelForm):
fields = ["title", "content"]
widgets = {}
if PagedownWidget is not None:
widgets["content"] = MathJaxPagedownWidget()
widgets["content"] = PagedownWidget()
class CustomAuthenticationForm(AuthenticationForm):

View file

@ -96,7 +96,7 @@ class Command(BaseCommand):
.replace("'//", "'https://")
)
maker.title = problem_name
for file in ("style.css", "mathjax3_config.js"):
for file in "style.css":
maker.load(file, os.path.join(settings.DMOJ_RESOURCES, file))
maker.make(debug=True)
if not maker.success:

View file

@ -6,7 +6,7 @@ from pymdownx import superfences
EXTENSIONS = [
"pymdownx.arithmatex",
# "pymdownx.arithmatex",
"pymdownx.magiclink",
"pymdownx.betterem",
"pymdownx.details",
@ -83,24 +83,9 @@ def markdown(value, lazy_load=False):
value, extensions=extensions, extension_configs=EXTENSION_CONFIGS
)
# Don't clean mathjax
hash_script_tag = {}
soup = BeautifulSoup(html, "html.parser")
for script_tag in soup.find_all("script"):
allow_math_types = ["math/tex", "math/tex; mode=display"]
if script_tag.attrs.get("type", False) in allow_math_types:
hash_script_tag[str(hash(str(script_tag)))] = str(script_tag)
for hashed_tag in hash_script_tag:
tag = hash_script_tag[hashed_tag]
html = html.replace(tag, hashed_tag)
html = bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS)
for hashed_tag in hash_script_tag:
tag = hash_script_tag[hashed_tag]
html = html.replace(hashed_tag, tag)
if not html:
html = escape(value)
if lazy_load:

View file

@ -27,7 +27,7 @@ from django_ratelimit.decorators import ratelimit
from judge.models import Comment, CommentVote, Notification, BlogPost
from judge.utils.views import TitleMixin
from judge.widgets import MathJaxPagedownWidget, HeavyPreviewPageDownWidget
from judge.widgets import HeavyPreviewPageDownWidget
from judge.comments import add_mention_notifications
import json

View file

@ -407,8 +407,6 @@ class ProblemPdfView(ProblemMixin, SingleObjectMixin, View):
)
maker.title = problem_name
assets = ["style.css"]
if maker.math_engine == "jax":
assets.append("mathjax3_config.js")
for file in assets:
maker.load(file, os.path.join(settings.DMOJ_RESOURCES, file))
maker.make()

View file

@ -10,8 +10,8 @@ from judge.widgets.mixins import CompressorWidgetMixin
__all__ = [
"PagedownWidget",
"AdminPagedownWidget",
"MathJaxPagedownWidget",
"MathJaxAdminPagedownWidget",
"KatexPagedownWidget",
"KatexAdminPagedownWidget",
"HeavyPreviewPageDownWidget",
"HeavyPreviewAdminPageDownWidget",
]
@ -21,8 +21,8 @@ try:
except ImportError:
PagedownWidget = None
AdminPagedownWidget = None
MathJaxPagedownWidget = None
MathJaxAdminPagedownWidget = None
KatexPagedownWidget = None
KatexAdminPagedownWidget = None
HeavyPreviewPageDownWidget = None
HeavyPreviewAdminPageDownWidget = None
else:
@ -61,15 +61,19 @@ else:
}
js = ["admin/js/pagedown.js"]
class MathJaxPagedownWidget(PagedownWidget):
class KatexPagedownWidget(PagedownWidget):
class Media:
css = {
"all": ["https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css"]
}
js = [
"mathjax3_config.js",
"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js",
"katex_config.js",
"https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js",
"https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js",
"pagedown_math.js",
]
class MathJaxAdminPagedownWidget(AdminPagedownWidget, MathJaxPagedownWidget):
class KatexAdminPagedownWidget(AdminPagedownWidget, KatexPagedownWidget):
pass
class HeavyPreviewPageDownWidget(PagedownWidget):
@ -112,7 +116,7 @@ else:
js = ["dmmd-preview.js"]
class HeavyPreviewAdminPageDownWidget(
AdminPagedownWidget, HeavyPreviewPageDownWidget
KatexPagedownWidget, AdminPagedownWidget, HeavyPreviewPageDownWidget
):
class Media:
css = {