Pass one shared macros object into every call to katex renderer (#148006)

* Pass one shared `macros` object into every call to katex
renderer.

* Reset the `macros` object at each new
re-rendering.
This commit is contained in:
AlbertHilb 2022-05-02 18:45:06 +02:00 committed by GitHub
parent 82ad6afd36
commit 7e6b007dd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -43,10 +43,12 @@ export async function activate(ctx: RendererContext<void>) {
document.head.appendChild(styleTemplate);
const katex = require('@iktakahiro/markdown-it-katex');
const macros = {};
markdownItRenderer.extendMarkdownIt((md: markdownIt.MarkdownIt) => {
return md.use(katex, {
globalGroup: true,
enableBareBlocks: true,
macros
});
});
}

View file

@ -24,7 +24,9 @@ export function activate(context: vscode.ExtensionContext) {
extendMarkdownIt(md: any) {
if (isEnabled()) {
const katex = require('@iktakahiro/markdown-it-katex');
return md.use(katex, { globalGroup: true });
const options = { globalGroup: true, macros: {} };
md.core.ruler.push('reset-katex-macros', () => { options.macros = {}; });
return md.use(katex, options);
}
return md;
}