MCPcopy Index your code
hub / github.com/markmap/markmap / fillTemplate

Function fillTemplate

packages/markmap-render/src/index.ts:20–85  ·  view source on GitHub ↗
(
  root: IPureNode | null,
  assets: IAssets,
  extra?: {
    baseJs?: JSItem[];
    jsonOptions?: Partial<IMarkmapJSONOptions>;
    getOptions?: (
      jsonOptions: Partial<IMarkmapJSONOptions>,
    ) => Partial<IMarkmapOptions>;
    /** See https://github.com/gera2ld/npm2url */
    urlBuilder?: UrlBuilder;
  },
)

Source from the content-addressed store, hash-verified

18];
19
20export function fillTemplate(
21 root: IPureNode | null,
22 assets: IAssets,
23 extra?: {
24 baseJs?: JSItem[];
25 jsonOptions?: Partial<IMarkmapJSONOptions>;
26 getOptions?: (
27 jsonOptions: Partial<IMarkmapJSONOptions>,
28 ) => Partial<IMarkmapOptions>;
29 /** See https://github.com/gera2ld/npm2url */
30 urlBuilder?: UrlBuilder;
31 },
32): string {
33 extra = {
34 ...extra,
35 };
36 const urlBuilder = extra.urlBuilder ?? defaultUrlBuilder;
37 extra.baseJs ??= baseJsPaths
38 .map((path) => urlBuilder.getFullUrl(path))
39 .map((path) => buildJSItem(path));
40 const { scripts, styles } = assets;
41 const cssList = [...(styles ? persistCSS(styles) : [])];
42 const context = {
43 getMarkmap: () => window.markmap,
44 getOptions: extra.getOptions,
45 jsonOptions: extra.jsonOptions,
46 root,
47 };
48 const jsList = [
49 ...persistJS(
50 [
51 ...extra.baseJs,
52 ...(scripts || []),
53 {
54 type: 'iife',
55 data: {
56 fn: (
57 getMarkmap: (typeof context)['getMarkmap'],
58 getOptions: (typeof context)['getOptions'],
59 root: (typeof context)['root'],
60 jsonOptions: IMarkmapJSONOptions,
61 ) => {
62 const markmap = getMarkmap();
63 window.mm = markmap.Markmap.create(
64 'svg#mindmap',
65 (getOptions || markmap.deriveOptions)(jsonOptions),
66 root,
67 );
68 if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
69 document.documentElement.classList.add('markmap-dark');
70 }
71 },
72 getParams: ({ getMarkmap, getOptions, root, jsonOptions }) => {
73 return [getMarkmap, getOptions, root, jsonOptions];
74 },
75 },
76 } as JSItem,
77 ],

Callers 2

createMarkmapFunction · 0.90
_buildHtmlMethod · 0.90

Calls 4

buildJSItemFunction · 0.90
persistCSSFunction · 0.90
persistJSFunction · 0.90
createMethod · 0.45

Tested by

no test coverage detected