-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.js
46 lines (39 loc) · 1.22 KB
/
index.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
39
40
41
42
43
44
45
46
import plugin from "./src/plugin.js";
const mathup = await import("mathup").then(
(pkg) => pkg.default,
() => null,
);
/**
* @typedef {import("./src/plugin.js").PluginOptions} PluginOptions
* @typedef {import("mathup").Options} MathupOptions
* @typedef {object} ExtraOptions
* @property {MathupOptions} [defaultRendererOptions] - DEPRICATED: use mathupOptions.
* @property {MathupOptions} [mathupOptions] - Options passed into the mathup default renderer.
* @typedef {PluginOptions & ExtraOptions} MarkdownItMathOptions
*/
/** @type {import("markdown-it").PluginWithOptions<MarkdownItMathOptions>} */
export default function markdownItMath(
md,
{
defaultRendererOptions,
mathupOptions = defaultRendererOptions,
...options
} = {},
) {
if (!mathup) {
return plugin(md, options);
}
let { blockRenderer, inlineRenderer } = options;
if (!inlineRenderer && !options.inlineCustomElement) {
inlineRenderer = (src) => mathup(src, mathupOptions).toString();
}
if (!blockRenderer && !options.blockCustomElement) {
blockRenderer = (src) =>
mathup(src, { ...mathupOptions, display: "block" }).toString();
}
return plugin(md, {
...options,
inlineRenderer,
blockRenderer,
});
}