markmap-lib 0.15.9-alpha.6 → 0.16.1
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 +135 -213
- package/dist/browser/index.mjs +37 -81
- package/dist/index.d.ts +1 -3
- package/dist/index.js +17 -352
- package/dist/index.mjs +18 -353
- package/dist/index.no-plugins.js +136 -0
- package/dist/index.no-plugins.mjs +136 -0
- package/dist/plugins/checkbox/index.d.ts +2 -0
- package/dist/plugins/frontmatter/index.d.ts +2 -0
- package/dist/plugins/hljs/index.browser.d.ts +2 -0
- package/dist/plugins/hljs/index.d.ts +2 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/katex/index.browser.d.ts +2 -0
- package/dist/plugins/katex/index.d.ts +2 -0
- package/dist/plugins/npm-url/index.d.ts +2 -0
- package/dist/plugins/prism/index.browser.d.ts +2 -0
- package/dist/plugins/prism/index.d.ts +2 -0
- package/dist/plugins/source-lines/index.d.ts +2 -0
- package/dist/plugins.js +307 -0
- package/dist/plugins.mjs +307 -0
- package/dist/transform.d.ts +3 -9
- package/package.json +23 -7
- package/dist/constants.d.ts +0 -4
- package/dist/plugins/checkbox.d.ts +0 -2
- package/dist/plugins/frontmatter.d.ts +0 -2
- package/dist/plugins/hljs.browser.d.ts +0 -2
- package/dist/plugins/hljs.d.ts +0 -2
- package/dist/plugins/katex.browser.d.ts +0 -2
- package/dist/plugins/katex.d.ts +0 -2
- package/dist/plugins/npm-url.d.ts +0 -2
- package/dist/plugins/prism.browser.d.ts +0 -2
- package/dist/plugins/prism.d.ts +0 -2
- package/dist/plugins/source-lines.d.ts +0 -2
- /package/dist/plugins/{hljs.config.d.ts → hljs/config.d.ts} +0 -0
- /package/dist/plugins/{katex.config.d.ts → katex/config.d.ts} +0 -0
- /package/dist/plugins/{prism.config.d.ts → prism/config.d.ts} +0 -0
package/dist/browser/index.mjs
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import { Hook, buildJSItem, buildCSSItem, loadJS, noop, wrapFunction, UrlBuilder
|
|
1
|
+
import { Hook, buildJSItem, buildCSSItem, loadJS, noop, wrapFunction, UrlBuilder } from "markmap-common";
|
|
2
2
|
import { buildTree } from "markmap-html-parser";
|
|
3
3
|
import { Remarkable } from "remarkable";
|
|
4
4
|
import yaml from "js-yaml";
|
|
5
5
|
import remarkableKatex from "remarkable-katex";
|
|
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';
|
|
7
|
-
const baseJsPaths = [
|
|
8
|
-
`d3@${"7.8.5"}/dist/d3.min.js`,
|
|
9
|
-
`markmap-view@${"0.15.9-alpha.6"}/dist/browser/index.js`
|
|
10
|
-
];
|
|
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
6
|
function createTransformHooks(transformer) {
|
|
14
7
|
return {
|
|
15
8
|
transformer,
|
|
@@ -23,7 +16,13 @@ function createTransformHooks(transformer) {
|
|
|
23
16
|
function definePlugin(plugin2) {
|
|
24
17
|
return plugin2;
|
|
25
18
|
}
|
|
19
|
+
const svgMarked = '<svg width="16" height="16" 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>\n';
|
|
20
|
+
const svgUnmarked = '<svg width="16" height="16" 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>\n';
|
|
26
21
|
const name$5 = "checkbox";
|
|
22
|
+
const images = {
|
|
23
|
+
" ": svgUnmarked.trim(),
|
|
24
|
+
x: svgMarked.trim()
|
|
25
|
+
};
|
|
27
26
|
const plugin$3 = definePlugin({
|
|
28
27
|
name: name$5,
|
|
29
28
|
transform(transformHooks) {
|
|
@@ -38,11 +37,10 @@ const plugin$3 = definePlugin({
|
|
|
38
37
|
const prevType = state.tokens[i - 1].type;
|
|
39
38
|
const prevPrevType = state.tokens[i - 2].type;
|
|
40
39
|
if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
40
|
+
token.content = token.content.replace(
|
|
41
|
+
/^\[(.)\] /,
|
|
42
|
+
(m, g) => images[g] ? `${images[g]} ` : m
|
|
43
|
+
);
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
}
|
|
@@ -54,8 +52,9 @@ const plugin$3 = definePlugin({
|
|
|
54
52
|
return {};
|
|
55
53
|
}
|
|
56
54
|
});
|
|
55
|
+
const pluginCheckbox = plugin$3;
|
|
57
56
|
const name$4 = "frontmatter";
|
|
58
|
-
const
|
|
57
|
+
const pluginFrontmatter = definePlugin({
|
|
59
58
|
name: name$4,
|
|
60
59
|
transform(transformHooks) {
|
|
61
60
|
transformHooks.beforeParse.tap((md, context) => {
|
|
@@ -66,18 +65,18 @@ const frontmatter = definePlugin({
|
|
|
66
65
|
if (!match)
|
|
67
66
|
return;
|
|
68
67
|
const raw = content.slice(4, match.index);
|
|
69
|
-
let
|
|
68
|
+
let frontmatter;
|
|
70
69
|
try {
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
frontmatter = yaml.load(raw);
|
|
71
|
+
if (frontmatter == null ? void 0 : frontmatter.markmap) {
|
|
72
|
+
frontmatter.markmap = normalizeMarkmapJsonOptions(
|
|
73
|
+
frontmatter.markmap
|
|
75
74
|
);
|
|
76
75
|
}
|
|
77
76
|
} catch {
|
|
78
77
|
return;
|
|
79
78
|
}
|
|
80
|
-
context.frontmatter =
|
|
79
|
+
context.frontmatter = frontmatter;
|
|
81
80
|
context.content = content.slice(match.index + match[0].length);
|
|
82
81
|
context.contentLineOffset = content.slice(0, match.index).split("\n").length + 1;
|
|
83
82
|
});
|
|
@@ -140,7 +139,6 @@ const preloadScripts$1 = [
|
|
|
140
139
|
].map((path) => buildJSItem(path));
|
|
141
140
|
const styles$1 = [
|
|
142
141
|
`@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
|
|
143
|
-
// `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
|
|
144
142
|
].map((path) => buildCSSItem(path));
|
|
145
143
|
const config$1 = {
|
|
146
144
|
versions: {
|
|
@@ -188,6 +186,7 @@ const plugin$2 = definePlugin({
|
|
|
188
186
|
};
|
|
189
187
|
}
|
|
190
188
|
});
|
|
189
|
+
const pluginHljs = plugin$2;
|
|
191
190
|
const name$2 = "katex";
|
|
192
191
|
const preloadScripts = [
|
|
193
192
|
`katex@${"0.16.8"}/dist/katex.min.js`
|
|
@@ -320,13 +319,14 @@ const plugin$1 = definePlugin({
|
|
|
320
319
|
};
|
|
321
320
|
}
|
|
322
321
|
});
|
|
322
|
+
const pluginKatex = plugin$1;
|
|
323
323
|
const name$1 = "npmUrl";
|
|
324
|
-
const
|
|
324
|
+
const pluginNpmUrl = definePlugin({
|
|
325
325
|
name: name$1,
|
|
326
326
|
transform(transformHooks) {
|
|
327
327
|
transformHooks.afterParse.tap((_, context) => {
|
|
328
|
-
const { frontmatter
|
|
329
|
-
const markmap =
|
|
328
|
+
const { frontmatter } = context;
|
|
329
|
+
const markmap = frontmatter == null ? void 0 : frontmatter.markmap;
|
|
330
330
|
if (markmap) {
|
|
331
331
|
["extraJs", "extraCss"].forEach((key) => {
|
|
332
332
|
const value = markmap[key];
|
|
@@ -364,7 +364,7 @@ const plugin = definePlugin({
|
|
|
364
364
|
return {};
|
|
365
365
|
}
|
|
366
366
|
});
|
|
367
|
-
function patchRule(rule) {
|
|
367
|
+
function patchRule(rule, _key) {
|
|
368
368
|
return wrapFunction(rule, (render, tokens, idx, ...rest) => {
|
|
369
369
|
let html = render(tokens, idx, ...rest);
|
|
370
370
|
const { lines } = tokens[idx];
|
|
@@ -377,14 +377,16 @@ function patchRule(rule) {
|
|
|
377
377
|
return html;
|
|
378
378
|
});
|
|
379
379
|
}
|
|
380
|
+
const pluginSourceLines = plugin;
|
|
380
381
|
const plugins = [
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
382
|
+
pluginFrontmatter,
|
|
383
|
+
pluginKatex,
|
|
384
|
+
pluginHljs,
|
|
385
|
+
pluginNpmUrl,
|
|
386
|
+
pluginCheckbox,
|
|
387
|
+
pluginSourceLines
|
|
387
388
|
];
|
|
389
|
+
const builtInPlugins = plugins;
|
|
388
390
|
function cleanNode(node) {
|
|
389
391
|
while (!node.content && node.children.length === 1) {
|
|
390
392
|
node = node.children[0];
|
|
@@ -401,11 +403,11 @@ function cleanNode(node) {
|
|
|
401
403
|
};
|
|
402
404
|
}
|
|
403
405
|
class Transformer {
|
|
404
|
-
constructor(
|
|
406
|
+
constructor(plugins2 = builtInPlugins) {
|
|
405
407
|
this.assetsMap = {};
|
|
406
408
|
this.urlBuilder = new UrlBuilder();
|
|
407
409
|
this.hooks = createTransformHooks(this);
|
|
408
|
-
this.plugins =
|
|
410
|
+
this.plugins = plugins2.map(
|
|
409
411
|
(plugin2) => typeof plugin2 === "function" ? plugin2() : plugin2
|
|
410
412
|
);
|
|
411
413
|
const assetsMap = {};
|
|
@@ -474,58 +476,12 @@ class Transformer {
|
|
|
474
476
|
const keys = this.plugins.map((plugin2) => plugin2.name).filter((name2) => features[name2]);
|
|
475
477
|
return this.getAssets(keys);
|
|
476
478
|
}
|
|
477
|
-
fillTemplate(root, assets, extra) {
|
|
478
|
-
extra = {
|
|
479
|
-
...extra
|
|
480
|
-
};
|
|
481
|
-
extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => buildJSItem(path)));
|
|
482
|
-
const { scripts, styles: styles2 } = assets;
|
|
483
|
-
const cssList = [...styles2 ? persistCSS(styles2) : []];
|
|
484
|
-
const context = {
|
|
485
|
-
getMarkmap: () => window.markmap,
|
|
486
|
-
getOptions: extra.getOptions,
|
|
487
|
-
jsonOptions: extra.jsonOptions,
|
|
488
|
-
root
|
|
489
|
-
};
|
|
490
|
-
const jsList = [
|
|
491
|
-
...persistJS(
|
|
492
|
-
[
|
|
493
|
-
...extra.baseJs,
|
|
494
|
-
...scripts || [],
|
|
495
|
-
{
|
|
496
|
-
type: "iife",
|
|
497
|
-
data: {
|
|
498
|
-
fn: (getMarkmap, getOptions, root2, jsonOptions) => {
|
|
499
|
-
const markmap = getMarkmap();
|
|
500
|
-
window.mm = markmap.Markmap.create(
|
|
501
|
-
"svg#mindmap",
|
|
502
|
-
(getOptions || markmap.deriveOptions)(jsonOptions),
|
|
503
|
-
root2
|
|
504
|
-
);
|
|
505
|
-
},
|
|
506
|
-
getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
|
|
507
|
-
return [getMarkmap, getOptions, root2, jsonOptions];
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
],
|
|
512
|
-
context
|
|
513
|
-
)
|
|
514
|
-
];
|
|
515
|
-
const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
|
|
516
|
-
return html;
|
|
517
|
-
}
|
|
518
479
|
}
|
|
519
480
|
const transformerVersions = {
|
|
520
|
-
"markmap-lib": "
|
|
521
|
-
d3: "7.8.5"
|
|
481
|
+
"markmap-lib": "0.16.1"
|
|
522
482
|
};
|
|
523
483
|
export {
|
|
524
484
|
Transformer,
|
|
525
|
-
|
|
526
|
-
plugins as builtInPlugins,
|
|
527
|
-
svg_marked,
|
|
528
|
-
svg_unmarked,
|
|
529
|
-
template,
|
|
485
|
+
builtInPlugins,
|
|
530
486
|
transformerVersions
|
|
531
487
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,300 +3,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const markmapCommon = require("markmap-common");
|
|
4
4
|
const markmapHtmlParser = require("markmap-html-parser");
|
|
5
5
|
const remarkable = require("remarkable");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const baseJsPaths = [
|
|
11
|
-
`d3@${"7.8.5"}/dist/d3.min.js`,
|
|
12
|
-
`markmap-view@${"0.15.9-alpha.6"}/dist/browser/index.js`
|
|
13
|
-
];
|
|
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
|
-
function createTransformHooks(transformer) {
|
|
17
|
-
return {
|
|
18
|
-
transformer,
|
|
19
|
-
parser: new markmapCommon.Hook(),
|
|
20
|
-
beforeParse: new markmapCommon.Hook(),
|
|
21
|
-
afterParse: new markmapCommon.Hook(),
|
|
22
|
-
htmltag: new markmapCommon.Hook(),
|
|
23
|
-
retransform: new markmapCommon.Hook()
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function definePlugin(plugin2) {
|
|
27
|
-
return plugin2;
|
|
28
|
-
}
|
|
29
|
-
const name$5 = "checkbox";
|
|
30
|
-
const plugin$3 = definePlugin({
|
|
31
|
-
name: name$5,
|
|
32
|
-
transform(transformHooks) {
|
|
33
|
-
transformHooks.parser.tap((md) => {
|
|
34
|
-
md.core.ruler.before(
|
|
35
|
-
"inline",
|
|
36
|
-
"checkbox",
|
|
37
|
-
(state) => {
|
|
38
|
-
for (let i = 2; i < state.tokens.length; i += 1) {
|
|
39
|
-
const token = state.tokens[i];
|
|
40
|
-
if (token.type === "inline" && token.content) {
|
|
41
|
-
const prevType = state.tokens[i - 1].type;
|
|
42
|
-
const prevPrevType = state.tokens[i - 2].type;
|
|
43
|
-
if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
|
|
44
|
-
if (token.content.startsWith("[ ]")) {
|
|
45
|
-
token.content = `${svg_unmarked} ${token.content.slice(3)}`;
|
|
46
|
-
} else if (token.content.startsWith("[x]")) {
|
|
47
|
-
token.content = `${svg_marked} ${token.content.slice(3)}`;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
53
|
-
},
|
|
54
|
-
{}
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
const name$4 = "frontmatter";
|
|
61
|
-
const frontmatter = definePlugin({
|
|
62
|
-
name: name$4,
|
|
63
|
-
transform(transformHooks) {
|
|
64
|
-
transformHooks.beforeParse.tap((md, context) => {
|
|
65
|
-
const { content } = context;
|
|
66
|
-
if (!/^---\r?\n/.test(content))
|
|
67
|
-
return;
|
|
68
|
-
const match = /\n---\r?\n/.exec(content);
|
|
69
|
-
if (!match)
|
|
70
|
-
return;
|
|
71
|
-
const raw = content.slice(4, match.index);
|
|
72
|
-
let frontmatter2;
|
|
73
|
-
try {
|
|
74
|
-
frontmatter2 = yaml.load(raw);
|
|
75
|
-
if (frontmatter2 == null ? void 0 : frontmatter2.markmap) {
|
|
76
|
-
frontmatter2.markmap = normalizeMarkmapJsonOptions(
|
|
77
|
-
frontmatter2.markmap
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
} catch {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
context.frontmatter = frontmatter2;
|
|
84
|
-
context.content = content.slice(match.index + match[0].length);
|
|
85
|
-
context.contentLineOffset = content.slice(0, match.index).split("\n").length + 1;
|
|
86
|
-
});
|
|
87
|
-
return {};
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
function normalizeMarkmapJsonOptions(options) {
|
|
91
|
-
if (!options)
|
|
92
|
-
return;
|
|
93
|
-
["color", "extraJs", "extraCss"].forEach((key) => {
|
|
94
|
-
if (options[key] != null)
|
|
95
|
-
options[key] = normalizeStringArray(options[key]);
|
|
96
|
-
});
|
|
97
|
-
["duration", "maxWidth", "initialExpandLevel"].forEach((key) => {
|
|
98
|
-
if (options[key] != null)
|
|
99
|
-
options[key] = normalizeNumber(options[key]);
|
|
100
|
-
});
|
|
101
|
-
return options;
|
|
102
|
-
}
|
|
103
|
-
function normalizeStringArray(value) {
|
|
104
|
-
let result;
|
|
105
|
-
if (typeof value === "string")
|
|
106
|
-
result = [value];
|
|
107
|
-
else if (Array.isArray(value))
|
|
108
|
-
result = value.filter((item) => item && typeof item === "string");
|
|
109
|
-
return (result == null ? void 0 : result.length) ? result : void 0;
|
|
110
|
-
}
|
|
111
|
-
function normalizeNumber(value) {
|
|
112
|
-
if (isNaN(+value))
|
|
113
|
-
return;
|
|
114
|
-
return +value;
|
|
115
|
-
}
|
|
116
|
-
const name$3 = "hljs";
|
|
117
|
-
const preloadScripts$1 = [
|
|
118
|
-
`@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
|
|
119
|
-
].map((path) => markmapCommon.buildJSItem(path));
|
|
120
|
-
const styles$1 = [
|
|
121
|
-
`@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
|
|
122
|
-
// `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
|
|
123
|
-
].map((path) => markmapCommon.buildCSSItem(path));
|
|
124
|
-
const config$1 = {
|
|
125
|
-
versions: {
|
|
126
|
-
hljs: "11.8.0"
|
|
127
|
-
},
|
|
128
|
-
preloadScripts: preloadScripts$1,
|
|
129
|
-
styles: styles$1
|
|
130
|
-
};
|
|
131
|
-
const plugin$2 = definePlugin({
|
|
132
|
-
name: name$3,
|
|
133
|
-
config: config$1,
|
|
134
|
-
transform(transformHooks) {
|
|
135
|
-
var _a;
|
|
136
|
-
let enableFeature = markmapCommon.noop;
|
|
137
|
-
transformHooks.parser.tap((md) => {
|
|
138
|
-
md.set({
|
|
139
|
-
highlight: (str, language) => {
|
|
140
|
-
enableFeature();
|
|
141
|
-
return hljs.highlightAuto(str, language ? [language] : void 0).value;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
146
|
-
enableFeature = () => {
|
|
147
|
-
context.features[name$3] = true;
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
return {
|
|
151
|
-
styles: (_a = plugin$2.config) == null ? void 0 : _a.styles
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
const name$2 = "katex";
|
|
156
|
-
const preloadScripts = [
|
|
157
|
-
`katex@${"0.16.8"}/dist/katex.min.js`
|
|
158
|
-
].map((path) => markmapCommon.buildJSItem(path));
|
|
159
|
-
const webfontloader = markmapCommon.buildJSItem(
|
|
160
|
-
`webfontloader@${"1.6.28"}/webfontloader.js`
|
|
161
|
-
);
|
|
162
|
-
webfontloader.data.defer = true;
|
|
163
|
-
const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
|
|
164
|
-
(path) => markmapCommon.buildCSSItem(path)
|
|
165
|
-
);
|
|
166
|
-
const config = {
|
|
167
|
-
versions: {
|
|
168
|
-
katex: "0.16.8",
|
|
169
|
-
webfontloader: "1.6.28"
|
|
170
|
-
},
|
|
171
|
-
preloadScripts,
|
|
172
|
-
scripts: [
|
|
173
|
-
{
|
|
174
|
-
type: "iife",
|
|
175
|
-
data: {
|
|
176
|
-
fn: (getMarkmap) => {
|
|
177
|
-
window.WebFontConfig = {
|
|
178
|
-
custom: {
|
|
179
|
-
families: [
|
|
180
|
-
"KaTeX_AMS",
|
|
181
|
-
"KaTeX_Caligraphic:n4,n7",
|
|
182
|
-
"KaTeX_Fraktur:n4,n7",
|
|
183
|
-
"KaTeX_Main:n4,n7,i4,i7",
|
|
184
|
-
"KaTeX_Math:i4,i7",
|
|
185
|
-
"KaTeX_Script",
|
|
186
|
-
"KaTeX_SansSerif:n4,n7,i4",
|
|
187
|
-
"KaTeX_Size1",
|
|
188
|
-
"KaTeX_Size2",
|
|
189
|
-
"KaTeX_Size3",
|
|
190
|
-
"KaTeX_Size4",
|
|
191
|
-
"KaTeX_Typewriter"
|
|
192
|
-
]
|
|
193
|
-
},
|
|
194
|
-
active: () => {
|
|
195
|
-
getMarkmap().refreshHook.call();
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
},
|
|
199
|
-
getParams({ getMarkmap }) {
|
|
200
|
-
return [getMarkmap];
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
webfontloader
|
|
205
|
-
],
|
|
206
|
-
styles
|
|
207
|
-
};
|
|
208
|
-
const plugin$1 = definePlugin({
|
|
209
|
-
name: name$2,
|
|
210
|
-
config,
|
|
211
|
-
transform(transformHooks) {
|
|
212
|
-
var _a, _b;
|
|
213
|
-
let enableFeature = markmapCommon.noop;
|
|
214
|
-
transformHooks.parser.tap((md) => {
|
|
215
|
-
md.use(remarkableKatex);
|
|
216
|
-
md.renderer.rules.katex = markmapCommon.wrapFunction(
|
|
217
|
-
md.renderer.rules.katex,
|
|
218
|
-
(render, ...args) => {
|
|
219
|
-
enableFeature();
|
|
220
|
-
return render(...args);
|
|
221
|
-
}
|
|
222
|
-
);
|
|
223
|
-
});
|
|
224
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
225
|
-
enableFeature = () => {
|
|
226
|
-
context.features[name$2] = true;
|
|
227
|
-
};
|
|
228
|
-
});
|
|
229
|
-
return {
|
|
230
|
-
styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
|
|
231
|
-
scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
const name$1 = "npmUrl";
|
|
236
|
-
const npmUrl = definePlugin({
|
|
237
|
-
name: name$1,
|
|
238
|
-
transform(transformHooks) {
|
|
239
|
-
transformHooks.afterParse.tap((_, context) => {
|
|
240
|
-
const { frontmatter: frontmatter2 } = context;
|
|
241
|
-
const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
|
|
242
|
-
if (markmap) {
|
|
243
|
-
["extraJs", "extraCss"].forEach((key) => {
|
|
244
|
-
const value = markmap[key];
|
|
245
|
-
if (value) {
|
|
246
|
-
markmap[key] = value.map((path) => {
|
|
247
|
-
if (path.startsWith("npm:")) {
|
|
248
|
-
return transformHooks.transformer.urlBuilder.getFullUrl(
|
|
249
|
-
path.slice(4)
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
return path;
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
return {};
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
const name = "sourceLines";
|
|
262
|
-
const plugin = definePlugin({
|
|
263
|
-
name,
|
|
264
|
-
transform(transformHooks) {
|
|
265
|
-
transformHooks.parser.tap((md) => {
|
|
266
|
-
Object.entries(md.renderer.rules).forEach(([key, value]) => {
|
|
267
|
-
if (typeof value === "function") {
|
|
268
|
-
md.renderer.rules[key] = patchRule(value);
|
|
269
|
-
} else {
|
|
270
|
-
Object.entries(value).forEach(([k, v]) => {
|
|
271
|
-
value[k] = patchRule(v);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
return {};
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
function patchRule(rule) {
|
|
280
|
-
return markmapCommon.wrapFunction(rule, (render, tokens, idx, ...rest) => {
|
|
281
|
-
let html = render(tokens, idx, ...rest);
|
|
282
|
-
const { lines } = tokens[idx];
|
|
283
|
-
if (lines) {
|
|
284
|
-
html = html.replace(
|
|
285
|
-
/^<[\w-]+/,
|
|
286
|
-
(m) => `${m} data-lines="${lines.join(",")}"`
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
return html;
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
const plugins = [
|
|
293
|
-
frontmatter,
|
|
294
|
-
plugin$1,
|
|
295
|
-
plugin$2,
|
|
296
|
-
npmUrl,
|
|
297
|
-
plugin$3,
|
|
298
|
-
plugin
|
|
299
|
-
];
|
|
6
|
+
const plugins = require("./plugins.js");
|
|
7
|
+
require("js-yaml");
|
|
8
|
+
require("highlight.js");
|
|
9
|
+
require("remarkable-katex");
|
|
300
10
|
function patchJSItem(urlBuilder, item) {
|
|
301
11
|
if (item.type === "script" && item.data.src) {
|
|
302
12
|
return {
|
|
@@ -321,6 +31,7 @@ function patchCSSItem(urlBuilder, item) {
|
|
|
321
31
|
}
|
|
322
32
|
return item;
|
|
323
33
|
}
|
|
34
|
+
const builtInPlugins = plugins.plugins;
|
|
324
35
|
function cleanNode(node) {
|
|
325
36
|
while (!node.content && node.children.length === 1) {
|
|
326
37
|
node = node.children[0];
|
|
@@ -337,16 +48,16 @@ function cleanNode(node) {
|
|
|
337
48
|
};
|
|
338
49
|
}
|
|
339
50
|
class Transformer {
|
|
340
|
-
constructor(plugins$1 =
|
|
51
|
+
constructor(plugins$1 = builtInPlugins) {
|
|
341
52
|
this.assetsMap = {};
|
|
342
53
|
this.urlBuilder = new markmapCommon.UrlBuilder();
|
|
343
|
-
this.hooks = createTransformHooks(this);
|
|
54
|
+
this.hooks = plugins.createTransformHooks(this);
|
|
344
55
|
this.plugins = plugins$1.map(
|
|
345
|
-
(
|
|
56
|
+
(plugin) => typeof plugin === "function" ? plugin() : plugin
|
|
346
57
|
);
|
|
347
58
|
const assetsMap = {};
|
|
348
|
-
for (const { name
|
|
349
|
-
assetsMap[
|
|
59
|
+
for (const { name, transform } of this.plugins) {
|
|
60
|
+
assetsMap[name] = transform(this.hooks);
|
|
350
61
|
}
|
|
351
62
|
this.assetsMap = assetsMap;
|
|
352
63
|
const md = new remarkable.Remarkable("full", {
|
|
@@ -387,19 +98,19 @@ class Transformer {
|
|
|
387
98
|
* Get all assets from enabled plugins or filter them by plugin names as keys.
|
|
388
99
|
*/
|
|
389
100
|
getAssets(keys) {
|
|
390
|
-
const
|
|
101
|
+
const styles = [];
|
|
391
102
|
const scripts = [];
|
|
392
|
-
keys ?? (keys = this.plugins.map((
|
|
103
|
+
keys ?? (keys = this.plugins.map((plugin) => plugin.name));
|
|
393
104
|
for (const assets of keys.map((key) => this.assetsMap[key])) {
|
|
394
105
|
if (assets) {
|
|
395
106
|
if (assets.styles)
|
|
396
|
-
|
|
107
|
+
styles.push(...assets.styles);
|
|
397
108
|
if (assets.scripts)
|
|
398
109
|
scripts.push(...assets.scripts);
|
|
399
110
|
}
|
|
400
111
|
}
|
|
401
112
|
return {
|
|
402
|
-
styles:
|
|
113
|
+
styles: styles.map((item) => patchCSSItem(this.urlBuilder, item)),
|
|
403
114
|
scripts: scripts.map((item) => patchJSItem(this.urlBuilder, item))
|
|
404
115
|
};
|
|
405
116
|
}
|
|
@@ -407,59 +118,13 @@ class Transformer {
|
|
|
407
118
|
* Get used assets by features object returned by `transform`.
|
|
408
119
|
*/
|
|
409
120
|
getUsedAssets(features) {
|
|
410
|
-
const keys = this.plugins.map((
|
|
121
|
+
const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
|
|
411
122
|
return this.getAssets(keys);
|
|
412
123
|
}
|
|
413
|
-
fillTemplate(root, assets, extra) {
|
|
414
|
-
extra = {
|
|
415
|
-
...extra
|
|
416
|
-
};
|
|
417
|
-
extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => markmapCommon.buildJSItem(path)));
|
|
418
|
-
const { scripts, styles: styles2 } = assets;
|
|
419
|
-
const cssList = [...styles2 ? markmapCommon.persistCSS(styles2) : []];
|
|
420
|
-
const context = {
|
|
421
|
-
getMarkmap: () => window.markmap,
|
|
422
|
-
getOptions: extra.getOptions,
|
|
423
|
-
jsonOptions: extra.jsonOptions,
|
|
424
|
-
root
|
|
425
|
-
};
|
|
426
|
-
const jsList = [
|
|
427
|
-
...markmapCommon.persistJS(
|
|
428
|
-
[
|
|
429
|
-
...extra.baseJs,
|
|
430
|
-
...scripts || [],
|
|
431
|
-
{
|
|
432
|
-
type: "iife",
|
|
433
|
-
data: {
|
|
434
|
-
fn: (getMarkmap, getOptions, root2, jsonOptions) => {
|
|
435
|
-
const markmap = getMarkmap();
|
|
436
|
-
window.mm = markmap.Markmap.create(
|
|
437
|
-
"svg#mindmap",
|
|
438
|
-
(getOptions || markmap.deriveOptions)(jsonOptions),
|
|
439
|
-
root2
|
|
440
|
-
);
|
|
441
|
-
},
|
|
442
|
-
getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
|
|
443
|
-
return [getMarkmap, getOptions, root2, jsonOptions];
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
],
|
|
448
|
-
context
|
|
449
|
-
)
|
|
450
|
-
];
|
|
451
|
-
const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
|
|
452
|
-
return html;
|
|
453
|
-
}
|
|
454
124
|
}
|
|
455
125
|
const transformerVersions = {
|
|
456
|
-
"markmap-lib": "
|
|
457
|
-
d3: "7.8.5"
|
|
126
|
+
"markmap-lib": "0.16.1"
|
|
458
127
|
};
|
|
459
128
|
exports.Transformer = Transformer;
|
|
460
|
-
exports.
|
|
461
|
-
exports.builtInPlugins = plugins;
|
|
462
|
-
exports.svg_marked = svg_marked;
|
|
463
|
-
exports.svg_unmarked = svg_unmarked;
|
|
464
|
-
exports.template = template;
|
|
129
|
+
exports.builtInPlugins = builtInPlugins;
|
|
465
130
|
exports.transformerVersions = transformerVersions;
|