Skip to content

Commit 7679030

Browse files
committed
Render MathJax in clarifications
1 parent 4d90038 commit 7679030

File tree

11 files changed

+40
-2
lines changed

11 files changed

+40
-2
lines changed

webapp/public/js/domjudge.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ function previewClarification($input, $previewDiv) {
939939
}
940940
}).done(function (data) {
941941
$previewDiv.html(data.html);
942+
MathJax.typesetPromise([document.getElementById($previewDiv[0].id)]);
942943
});
943944
}
944945
}

webapp/public/js/tex-chtml.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../node_modules/mathjax/tex-chtml.js

webapp/public/mathjax

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../node_modules/mathjax

webapp/public/mathjaxfonts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../node_modules/@mathjax/mathjax-newcm-font/chtml/woff2

webapp/src/EventListener/AddContentSecurityPolicyListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __invoke(ResponseEvent $event): void
1717
// the profiler requires 'unsafe-eval' for script-src 'self'.
1818
$response = $event->getResponse();
1919
$cspExtra = $this->profiler ? "'unsafe-eval'" : "";
20-
$csp = "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' $cspExtra; img-src 'self' data:; worker-src 'self' blob:";
20+
$csp = "font-src 'self' data:; default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' $cspExtra; img-src 'self' data:; worker-src 'self' blob:";
2121
$response->headers->set('Content-Security-Policy', $csp);
2222
}
2323
}

webapp/templates/base.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<script src="{{ asset("js/jquery.min.js") }}"></script>
1414
<script src="{{ asset("js/jquery.debounce.min.js") }}"></script>
1515
<script src="{{ asset("js/bootstrap.bundle.min.js") }}"></script>
16+
{% include 'partials/mathjaxhead.html.twig' %}
1617

1718
<script src="{{ asset("js/domjudge.js") }}"></script>
1819
{% for file in customAssetFiles('js') %}

webapp/templates/jury/export/layout.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
color: darkgrey;
109109
}
110110
</style>
111+
{% include 'partials/mathjaxhead.html.twig' %}
111112
</head>
112113
<body>
113114
<main role="main" class="">
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
window.MathJax = {
3+
tex: {
4+
inlineMath: [['$', '$'], ['\\(', '\\)']]
5+
},
6+
chtml: {
7+
fontURL: "{{ app.request.basePath }}/mathjaxfonts",
8+
scale: 1.0
9+
},
10+
loader: {
11+
paths: {
12+
mathjax: "{{ app.request.basePath }}/mathjax"
13+
},
14+
load: ['input/tex', 'output/chtml']
15+
}
16+
};
17+
</script>
18+
<script src="{{ app.request.basePath }}/mathjax/tex-chtml.js"></script>

webapp/templates/team/partials/clarification_content.html.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@
2424
{{ form_end(form) }}
2525
</div>
2626
</div>
27+
28+
<script>
29+
MathJax.typeset([document.getElementsByClassName('card-body')]);
30+
</script>

webapp/templates/team/partials/clarification_list.html.twig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@
6262
</td>
6363
{% endif %}
6464

65-
<td>
65+
<td class="clarification-text">
6666
<a data-ajax-modal data-ajax-modal-after="markSeen" href="{{ link }}">
6767
{{ clarification.summary | markdown_to_html | sanitize_html('app.clarification_sanitizer') }}
6868
</a>
69+
<script>
70+
MathJax.typeset([document.getElementsByClassName('card-body')]);
71+
</script>
6972
</td>
7073
</tr>
7174
{%- endfor %}

0 commit comments

Comments
 (0)