diff --git a/src/elements/markdown/math.mjs b/src/elements/markdown/math.mjs index f5ae7c1..982f9d6 100644 --- a/src/elements/markdown/math.mjs +++ b/src/elements/markdown/math.mjs @@ -42,6 +42,12 @@ export class MathElement extends CustomElement { */ katexElement + /** + * The group to use to store macros in. + * Should be overridden by the creator element. + */ + katexGroup = {} + /** * The name of the slot where {@link katexElement} should be placed in. * @type {string} @@ -68,6 +74,8 @@ export class MathElement extends CustomElement { { throwOnError: false, globalGroup: true, + macros: this.katexGroup, + trust: true, } ) diff --git a/src/elements/markdown/renderer.mjs b/src/elements/markdown/renderer.mjs index 6c2a4f0..973a522 100644 --- a/src/elements/markdown/renderer.mjs +++ b/src/elements/markdown/renderer.mjs @@ -11,6 +11,11 @@ export class MarkdownElement extends CustomElement { return document.getElementById("template-markdown") } + /** + * The group to use to store KaTeX macros in for everything in this {@link MarkdownElement}. + */ + katexGroup = {} + // noinspection JSUnusedGlobalSymbols /** * {@link Marked} Markdown renderer. @@ -226,6 +231,11 @@ export class MarkdownElement extends CustomElement { this.documentElement = document.createElement("div") this.documentElement.slot = this.constructor.DOCUMENT_ELEMENT_SLOT this.documentElement.innerHTML = this.constructor.MARKED.parse(this.markdownDocument) + + for(const el of this.documentElement.getElementsByTagName("x-math")) { + el.katexGroup = this.katexGroup + } + this.appendChild(this.documentElement) }