Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/jobs/baseinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ section_end

section_start "Install JS frontend dependencies"
cd webapp
apt-get update; apt-get install -y yarnpkg
yarnpkg install
cd ..
section_end
Expand Down
1 change: 1 addition & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"file-saver": "^2.0.5",
"flag-icons": "^7.5.0",
"jquery-debounce-throttle": "^1.0.6-rc.0",
"mathjax": "^4.0.0",
"monaco-editor": "^0.54.0",
"nvd3": "1.8.6",
"select2": "^4.0.13",
Expand Down
1 change: 1 addition & 0 deletions webapp/public/js/domjudge.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ function previewClarification($input, $previewDiv) {
}
}).done(function (data) {
$previewDiv.html(data.html);
MathJax.typesetPromise([document.getElementById($previewDiv[0].id)]);
});
}
}
Expand Down
1 change: 1 addition & 0 deletions webapp/public/js/tex-chtml.js
1 change: 1 addition & 0 deletions webapp/public/mathjax
1 change: 1 addition & 0 deletions webapp/public/mathjaxfonts
37 changes: 37 additions & 0 deletions webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
use Twig\Extra\Markdown\MarkdownRuntime;
use Twig\Runtime\EscaperRuntime;
use Twig\TwigFilter;
use Twig\TwigFunction;
Expand Down Expand Up @@ -124,6 +125,7 @@ public function getFilters(): array
new TwigFilter('medalType', $this->awards->medalType(...)),
new TwigFilter('numTableActions', $this->numTableActions(...)),
new TwigFilter('extensionToMime', $this->extensionToMime(...)),
new TwigFilter('domjudgeMarkdownToHtml', $this->domjudgeMarkdownToHTML(...), ['is_safe' => ['html']]),
];
}

Expand Down Expand Up @@ -1406,4 +1408,39 @@ public function extensionToMime(string $extension): string
{
return DOMJudgeService::EXTENSION_TO_MIMETYPE[$extension];
}

/**
* Extract all LaTeX code from the given string, sanitize the markdown and
* inject the original LaTeX code back so MathJax can render it.
*/
public function domjudgeMarkdownToHTML(string $markdown): string
{
$latexFound = [];
while (true) {
$start = strpos($markdown, '$$');
$end = strpos(substr($markdown, $start+2), '$$');
if ($start === false || $end === false) {
break;
}
$latexFound[] = substr($markdown, $start, $end+2+2);
$newMarkdown = substr($markdown, 0, $start);
$newMarkdown .= '$LaTeX$';
$newMarkdown .= substr($markdown, $end+$start+4);
$markdown = $newMarkdown;
}

/** @var MarkdownRuntime $runtime */
$runtime = $this->twig->getRuntime(MarkdownRuntime::class);
$markdown = (string)$runtime->convert($markdown);

$new = '';
foreach ($latexFound as $inlineLatex) {
$replacedStart = strpos($markdown, '$LaTeX$');
$new = substr($markdown, 0, $replacedStart);
$new .= $inlineLatex;
$new .= substr($markdown, $replacedStart+strlen('$LaTeX$'));
$markdown = $new;
}
return $markdown;
}
}
1 change: 1 addition & 0 deletions webapp/templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script src="{{ asset("js/jquery.min.js") }}"></script>
<script src="{{ asset("js/jquery.debounce.min.js") }}"></script>
<script src="{{ asset("js/bootstrap.bundle.min.js") }}"></script>
{% include 'partials/mathjaxhead.html.twig' %}

<script src="{{ asset("js/domjudge.js") }}"></script>
{% for file in customAssetFiles('js') %}
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/jury/clarification.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

<hr/>

<div class="card-text">{{ clar.body | markdown_to_html | sanitize_html('app.clarification_sanitizer') }}</div>
<div class="card-text">{{ clar.body | domjudgeMarkdownToHtml | sanitize_html('app.clarification_sanitizer') }}</div>

</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/jury/config.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
{{ errors[option.name] }}
</div>
{% endif %}
<div class="small text-muted">{{ option.description | markdown_to_html }}</div>
<div class="small text-muted">{{ option.description | domjudgeMarkdownToHtml }}</div>
</div>
</li>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/jury/config_check.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
{% if testresult.escape is not defined or testresult.escape %}
{% set description = description | escape %}
{% endif %}
{{ description | markdown_to_html }}
{{ description | domjudgeMarkdownToHtml }}
</div>
</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions webapp/templates/jury/export/clarifications.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
<div class="page-break"></div>
<h1>{{ title }}</h1>
{% endif %}
<h2>{{ queues[queue] }}</h2>
{% if queues[queue] is defined %}
<h2>{{ queues[queue] }}</h2>
{% else %}
<h2><i>Unknown queue: {{ queue }}</h2>
{% endif %}
<table class="table">
<thead>
<tr>
Expand Down Expand Up @@ -94,7 +98,7 @@
<tr>
<td><b>Content</b></td>
<td colspan="5">
<div class="card-text">{{ clarification.body | markdown_to_html | sanitize_html('app.clarification_sanitizer') }}</div>
<div class="card-text">{{ clarification.body | domjudgeMarkdownToHtml | sanitize_html('app.clarification_sanitizer') }}</div>
</td>
</tr>
{% if clarification.replies is not empty %}
Expand All @@ -110,7 +114,7 @@
</b>
</td>
<td colspan="5">
<div class="card-text">{{ reply.body | markdown_to_html | sanitize_html('app.clarification_sanitizer') }}</div>
<div class="card-text">{{ reply.body | domjudgeMarkdownToHtml | sanitize_html('app.clarification_sanitizer') }}</div>
</td>
</tr>
{% endfor %}
Expand Down
1 change: 1 addition & 0 deletions webapp/templates/jury/export/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
color: darkgrey;
}
</style>
{% include 'partials/mathjaxhead.html.twig' %}
</head>
<body>
<main role="main" class="">
Expand Down
2 changes: 2 additions & 0 deletions webapp/templates/jury/menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

{% set current_route = app.request.attributes.get('_route') %}

<span>Euler's identity: $( e^{i\pi} + 1 = 0 )$</span>
<span>$$\vec{a} \times \vec{b} = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ a_x & a_y & a_z \\ b_x & b_y & b_z \end{vmatrix}$$</span>
<div class="collapse navbar-collapse" id="menuDefault" data-update-url="{{ path('jury_ajax_updates') }}">
<ul class="navbar-nav me-auto">

Expand Down
18 changes: 18 additions & 0 deletions webapp/templates/partials/mathjaxhead.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
},
chtml: {
fontURL: "{{ app.request.basePath }}/mathjaxfonts",
scale: 1.0
},
loader: {
paths: {
mathjax: "{{ app.request.basePath }}/mathjax"
},
load: ['input/tex', 'output/chtml']
}
};
</script>
<script src="{{ app.request.basePath }}/mathjax/tex-chtml.js"></script>
2 changes: 1 addition & 1 deletion webapp/templates/team/partials/clarification.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<hr/>

<div class="card-text">
{{ clarification.body | markdown_to_html | sanitize_html('app.clarification_sanitizer') }}
{{ clarification.body | domjudgeMarkdownToHtml | sanitize_html('app.clarification_sanitizer') }}
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
{{ form_end(form) }}
</div>
</div>

<script>
MathJax.typeset([document.getElementsByClassName('card-body')]);
</script>
7 changes: 5 additions & 2 deletions webapp/templates/team/partials/clarification_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@
</td>
{% endif %}

<td>
<td class="clarification-text">
<a data-ajax-modal data-ajax-modal-after="markSeen" href="{{ link }}">
{{ clarification.summary | markdown_to_html | sanitize_html('app.clarification_sanitizer') }}
{{ clarification.summary | domjudgeMarkdownToHtml | sanitize_html('app.clarification_sanitizer') }}
</a>
<script>
MathJax.typeset([document.getElementsByClassName('card-body')]);
</script>
</td>
</tr>
{%- endfor %}
Expand Down
12 changes: 12 additions & 0 deletions webapp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-7.1.0.tgz#8eb76278515341720aa74485266f8be121089529"
integrity sha512-+WxNld5ZCJHvPQCr/GnzCTVREyStrAJjisUPtUxG5ngDA8TMlPnKp6dddlTpai4+1GNmltAeuk1hJEkBohwZYA==

"@mathjax/mathjax-newcm-font@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@mathjax/mathjax-newcm-font/-/mathjax-newcm-font-4.0.0.tgz#01afa8b20f2114665dc1d9a7fbc623a23ddb54e4"
integrity sha512-kpsJgIF4FpWiwIkFgOPmWwy5GXfL25spmJJNg27HQxPddmEL8Blx0jn2BuU/nlwjM/9SnYpEfDrWiAMgLPlB8Q==

"@melloware/coloris@^0.25.0":
version "0.25.0"
resolved "https://registry.yarnpkg.com/@melloware/coloris/-/coloris-0.25.0.tgz#7012c10dc510dca1660b3692ed3c812344aec6ca"
Expand Down Expand Up @@ -79,6 +84,13 @@ marked@14.0.0:
resolved "https://registry.yarnpkg.com/marked/-/marked-14.0.0.tgz#79a1477358a59e0660276f8fec76de2c33f35d83"
integrity sha512-uIj4+faQ+MgHgwUW1l2PsPglZLOLOT1uErt06dAPtx2kjteLAkbsd/0FiYg/MGS+i7ZKLb7w2WClxHkzOOuryQ==

mathjax@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/mathjax/-/mathjax-4.0.0.tgz#ff7aa8b6bfdc7e97e41091a9ed6d8c8f8eefd2a0"
integrity sha512-ThMPHiPl9ibZBInAmfoTCNq9MgCdH7ChIQ9YhKFc325noJ4DMzy9/Q14qdcuPzVJjEmC3kyXhwnERZWX3hbWzQ==
dependencies:
"@mathjax/mathjax-newcm-font" "^4.0.0"

monaco-editor@^0.54.0:
version "0.54.0"
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.54.0.tgz#c0d6ebb46b83f1bef6f67f6aa471e38ba7ef8231"
Expand Down
Loading