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 @@ -5,6 +5,7 @@
"d3": "3.5.17",
"file-saver": "^2.0.5",
"jquery-debounce-throttle": "^1.0.6-rc.0",
"mathjax": "^4.0.0",
"monaco": "^1.201704190613.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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __invoke(ResponseEvent $event): void
// the profiler requires 'unsafe-eval' for script-src 'self'.
$response = $event->getResponse();
$cspExtra = $this->profiler ? "'unsafe-eval'" : "";
$csp = "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' $cspExtra; img-src 'self' data:; worker-src 'self' blob:";
$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:";
$response->headers->set('Content-Security-Policy', $csp);
}
}
33 changes: 33 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('domjudge_markdown_to_html', $this->domjudgeMarkdownToHTML(...), ['is_safe' => ['html']]),
];
}

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

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
7 changes: 7 additions & 0 deletions webapp/templates/jury/clarification.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
{% endif %}

{% for clar in list %}
<div style="height: 100px;"></div>
<div>Pure body:<br>{{ clar.body }}</div>
<div>Markdown converted:<br>{{ clar.body | markdown_to_html }}</div>
<div>DOMjudge Markdown converted:<br>{{ clar.body | domjudge_markdown_to_html }}</div>
<div>Sanitized:<br>{{ clar.body | sanitize_html('app.clarification_sanitizer') }}</div>
<div>All:<br>{{ clar.body | domjudge_markdown_to_html | sanitize_html('app.clarification_sanitizer') }}</div>
<div>DOMjudge all:<br>{{ clar.body | domjudge_markdown_to_html | sanitize_html('app.clarification_sanitizer') }}</div>
<div class="card mb-3 {% if clar.from_team is not defined %}border-primary{% endif %}">
<div class="card-header">
<div class="row">
Expand Down
6 changes: 5 additions & 1 deletion 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
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>
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>
5 changes: 4 additions & 1 deletion 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') }}
</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 @@ -2,6 +2,11 @@
# yarn lockfile v1


"@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 @@ -34,6 +39,13 @@ jquery@>=1.7:
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.7.1.tgz#083ef98927c9a6a74d05a6af02806566d16274de"
integrity sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==

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@^1.201704190613.0:
version "1.201704190613.0"
resolved "https://registry.npmjs.org/monaco/-/monaco-1.201704190613.0.tgz"
Expand Down
Loading