-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtemml.js
38 lines (31 loc) · 1.06 KB
/
temml.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import plugin from "./src/plugin.js";
const temml = await import("temml").then(
(pkg) => pkg.default,
() => null,
);
/**
* @typedef {import("./src/plugin.js").PluginOptions} PluginOptions
* @typedef {import("temml").Options} TemmlOptions
* @typedef {object} ExtraOptions
* @property {TemmlOptions} [temmlOptions] - Options passed into the mathup default renderer.
* @typedef {PluginOptions & ExtraOptions} MarkdownItMathOptions
*/
/** @type {import("markdown-it").PluginWithOptions<MarkdownItMathOptions>} */
export default function markdownItMath(md, { temmlOptions, ...options } = {}) {
if (!temml) {
return plugin(md, options);
}
let { blockRenderer, inlineRenderer } = options;
if (!inlineRenderer && !options.inlineCustomElement) {
inlineRenderer = (src) => temml.renderToString(src, temmlOptions);
}
if (!blockRenderer && !options.blockCustomElement) {
blockRenderer = (src) =>
temml.renderToString(src, { ...temmlOptions, displayMode: true });
}
return plugin(md, {
...options,
inlineRenderer,
blockRenderer,
});
}