mirror of
https://github.com/glassflame/glassflame.github.io.git
synced 2024-12-12 01:34:26 +00:00
Provide a per-MarkdownRenderer context where KaTeX can store macros
This commit is contained in:
parent
154711b63c
commit
d200a47866
2 changed files with 18 additions and 0 deletions
|
@ -42,6 +42,12 @@ export class MathElement extends CustomElement {
|
||||||
*/
|
*/
|
||||||
katexElement
|
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.
|
* The name of the slot where {@link katexElement} should be placed in.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
@ -68,6 +74,8 @@ export class MathElement extends CustomElement {
|
||||||
{
|
{
|
||||||
throwOnError: false,
|
throwOnError: false,
|
||||||
globalGroup: true,
|
globalGroup: true,
|
||||||
|
macros: this.katexGroup,
|
||||||
|
trust: true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,11 @@ export class MarkdownElement extends CustomElement {
|
||||||
return document.getElementById("template-markdown")
|
return document.getElementById("template-markdown")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The group to use to store KaTeX macros in for everything in this {@link MarkdownElement}.
|
||||||
|
*/
|
||||||
|
katexGroup = {}
|
||||||
|
|
||||||
// noinspection JSUnusedGlobalSymbols
|
// noinspection JSUnusedGlobalSymbols
|
||||||
/**
|
/**
|
||||||
* {@link Marked} Markdown renderer.
|
* {@link Marked} Markdown renderer.
|
||||||
|
@ -226,6 +231,11 @@ export class MarkdownElement extends CustomElement {
|
||||||
this.documentElement = document.createElement("div")
|
this.documentElement = document.createElement("div")
|
||||||
this.documentElement.slot = this.constructor.DOCUMENT_ELEMENT_SLOT
|
this.documentElement.slot = this.constructor.DOCUMENT_ELEMENT_SLOT
|
||||||
this.documentElement.innerHTML = this.constructor.MARKED.parse(this.markdownDocument)
|
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)
|
this.appendChild(this.documentElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue