1
Fork 0
mirror of https://github.com/glassflame/glassflame.github.io.git synced 2024-12-11 17:24:27 +00:00

Provide a per-MarkdownRenderer context where KaTeX can store macros

This commit is contained in:
Steffo 2024-11-08 06:15:14 +01:00
parent 154711b63c
commit d200a47866
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 18 additions and 0 deletions

View file

@ -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,
}
)

View file

@ -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)
}