MCPcopy
hub / github.com/markmap/markmap / transform

Function transform

packages/markmap-lib/src/plugins/hljs/index.browser.ts:10–46  ·  view source on GitHub ↗
(transformHooks: ITransformHooks)

Source from the content-addressed store, hash-verified

8 name,
9 config,
10 transform(transformHooks: ITransformHooks) {
11 let loading: Promise<void>;
12 const preloadScripts =
13 plugin.config?.preloadScripts?.map((item) =>
14 patchJSItem(transformHooks.transformer.urlBuilder, item),
15 ) || [];
16 const autoload = () => {
17 loading ||= loadJS(preloadScripts);
18 return loading;
19 };
20
21 let enableFeature = noop;
22 transformHooks.parser.tap((md) => {
23 md.set({
24 highlight: (str: string, language?: string) => {
25 enableFeature();
26 const { hljs } = window;
27 if (hljs) {
28 return hljs.highlightAuto(str, language ? [language] : undefined)
29 .value;
30 }
31 autoload().then(() => {
32 transformHooks.retransform.call();
33 });
34 return str;
35 },
36 });
37 });
38 transformHooks.beforeParse.tap((_, context) => {
39 enableFeature = () => {
40 context.features[name] = true;
41 };
42 });
43 return {
44 styles: plugin.config?.styles,
45 };
46 },
47});
48
49export default plugin;

Callers

nothing calls this directly

Calls 4

patchJSItemFunction · 0.90
tapMethod · 0.80
callMethod · 0.80
autoloadFunction · 0.70

Tested by

no test coverage detected