markmap-lib 0.15.8 → 0.15.9-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,16 @@
1
- import { Remarkable } from "remarkable";
2
1
  import { buildJSItem, buildCSSItem, Hook, noop, loadJS, UrlBuilder, wrapFunction, persistCSS, persistJS } from "markmap-common";
2
+ import { buildTree } from "markmap-html-parser";
3
+ import { Remarkable } from "remarkable";
3
4
  import remarkableKatex from "remarkable-katex";
4
5
  import yaml from "js-yaml";
5
6
  const template = '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<meta name="viewport" content="width=device-width, initial-scale=1.0">\n<meta http-equiv="X-UA-Compatible" content="ie=edge">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id="mindmap"></svg>\n<!--JS-->\n</body>\n</html>\n';
6
7
  const baseJsPaths = [
7
8
  `d3@${"7.8.5"}/dist/d3.min.js`,
8
- `markmap-view@${"0.15.8"}/dist/browser/index.js`
9
+ `markmap-view@${"0.15.9-alpha.5"}/dist/browser/index.js`
9
10
  ];
10
- const name$3 = "katex";
11
+ const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
12
+ const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
13
+ const name$4 = "katex";
11
14
  const preloadScripts$1 = [
12
15
  `katex@${"0.16.8"}/dist/katex.min.js`
13
16
  ].map((path) => buildJSItem(path));
@@ -113,13 +116,13 @@ function createTransformHooks(transformer) {
113
116
  function definePlugin(plugin2) {
114
117
  return plugin2;
115
118
  }
116
- const plugin$1 = definePlugin({
117
- name: name$3,
119
+ const plugin$2 = definePlugin({
120
+ name: name$4,
118
121
  config: config$1,
119
122
  transform(transformHooks) {
120
123
  var _a, _b, _c, _d;
121
124
  let loading;
122
- const preloadScripts2 = ((_b = (_a = plugin$1.config) == null ? void 0 : _a.preloadScripts) == null ? void 0 : _b.map(
125
+ const preloadScripts2 = ((_b = (_a = plugin$2.config) == null ? void 0 : _a.preloadScripts) == null ? void 0 : _b.map(
123
126
  (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
124
127
  )) || [];
125
128
  const autoload = () => {
@@ -150,7 +153,7 @@ const plugin$1 = definePlugin({
150
153
  });
151
154
  transformHooks.beforeParse.tap((_, context) => {
152
155
  enableFeature = () => {
153
- context.features[name$3] = true;
156
+ context.features[name$4] = true;
154
157
  };
155
158
  });
156
159
  transformHooks.afterParse.tap((_, context) => {
@@ -163,22 +166,22 @@ const plugin$1 = definePlugin({
163
166
  if (value) {
164
167
  markmap[key] = addDefaultVersions(
165
168
  value,
166
- name$3,
167
- ((_b2 = (_a3 = plugin$1.config) == null ? void 0 : _a3.versions) == null ? void 0 : _b2.katex) || ""
169
+ name$4,
170
+ ((_b2 = (_a3 = plugin$2.config) == null ? void 0 : _a3.versions) == null ? void 0 : _b2.katex) || ""
168
171
  );
169
172
  }
170
173
  });
171
174
  }
172
175
  });
173
176
  return {
174
- styles: (_c = plugin$1.config) == null ? void 0 : _c.styles,
175
- scripts: (_d = plugin$1.config) == null ? void 0 : _d.scripts
177
+ styles: (_c = plugin$2.config) == null ? void 0 : _c.styles,
178
+ scripts: (_d = plugin$2.config) == null ? void 0 : _d.scripts
176
179
  };
177
180
  }
178
181
  });
179
- const name$2 = "frontmatter";
182
+ const name$3 = "frontmatter";
180
183
  const frontmatter = definePlugin({
181
- name: name$2,
184
+ name: name$3,
182
185
  transform(transformHooks) {
183
186
  transformHooks.beforeParse.tap((md, context) => {
184
187
  const { content } = context;
@@ -232,9 +235,9 @@ function normalizeNumber(value) {
232
235
  return;
233
236
  return +value;
234
237
  }
235
- const name$1 = "npmUrl";
238
+ const name$2 = "npmUrl";
236
239
  const npmUrl = definePlugin({
237
- name: name$1,
240
+ name: name$2,
238
241
  transform(transformHooks) {
239
242
  transformHooks.afterParse.tap((_, context) => {
240
243
  const { frontmatter: frontmatter2 } = context;
@@ -258,7 +261,7 @@ const npmUrl = definePlugin({
258
261
  return {};
259
262
  }
260
263
  });
261
- const name = "hljs";
264
+ const name$1 = "hljs";
262
265
  const preloadScripts = [
263
266
  `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
264
267
  ].map((path) => buildJSItem(path));
@@ -273,13 +276,13 @@ const config = {
273
276
  preloadScripts,
274
277
  styles
275
278
  };
276
- const plugin = definePlugin({
277
- name,
279
+ const plugin$1 = definePlugin({
280
+ name: name$1,
278
281
  config,
279
282
  transform(transformHooks) {
280
283
  var _a, _b, _c;
281
284
  let loading;
282
- const preloadScripts2 = ((_b = (_a = plugin.config) == null ? void 0 : _a.preloadScripts) == null ? void 0 : _b.map(
285
+ const preloadScripts2 = ((_b = (_a = plugin$1.config) == null ? void 0 : _a.preloadScripts) == null ? void 0 : _b.map(
283
286
  (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
284
287
  )) || [];
285
288
  const autoload = () => {
@@ -304,60 +307,60 @@ const plugin = definePlugin({
304
307
  });
305
308
  transformHooks.beforeParse.tap((_, context) => {
306
309
  enableFeature = () => {
307
- context.features[name] = true;
310
+ context.features[name$1] = true;
308
311
  };
309
312
  });
310
313
  return {
311
- styles: (_c = plugin.config) == null ? void 0 : _c.styles
314
+ styles: (_c = plugin$1.config) == null ? void 0 : _c.styles
312
315
  };
313
316
  }
314
317
  });
315
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
316
- function cleanNode(node) {
317
- var _a, _b;
318
- if (node.type === "heading") {
319
- node.children = node.children.filter((item) => item.type !== "paragraph");
320
- } else if (node.type === "list_item") {
321
- node.children = node.children.filter((item) => {
322
- if (["paragraph", "fence"].includes(item.type)) {
323
- if (!node.content) {
324
- node.content = item.content;
325
- node.payload = {
326
- ...node.payload,
327
- ...item.payload
328
- };
329
- }
330
- return false;
331
- }
332
- return true;
333
- });
334
- if (((_a = node.payload) == null ? void 0 : _a.index) != null) {
335
- node.content = `${node.payload.index}. ${node.content}`;
336
- }
337
- } else if (node.type === "ordered_list") {
338
- let index = ((_b = node.payload) == null ? void 0 : _b.startIndex) ?? 1;
339
- node.children.forEach((item) => {
340
- if (item.type === "list_item") {
341
- item.payload = {
342
- ...item.payload,
343
- index
344
- };
345
- index += 1;
346
- }
318
+ const name = "checkbox";
319
+ const plugin = definePlugin({
320
+ name,
321
+ transform(transformHooks) {
322
+ transformHooks.parser.tap((md) => {
323
+ md.core.ruler.before(
324
+ "inline",
325
+ "checkbox",
326
+ (state) => {
327
+ for (let i = 2; i < state.tokens.length; i += 1) {
328
+ const token = state.tokens[i];
329
+ if (token.type === "inline" && token.content) {
330
+ const prevType = state.tokens[i - 1].type;
331
+ const prevPrevType = state.tokens[i - 2].type;
332
+ if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
333
+ if (token.content.startsWith("[ ]")) {
334
+ token.content = `${svg_unmarked} ${token.content.slice(3)}`;
335
+ } else if (token.content.startsWith("[x]")) {
336
+ token.content = `${svg_marked} ${token.content.slice(3)}`;
337
+ }
338
+ }
339
+ }
340
+ }
341
+ return false;
342
+ },
343
+ {}
344
+ );
347
345
  });
346
+ return {};
348
347
  }
349
- if (node.children.length > 0) {
350
- node.children.forEach((child) => cleanNode(child));
351
- if (node.children.length === 1 && !node.children[0].content) {
352
- node.children = node.children[0].children;
353
- }
348
+ });
349
+ const plugins = [frontmatter, plugin$2, plugin$1, npmUrl, plugin];
350
+ function cleanNode(node) {
351
+ while (!node.content && node.children.length === 1) {
352
+ node = node.children[0];
354
353
  }
355
- }
356
- function resetDepth(node, depth = 0) {
357
- node.depth = depth;
358
- node.children.forEach((child) => {
359
- resetDepth(child, depth + 1);
360
- });
354
+ while (node.children.length === 1 && !node.children[0].content) {
355
+ node = {
356
+ ...node,
357
+ children: node.children[0].children
358
+ };
359
+ }
360
+ return {
361
+ ...node,
362
+ children: node.children.map(cleanNode)
363
+ };
361
364
  }
362
365
  class Transformer {
363
366
  constructor(plugins$1 = plugins) {
@@ -388,100 +391,22 @@ class Transformer {
388
391
  this.md = md;
389
392
  this.hooks.parser.call(md);
390
393
  }
391
- buildTree(tokens) {
392
- const { md } = this;
393
- const root = {
394
- type: "root",
395
- depth: 0,
396
- content: "",
397
- children: [],
398
- payload: {}
399
- };
400
- const stack = [root];
401
- let depth = 0;
402
- for (const token of tokens) {
403
- const payload = {};
404
- if (token.lines) {
405
- payload.lines = token.lines;
406
- }
407
- let current = stack[stack.length - 1];
408
- if (token.type.endsWith("_open")) {
409
- const type = token.type.slice(0, -5);
410
- if (type === "heading") {
411
- depth = token.hLevel;
412
- while ((current == null ? void 0 : current.depth) >= depth) {
413
- stack.pop();
414
- current = stack[stack.length - 1];
415
- }
416
- } else {
417
- depth = Math.max(depth, (current == null ? void 0 : current.depth) || 0) + 1;
418
- if (type === "ordered_list") {
419
- payload.startIndex = token.order;
420
- }
421
- }
422
- const item = {
423
- type,
424
- depth,
425
- payload,
426
- content: "",
427
- children: []
428
- };
429
- current.children.push(item);
430
- stack.push(item);
431
- } else if (!current) {
432
- continue;
433
- } else if (token.type === `${current.type}_close`) {
434
- if (current.type === "heading") {
435
- depth = current.depth;
436
- } else {
437
- stack.pop();
438
- depth = 0;
439
- }
440
- } else if (token.type === "inline") {
441
- const revoke = this.hooks.htmltag.tap((ctx) => {
442
- var _a;
443
- const comment = (_a = ctx.result) == null ? void 0 : _a.match(/^<!--([\s\S]*?)-->$/);
444
- const data = comment == null ? void 0 : comment[1].trim().split(" ");
445
- if ((data == null ? void 0 : data[0]) === "fold") {
446
- current.payload = {
447
- ...current.payload,
448
- fold: ["all", "recursively"].includes(data[1]) ? 2 : 1
449
- };
450
- ctx.result = "";
451
- }
452
- });
453
- const text = md.renderer.render([token], md.options, {});
454
- revoke();
455
- current.content = `${current.content || ""}${text}`;
456
- } else if (token.type === "fence") {
457
- const result = md.renderer.render([token], md.options, {});
458
- current.children.push({
459
- type: token.type,
460
- depth: depth + 1,
461
- content: result,
462
- children: [],
463
- payload
464
- });
465
- } else
466
- ;
467
- }
468
- return root;
469
- }
470
- transform(content) {
471
- var _a;
394
+ transform(content, opts) {
395
+ var _a, _b;
472
396
  const context = {
473
397
  content,
474
398
  features: {},
475
399
  contentLineOffset: 0
476
400
  };
477
401
  this.hooks.beforeParse.call(this.md, context);
478
- const tokens = this.md.parse(context.content, {});
402
+ const html = this.md.render(context.content, {});
479
403
  this.hooks.afterParse.call(this.md, context);
480
- let root = this.buildTree(tokens);
481
- cleanNode(root);
482
- if (((_a = root.children) == null ? void 0 : _a.length) === 1)
483
- root = root.children[0];
484
- resetDepth(root);
404
+ const root = cleanNode(
405
+ buildTree(html, {
406
+ ...(_b = (_a = context.frontmatter) == null ? void 0 : _a.markmap) == null ? void 0 : _b.htmlParser,
407
+ ...opts
408
+ })
409
+ );
485
410
  return { ...context, root };
486
411
  }
487
412
  /**
@@ -561,6 +486,8 @@ export {
561
486
  Transformer,
562
487
  baseJsPaths,
563
488
  plugins as builtInPlugins,
489
+ svg_marked,
490
+ svg_unmarked,
564
491
  template,
565
492
  transformerVersions
566
493
  };
@@ -1,2 +1,4 @@
1
1
  export declare const template: string;
2
2
  export declare const baseJsPaths: string[];
3
+ export declare const svg_marked = "<svg width=\"16\" height=\"16\" fill=\"currentColor\" viewBox=\"0 -3 24 24\"><path d=\"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z\"/></svg>";
4
+ export declare const svg_unmarked = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"currentColor\" viewBox=\"0 -3 24 24\"><path fill-rule=\"evenodd\" d=\"M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z\" clip-rule=\"evenodd\"/></svg>";
package/dist/index.js CHANGED
@@ -1,16 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const remarkable = require("remarkable");
4
3
  const markmapCommon = require("markmap-common");
4
+ const markmapHtmlParser = require("markmap-html-parser");
5
+ const remarkable = require("remarkable");
5
6
  const remarkableKatex = require("remarkable-katex");
6
7
  const yaml = require("js-yaml");
7
8
  const hljs = require("highlight.js");
8
9
  const template = '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<meta name="viewport" content="width=device-width, initial-scale=1.0">\n<meta http-equiv="X-UA-Compatible" content="ie=edge">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id="mindmap"></svg>\n<!--JS-->\n</body>\n</html>\n';
9
10
  const baseJsPaths = [
10
11
  `d3@${"7.8.5"}/dist/d3.min.js`,
11
- `markmap-view@${"0.15.8"}/dist/browser/index.js`
12
+ `markmap-view@${"0.15.9-alpha.5"}/dist/browser/index.js`
12
13
  ];
13
- const name$3 = "katex";
14
+ const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
15
+ const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
16
+ const name$4 = "katex";
14
17
  const preloadScripts$1 = [
15
18
  `katex@${"0.16.8"}/dist/katex.min.js`
16
19
  ].map((path) => markmapCommon.buildJSItem(path));
@@ -76,8 +79,8 @@ function createTransformHooks(transformer) {
76
79
  function definePlugin(plugin2) {
77
80
  return plugin2;
78
81
  }
79
- const plugin$1 = definePlugin({
80
- name: name$3,
82
+ const plugin$2 = definePlugin({
83
+ name: name$4,
81
84
  config: config$1,
82
85
  transform(transformHooks) {
83
86
  var _a, _b;
@@ -94,18 +97,18 @@ const plugin$1 = definePlugin({
94
97
  });
95
98
  transformHooks.beforeParse.tap((_, context) => {
96
99
  enableFeature = () => {
97
- context.features[name$3] = true;
100
+ context.features[name$4] = true;
98
101
  };
99
102
  });
100
103
  return {
101
- styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
102
- scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
104
+ styles: (_a = plugin$2.config) == null ? void 0 : _a.styles,
105
+ scripts: (_b = plugin$2.config) == null ? void 0 : _b.scripts
103
106
  };
104
107
  }
105
108
  });
106
- const name$2 = "frontmatter";
109
+ const name$3 = "frontmatter";
107
110
  const frontmatter = definePlugin({
108
- name: name$2,
111
+ name: name$3,
109
112
  transform(transformHooks) {
110
113
  transformHooks.beforeParse.tap((md, context) => {
111
114
  const { content } = context;
@@ -159,9 +162,9 @@ function normalizeNumber(value) {
159
162
  return;
160
163
  return +value;
161
164
  }
162
- const name$1 = "npmUrl";
165
+ const name$2 = "npmUrl";
163
166
  const npmUrl = definePlugin({
164
- name: name$1,
167
+ name: name$2,
165
168
  transform(transformHooks) {
166
169
  transformHooks.afterParse.tap((_, context) => {
167
170
  const { frontmatter: frontmatter2 } = context;
@@ -185,7 +188,7 @@ const npmUrl = definePlugin({
185
188
  return {};
186
189
  }
187
190
  });
188
- const name = "hljs";
191
+ const name$1 = "hljs";
189
192
  const preloadScripts = [
190
193
  `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
191
194
  ].map((path) => markmapCommon.buildJSItem(path));
@@ -200,8 +203,8 @@ const config = {
200
203
  preloadScripts,
201
204
  styles
202
205
  };
203
- const plugin = definePlugin({
204
- name,
206
+ const plugin$1 = definePlugin({
207
+ name: name$1,
205
208
  config,
206
209
  transform(transformHooks) {
207
210
  var _a;
@@ -216,15 +219,46 @@ const plugin = definePlugin({
216
219
  });
217
220
  transformHooks.beforeParse.tap((_, context) => {
218
221
  enableFeature = () => {
219
- context.features[name] = true;
222
+ context.features[name$1] = true;
220
223
  };
221
224
  });
222
225
  return {
223
- styles: (_a = plugin.config) == null ? void 0 : _a.styles
226
+ styles: (_a = plugin$1.config) == null ? void 0 : _a.styles
224
227
  };
225
228
  }
226
229
  });
227
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
230
+ const name = "checkbox";
231
+ const plugin = definePlugin({
232
+ name,
233
+ transform(transformHooks) {
234
+ transformHooks.parser.tap((md) => {
235
+ md.core.ruler.before(
236
+ "inline",
237
+ "checkbox",
238
+ (state) => {
239
+ for (let i = 2; i < state.tokens.length; i += 1) {
240
+ const token = state.tokens[i];
241
+ if (token.type === "inline" && token.content) {
242
+ const prevType = state.tokens[i - 1].type;
243
+ const prevPrevType = state.tokens[i - 2].type;
244
+ if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
245
+ if (token.content.startsWith("[ ]")) {
246
+ token.content = `${svg_unmarked} ${token.content.slice(3)}`;
247
+ } else if (token.content.startsWith("[x]")) {
248
+ token.content = `${svg_marked} ${token.content.slice(3)}`;
249
+ }
250
+ }
251
+ }
252
+ }
253
+ return false;
254
+ },
255
+ {}
256
+ );
257
+ });
258
+ return {};
259
+ }
260
+ });
261
+ const plugins = [frontmatter, plugin$2, plugin$1, npmUrl, plugin];
228
262
  function patchJSItem(urlBuilder, item) {
229
263
  if (item.type === "script" && item.data.src) {
230
264
  return {
@@ -250,50 +284,19 @@ function patchCSSItem(urlBuilder, item) {
250
284
  return item;
251
285
  }
252
286
  function cleanNode(node) {
253
- var _a, _b;
254
- if (node.type === "heading") {
255
- node.children = node.children.filter((item) => item.type !== "paragraph");
256
- } else if (node.type === "list_item") {
257
- node.children = node.children.filter((item) => {
258
- if (["paragraph", "fence"].includes(item.type)) {
259
- if (!node.content) {
260
- node.content = item.content;
261
- node.payload = {
262
- ...node.payload,
263
- ...item.payload
264
- };
265
- }
266
- return false;
267
- }
268
- return true;
269
- });
270
- if (((_a = node.payload) == null ? void 0 : _a.index) != null) {
271
- node.content = `${node.payload.index}. ${node.content}`;
272
- }
273
- } else if (node.type === "ordered_list") {
274
- let index = ((_b = node.payload) == null ? void 0 : _b.startIndex) ?? 1;
275
- node.children.forEach((item) => {
276
- if (item.type === "list_item") {
277
- item.payload = {
278
- ...item.payload,
279
- index
280
- };
281
- index += 1;
282
- }
283
- });
287
+ while (!node.content && node.children.length === 1) {
288
+ node = node.children[0];
284
289
  }
285
- if (node.children.length > 0) {
286
- node.children.forEach((child) => cleanNode(child));
287
- if (node.children.length === 1 && !node.children[0].content) {
288
- node.children = node.children[0].children;
289
- }
290
+ while (node.children.length === 1 && !node.children[0].content) {
291
+ node = {
292
+ ...node,
293
+ children: node.children[0].children
294
+ };
290
295
  }
291
- }
292
- function resetDepth(node, depth = 0) {
293
- node.depth = depth;
294
- node.children.forEach((child) => {
295
- resetDepth(child, depth + 1);
296
- });
296
+ return {
297
+ ...node,
298
+ children: node.children.map(cleanNode)
299
+ };
297
300
  }
298
301
  class Transformer {
299
302
  constructor(plugins$1 = plugins) {
@@ -324,100 +327,22 @@ class Transformer {
324
327
  this.md = md;
325
328
  this.hooks.parser.call(md);
326
329
  }
327
- buildTree(tokens) {
328
- const { md } = this;
329
- const root = {
330
- type: "root",
331
- depth: 0,
332
- content: "",
333
- children: [],
334
- payload: {}
335
- };
336
- const stack = [root];
337
- let depth = 0;
338
- for (const token of tokens) {
339
- const payload = {};
340
- if (token.lines) {
341
- payload.lines = token.lines;
342
- }
343
- let current = stack[stack.length - 1];
344
- if (token.type.endsWith("_open")) {
345
- const type = token.type.slice(0, -5);
346
- if (type === "heading") {
347
- depth = token.hLevel;
348
- while ((current == null ? void 0 : current.depth) >= depth) {
349
- stack.pop();
350
- current = stack[stack.length - 1];
351
- }
352
- } else {
353
- depth = Math.max(depth, (current == null ? void 0 : current.depth) || 0) + 1;
354
- if (type === "ordered_list") {
355
- payload.startIndex = token.order;
356
- }
357
- }
358
- const item = {
359
- type,
360
- depth,
361
- payload,
362
- content: "",
363
- children: []
364
- };
365
- current.children.push(item);
366
- stack.push(item);
367
- } else if (!current) {
368
- continue;
369
- } else if (token.type === `${current.type}_close`) {
370
- if (current.type === "heading") {
371
- depth = current.depth;
372
- } else {
373
- stack.pop();
374
- depth = 0;
375
- }
376
- } else if (token.type === "inline") {
377
- const revoke = this.hooks.htmltag.tap((ctx) => {
378
- var _a;
379
- const comment = (_a = ctx.result) == null ? void 0 : _a.match(/^<!--([\s\S]*?)-->$/);
380
- const data = comment == null ? void 0 : comment[1].trim().split(" ");
381
- if ((data == null ? void 0 : data[0]) === "fold") {
382
- current.payload = {
383
- ...current.payload,
384
- fold: ["all", "recursively"].includes(data[1]) ? 2 : 1
385
- };
386
- ctx.result = "";
387
- }
388
- });
389
- const text = md.renderer.render([token], md.options, {});
390
- revoke();
391
- current.content = `${current.content || ""}${text}`;
392
- } else if (token.type === "fence") {
393
- const result = md.renderer.render([token], md.options, {});
394
- current.children.push({
395
- type: token.type,
396
- depth: depth + 1,
397
- content: result,
398
- children: [],
399
- payload
400
- });
401
- } else
402
- ;
403
- }
404
- return root;
405
- }
406
- transform(content) {
407
- var _a;
330
+ transform(content, opts) {
331
+ var _a, _b;
408
332
  const context = {
409
333
  content,
410
334
  features: {},
411
335
  contentLineOffset: 0
412
336
  };
413
337
  this.hooks.beforeParse.call(this.md, context);
414
- const tokens = this.md.parse(context.content, {});
338
+ const html = this.md.render(context.content, {});
415
339
  this.hooks.afterParse.call(this.md, context);
416
- let root = this.buildTree(tokens);
417
- cleanNode(root);
418
- if (((_a = root.children) == null ? void 0 : _a.length) === 1)
419
- root = root.children[0];
420
- resetDepth(root);
340
+ const root = cleanNode(
341
+ markmapHtmlParser.buildTree(html, {
342
+ ...(_b = (_a = context.frontmatter) == null ? void 0 : _a.markmap) == null ? void 0 : _b.htmlParser,
343
+ ...opts
344
+ })
345
+ );
421
346
  return { ...context, root };
422
347
  }
423
348
  /**
@@ -496,5 +421,7 @@ const transformerVersions = {
496
421
  exports.Transformer = Transformer;
497
422
  exports.baseJsPaths = baseJsPaths;
498
423
  exports.builtInPlugins = plugins;
424
+ exports.svg_marked = svg_marked;
425
+ exports.svg_unmarked = svg_unmarked;
499
426
  exports.template = template;
500
427
  exports.transformerVersions = transformerVersions;