markmap-lib 0.15.7 → 0.15.9-alpha.0
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.
- package/dist/browser/index.iife.js +17622 -3999
- package/dist/browser/index.mjs +23 -131
- package/dist/index.js +23 -131
- package/dist/index.mjs +23 -131
- package/dist/transform.d.ts +4 -4
- package/dist/types.d.ts +6 -1
- package/package.json +5 -4
package/dist/browser/index.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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.
|
|
9
|
+
`markmap-view@${"0.15.9-alpha.0"}/dist/browser/index.js`
|
|
9
10
|
];
|
|
10
11
|
const name$3 = "katex";
|
|
11
12
|
const preloadScripts$1 = [
|
|
@@ -314,50 +315,19 @@ const plugin = definePlugin({
|
|
|
314
315
|
});
|
|
315
316
|
const plugins = [frontmatter, plugin$1, plugin, npmUrl];
|
|
316
317
|
function cleanNode(node) {
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
}
|
|
347
|
-
});
|
|
318
|
+
while (!node.content && node.children.length === 1) {
|
|
319
|
+
node = node.children[0];
|
|
348
320
|
}
|
|
349
|
-
|
|
350
|
-
node
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
321
|
+
while (node.children.length === 1 && !node.children[0].content) {
|
|
322
|
+
node = {
|
|
323
|
+
...node,
|
|
324
|
+
children: node.children[0].children
|
|
325
|
+
};
|
|
354
326
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
resetDepth(child, depth + 1);
|
|
360
|
-
});
|
|
327
|
+
return {
|
|
328
|
+
...node,
|
|
329
|
+
children: node.children.map(cleanNode)
|
|
330
|
+
};
|
|
361
331
|
}
|
|
362
332
|
class Transformer {
|
|
363
333
|
constructor(plugins$1 = plugins) {
|
|
@@ -388,100 +358,22 @@ class Transformer {
|
|
|
388
358
|
this.md = md;
|
|
389
359
|
this.hooks.parser.call(md);
|
|
390
360
|
}
|
|
391
|
-
|
|
392
|
-
|
|
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;
|
|
361
|
+
transform(content, opts) {
|
|
362
|
+
var _a, _b;
|
|
472
363
|
const context = {
|
|
473
364
|
content,
|
|
474
365
|
features: {},
|
|
475
366
|
contentLineOffset: 0
|
|
476
367
|
};
|
|
477
368
|
this.hooks.beforeParse.call(this.md, context);
|
|
478
|
-
const
|
|
369
|
+
const html = this.md.render(context.content, {});
|
|
479
370
|
this.hooks.afterParse.call(this.md, context);
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
371
|
+
const root = cleanNode(
|
|
372
|
+
buildTree(html, {
|
|
373
|
+
...(_b = (_a = context.frontmatter) == null ? void 0 : _a.markmap) == null ? void 0 : _b.htmlParser,
|
|
374
|
+
...opts
|
|
375
|
+
})
|
|
376
|
+
);
|
|
485
377
|
return { ...context, root };
|
|
486
378
|
}
|
|
487
379
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
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.
|
|
12
|
+
`markmap-view@${"0.15.9-alpha.0"}/dist/browser/index.js`
|
|
12
13
|
];
|
|
13
14
|
const name$3 = "katex";
|
|
14
15
|
const preloadScripts$1 = [
|
|
@@ -250,50 +251,19 @@ function patchCSSItem(urlBuilder, item) {
|
|
|
250
251
|
return item;
|
|
251
252
|
}
|
|
252
253
|
function cleanNode(node) {
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
});
|
|
254
|
+
while (!node.content && node.children.length === 1) {
|
|
255
|
+
node = node.children[0];
|
|
284
256
|
}
|
|
285
|
-
|
|
286
|
-
node
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
257
|
+
while (node.children.length === 1 && !node.children[0].content) {
|
|
258
|
+
node = {
|
|
259
|
+
...node,
|
|
260
|
+
children: node.children[0].children
|
|
261
|
+
};
|
|
290
262
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
resetDepth(child, depth + 1);
|
|
296
|
-
});
|
|
263
|
+
return {
|
|
264
|
+
...node,
|
|
265
|
+
children: node.children.map(cleanNode)
|
|
266
|
+
};
|
|
297
267
|
}
|
|
298
268
|
class Transformer {
|
|
299
269
|
constructor(plugins$1 = plugins) {
|
|
@@ -324,100 +294,22 @@ class Transformer {
|
|
|
324
294
|
this.md = md;
|
|
325
295
|
this.hooks.parser.call(md);
|
|
326
296
|
}
|
|
327
|
-
|
|
328
|
-
|
|
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;
|
|
297
|
+
transform(content, opts) {
|
|
298
|
+
var _a, _b;
|
|
408
299
|
const context = {
|
|
409
300
|
content,
|
|
410
301
|
features: {},
|
|
411
302
|
contentLineOffset: 0
|
|
412
303
|
};
|
|
413
304
|
this.hooks.beforeParse.call(this.md, context);
|
|
414
|
-
const
|
|
305
|
+
const html = this.md.render(context.content, {});
|
|
415
306
|
this.hooks.afterParse.call(this.md, context);
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
307
|
+
const root = cleanNode(
|
|
308
|
+
markmapHtmlParser.buildTree(html, {
|
|
309
|
+
...(_b = (_a = context.frontmatter) == null ? void 0 : _a.markmap) == null ? void 0 : _b.htmlParser,
|
|
310
|
+
...opts
|
|
311
|
+
})
|
|
312
|
+
);
|
|
421
313
|
return { ...context, root };
|
|
422
314
|
}
|
|
423
315
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Remarkable } from "remarkable";
|
|
2
1
|
import { buildJSItem, buildCSSItem, Hook, wrapFunction, noop, UrlBuilder, 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
|
import hljs from "highlight.js";
|
|
6
7
|
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';
|
|
7
8
|
const baseJsPaths = [
|
|
8
9
|
`d3@${"7.8.5"}/dist/d3.min.js`,
|
|
9
|
-
`markmap-view@${"0.15.
|
|
10
|
+
`markmap-view@${"0.15.9-alpha.0"}/dist/browser/index.js`
|
|
10
11
|
];
|
|
11
12
|
const name$3 = "katex";
|
|
12
13
|
const preloadScripts$1 = [
|
|
@@ -248,50 +249,19 @@ function patchCSSItem(urlBuilder, item) {
|
|
|
248
249
|
return item;
|
|
249
250
|
}
|
|
250
251
|
function cleanNode(node) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
node.children = node.children.filter((item) => item.type !== "paragraph");
|
|
254
|
-
} else if (node.type === "list_item") {
|
|
255
|
-
node.children = node.children.filter((item) => {
|
|
256
|
-
if (["paragraph", "fence"].includes(item.type)) {
|
|
257
|
-
if (!node.content) {
|
|
258
|
-
node.content = item.content;
|
|
259
|
-
node.payload = {
|
|
260
|
-
...node.payload,
|
|
261
|
-
...item.payload
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
return true;
|
|
267
|
-
});
|
|
268
|
-
if (((_a = node.payload) == null ? void 0 : _a.index) != null) {
|
|
269
|
-
node.content = `${node.payload.index}. ${node.content}`;
|
|
270
|
-
}
|
|
271
|
-
} else if (node.type === "ordered_list") {
|
|
272
|
-
let index = ((_b = node.payload) == null ? void 0 : _b.startIndex) ?? 1;
|
|
273
|
-
node.children.forEach((item) => {
|
|
274
|
-
if (item.type === "list_item") {
|
|
275
|
-
item.payload = {
|
|
276
|
-
...item.payload,
|
|
277
|
-
index
|
|
278
|
-
};
|
|
279
|
-
index += 1;
|
|
280
|
-
}
|
|
281
|
-
});
|
|
252
|
+
while (!node.content && node.children.length === 1) {
|
|
253
|
+
node = node.children[0];
|
|
282
254
|
}
|
|
283
|
-
|
|
284
|
-
node
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
255
|
+
while (node.children.length === 1 && !node.children[0].content) {
|
|
256
|
+
node = {
|
|
257
|
+
...node,
|
|
258
|
+
children: node.children[0].children
|
|
259
|
+
};
|
|
288
260
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
resetDepth(child, depth + 1);
|
|
294
|
-
});
|
|
261
|
+
return {
|
|
262
|
+
...node,
|
|
263
|
+
children: node.children.map(cleanNode)
|
|
264
|
+
};
|
|
295
265
|
}
|
|
296
266
|
class Transformer {
|
|
297
267
|
constructor(plugins$1 = plugins) {
|
|
@@ -322,100 +292,22 @@ class Transformer {
|
|
|
322
292
|
this.md = md;
|
|
323
293
|
this.hooks.parser.call(md);
|
|
324
294
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const root = {
|
|
328
|
-
type: "root",
|
|
329
|
-
depth: 0,
|
|
330
|
-
content: "",
|
|
331
|
-
children: [],
|
|
332
|
-
payload: {}
|
|
333
|
-
};
|
|
334
|
-
const stack = [root];
|
|
335
|
-
let depth = 0;
|
|
336
|
-
for (const token of tokens) {
|
|
337
|
-
const payload = {};
|
|
338
|
-
if (token.lines) {
|
|
339
|
-
payload.lines = token.lines;
|
|
340
|
-
}
|
|
341
|
-
let current = stack[stack.length - 1];
|
|
342
|
-
if (token.type.endsWith("_open")) {
|
|
343
|
-
const type = token.type.slice(0, -5);
|
|
344
|
-
if (type === "heading") {
|
|
345
|
-
depth = token.hLevel;
|
|
346
|
-
while ((current == null ? void 0 : current.depth) >= depth) {
|
|
347
|
-
stack.pop();
|
|
348
|
-
current = stack[stack.length - 1];
|
|
349
|
-
}
|
|
350
|
-
} else {
|
|
351
|
-
depth = Math.max(depth, (current == null ? void 0 : current.depth) || 0) + 1;
|
|
352
|
-
if (type === "ordered_list") {
|
|
353
|
-
payload.startIndex = token.order;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
const item = {
|
|
357
|
-
type,
|
|
358
|
-
depth,
|
|
359
|
-
payload,
|
|
360
|
-
content: "",
|
|
361
|
-
children: []
|
|
362
|
-
};
|
|
363
|
-
current.children.push(item);
|
|
364
|
-
stack.push(item);
|
|
365
|
-
} else if (!current) {
|
|
366
|
-
continue;
|
|
367
|
-
} else if (token.type === `${current.type}_close`) {
|
|
368
|
-
if (current.type === "heading") {
|
|
369
|
-
depth = current.depth;
|
|
370
|
-
} else {
|
|
371
|
-
stack.pop();
|
|
372
|
-
depth = 0;
|
|
373
|
-
}
|
|
374
|
-
} else if (token.type === "inline") {
|
|
375
|
-
const revoke = this.hooks.htmltag.tap((ctx) => {
|
|
376
|
-
var _a;
|
|
377
|
-
const comment = (_a = ctx.result) == null ? void 0 : _a.match(/^<!--([\s\S]*?)-->$/);
|
|
378
|
-
const data = comment == null ? void 0 : comment[1].trim().split(" ");
|
|
379
|
-
if ((data == null ? void 0 : data[0]) === "fold") {
|
|
380
|
-
current.payload = {
|
|
381
|
-
...current.payload,
|
|
382
|
-
fold: ["all", "recursively"].includes(data[1]) ? 2 : 1
|
|
383
|
-
};
|
|
384
|
-
ctx.result = "";
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
const text = md.renderer.render([token], md.options, {});
|
|
388
|
-
revoke();
|
|
389
|
-
current.content = `${current.content || ""}${text}`;
|
|
390
|
-
} else if (token.type === "fence") {
|
|
391
|
-
const result = md.renderer.render([token], md.options, {});
|
|
392
|
-
current.children.push({
|
|
393
|
-
type: token.type,
|
|
394
|
-
depth: depth + 1,
|
|
395
|
-
content: result,
|
|
396
|
-
children: [],
|
|
397
|
-
payload
|
|
398
|
-
});
|
|
399
|
-
} else
|
|
400
|
-
;
|
|
401
|
-
}
|
|
402
|
-
return root;
|
|
403
|
-
}
|
|
404
|
-
transform(content) {
|
|
405
|
-
var _a;
|
|
295
|
+
transform(content, opts) {
|
|
296
|
+
var _a, _b;
|
|
406
297
|
const context = {
|
|
407
298
|
content,
|
|
408
299
|
features: {},
|
|
409
300
|
contentLineOffset: 0
|
|
410
301
|
};
|
|
411
302
|
this.hooks.beforeParse.call(this.md, context);
|
|
412
|
-
const
|
|
303
|
+
const html = this.md.render(context.content, {});
|
|
413
304
|
this.hooks.afterParse.call(this.md, context);
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
305
|
+
const root = cleanNode(
|
|
306
|
+
buildTree(html, {
|
|
307
|
+
...(_b = (_a = context.frontmatter) == null ? void 0 : _a.markmap) == null ? void 0 : _b.htmlParser,
|
|
308
|
+
...opts
|
|
309
|
+
})
|
|
310
|
+
);
|
|
419
311
|
return { ...context, root };
|
|
420
312
|
}
|
|
421
313
|
/**
|
package/dist/transform.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { IMarkmapOptions, IPureNode, JSItem, UrlBuilder } from 'markmap-common';
|
|
2
|
+
import { IHtmlParserOptions } from 'markmap-html-parser';
|
|
1
3
|
import { Remarkable } from 'remarkable';
|
|
2
|
-
import { UrlBuilder, JSItem, IMarkmapOptions, IMarkmapJSONOptions, IPureNode } from 'markmap-common';
|
|
3
|
-
import { ITransformResult, ITransformPlugin, IAssets, ITransformHooks, IFeatures, ITransformer } from './types';
|
|
4
4
|
import { plugins as builtInPlugins } from './plugins';
|
|
5
|
+
import { IAssets, IFeatures, ITransformHooks, ITransformPlugin, ITransformResult, ITransformer, IMarkmapJSONOptions } from './types';
|
|
5
6
|
export { builtInPlugins };
|
|
6
7
|
export declare class Transformer implements ITransformer {
|
|
7
8
|
hooks: ITransformHooks;
|
|
@@ -10,8 +11,7 @@ export declare class Transformer implements ITransformer {
|
|
|
10
11
|
urlBuilder: UrlBuilder;
|
|
11
12
|
plugins: ITransformPlugin[];
|
|
12
13
|
constructor(plugins?: Array<ITransformPlugin | (() => ITransformPlugin)>);
|
|
13
|
-
|
|
14
|
-
transform(content: string): ITransformResult;
|
|
14
|
+
transform(content: string, opts?: Partial<IHtmlParserOptions>): ITransformResult;
|
|
15
15
|
/**
|
|
16
16
|
* Get all assets from enabled plugins or filter them by plugin names as keys.
|
|
17
17
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CSSItem, Hook, IPureNode, IWrapContext, JSItem, UrlBuilder } from 'markmap-common';
|
|
2
|
+
import { IHtmlParserOptions } from 'markmap-html-parser';
|
|
3
|
+
import { IMarkmapJSONOptions as IMarkmapJSONOptionsForView } from 'markmap-view';
|
|
1
4
|
import type { Remarkable } from 'remarkable';
|
|
2
|
-
import { UrlBuilder, CSSItem, JSItem, IPureNode, IWrapContext, Hook, IMarkmapJSONOptions } from 'markmap-common';
|
|
3
5
|
type Htmltag = Remarkable.Rule<Remarkable.HtmlTagToken, string>;
|
|
4
6
|
export interface ITransformHooks {
|
|
5
7
|
transformer: ITransformer;
|
|
@@ -45,6 +47,9 @@ export interface IFeatures {
|
|
|
45
47
|
export interface ITransformer {
|
|
46
48
|
urlBuilder: UrlBuilder;
|
|
47
49
|
}
|
|
50
|
+
export interface IMarkmapJSONOptions extends IMarkmapJSONOptionsForView {
|
|
51
|
+
htmlParser?: Partial<IHtmlParserOptions>;
|
|
52
|
+
}
|
|
48
53
|
export interface ITransformContext {
|
|
49
54
|
features: IFeatures;
|
|
50
55
|
content: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-lib",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.9-alpha.0+9cb40e7",
|
|
4
4
|
"description": "Visualize your Markdown as mindmaps with Markmap",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@highlightjs/cdn-assets": "^11.8.0",
|
|
49
49
|
"@types/remarkable": "^2.0.3",
|
|
50
|
-
"markmap-common": "0.15.
|
|
51
|
-
"markmap-view": "0.15.
|
|
50
|
+
"markmap-common": "0.15.9-alpha.0+9cb40e7",
|
|
51
|
+
"markmap-view": "0.15.9-alpha.0+9cb40e7",
|
|
52
52
|
"webfontloader": "^1.6.28"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"highlight.js": "^11.8.0",
|
|
57
57
|
"js-yaml": "^4.1.0",
|
|
58
58
|
"katex": "^0.16.8",
|
|
59
|
+
"markmap-html-parser": "0.15.9-alpha.0+9cb40e7",
|
|
59
60
|
"prismjs": "^1.29.0",
|
|
60
61
|
"remarkable": "^2.0.1",
|
|
61
62
|
"remarkable-katex": "^1.2.1"
|
|
@@ -73,5 +74,5 @@
|
|
|
73
74
|
]
|
|
74
75
|
}
|
|
75
76
|
},
|
|
76
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "9cb40e7e9ec0aa1f25a2de6a74912cd0c21f52ed"
|
|
77
78
|
}
|