mirror of
https://github.com/discourse/discourse-math.git
synced 2025-07-07 14:22:11 +00:00
FEAT: enable persistent macros in Katex, update Katex to 0.15.6 (#51)
This commit is contained in:
parent
836d084818
commit
4b4ad9d532
@ -11,7 +11,7 @@ function ensureKaTeX() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function decorate(elem) {
|
function decorate(elem, macros) {
|
||||||
const $elem = $(elem);
|
const $elem = $(elem);
|
||||||
const displayMode = elem.tagName === "DIV";
|
const displayMode = elem.tagName === "DIV";
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ function decorate(elem) {
|
|||||||
const displayClass = tag === "div" ? "block-math" : "inline-math";
|
const displayClass = tag === "div" ? "block-math" : "inline-math";
|
||||||
const text = $elem.text();
|
const text = $elem.text();
|
||||||
$elem.addClass(`math-container ${displayClass} katex-math`).text("");
|
$elem.addClass(`math-container ${displayClass} katex-math`).text("");
|
||||||
window.katex.render(text, elem, { displayMode });
|
window.katex.render(text, elem, { displayMode, macros });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,9 @@ function katex($elem) {
|
|||||||
|
|
||||||
if (mathElems.length > 0) {
|
if (mathElems.length > 0) {
|
||||||
ensureKaTeX().then(() => {
|
ensureKaTeX().then(() => {
|
||||||
mathElems.each((idx, elem) => decorate(elem));
|
// enable persistent macros: https://katex.org/docs/api.html#persistent-macros
|
||||||
|
const macros = {};
|
||||||
|
mathElems.each((idx, elem) => decorate(elem, macros));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
public/katex/katex.min.css
vendored
2
public/katex/katex.min.css
vendored
File diff suppressed because one or more lines are too long
2
public/katex/katex.min.js
vendored
2
public/katex/katex.min.js
vendored
File diff suppressed because one or more lines are too long
2
public/katex/mhchem.min.js
vendored
2
public/katex/mhchem.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user