Skip to content

Commit 856aed1

Browse files
committed
Install Katex via NPM
1 parent 21c00dd commit 856aed1

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"d3": "^6.6.2",
5151
"gettext.js": "^2.0.3",
5252
"jquery": "^3.5.1",
53+
"katex": "^0.16.22",
5354
"quill": "^2.0.3",
5455
"resumablejs": "^1.1.0"
5556
},

scripts/text_widget.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,43 @@ export function makeProofTextWidget(container, projectId, userSettings, language
457457
const qHide = new Parchment.StyleAttributor("display", "display", config);
458458
Quill.register(qHide);
459459

460+
const Embed = Quill.import("blots/embed");
461+
class DFormula extends Embed {
462+
static blotName = "dformula";
463+
static className = "ql-dformula";
464+
static tagName = "SPAN";
465+
466+
static create(value) {
467+
// @ts-expect-error
468+
if (window.katex == null) {
469+
throw new Error("Formula module requires KaTeX.");
470+
}
471+
const node = super.create(value);
472+
if (typeof value === "string") {
473+
// @ts-expect-error
474+
window.katex.render(value, node, {
475+
throwOnError: false,
476+
errorColor: "#f00",
477+
displayMode: true,
478+
// output: "mathml",
479+
});
480+
node.setAttribute("data-value", value);
481+
}
482+
return node;
483+
}
484+
485+
static value(domNode) {
486+
return domNode.getAttribute("data-value");
487+
}
488+
489+
html() {
490+
const { dformula } = this.value();
491+
return `<span>${dformula}</span>`;
492+
}
493+
}
494+
495+
Quill.register(DFormula);
496+
460497
const { setup, reLayout, setText, quill, editBox, controlBar, setParaSpacing, qlEditor, extraSettings, onDoneSettings } = makeTextWidget(
461498
container,
462499
userSettings,

tools/proofers/proof.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
],
1919
"js_files" => [
2020
"$code_url/scripts/misc.js",
21+
"$code_url/node_modules/katex/dist/katex.min.js",
2122
"$code_url/node_modules/quill/dist/quill.js",
2223
],
2324
"css_files" => [
2425
"$code_url/styles/struct.css",
26+
"$code_url/node_modules/katex/dist/katex.min.css",
2527
"$code_url/node_modules/quill/dist/quill.core.css",
2628
],
2729
"body_attributes" => 'class="no-margin overflow-hidden fix-full"',

0 commit comments

Comments
 (0)