markmap-lib 0.15.5-alpha.1 → 0.15.6-alpha.4
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/README.md +2 -2
- package/dist/browser/index.iife.js +7607 -0
- package/dist/browser/index.mjs +274 -245
- package/dist/index.js +249 -226
- package/dist/index.mjs +254 -225
- package/dist/plugins/util.d.ts +4 -0
- package/dist/util.d.ts +3 -0
- package/package.json +11 -13
- package/dist/browser/index.js +0 -11337
- package/types/plugins/util.d.ts +0 -8
- /package/{types → dist}/constants.d.ts +0 -0
- /package/{types → dist}/index.d.ts +0 -0
- /package/{types → dist}/plugins/base.d.ts +0 -0
- /package/{types → dist}/plugins/frontmatter.d.ts +0 -0
- /package/{types → dist}/plugins/hljs.browser.d.ts +0 -0
- /package/{types → dist}/plugins/hljs.config.d.ts +0 -0
- /package/{types → dist}/plugins/hljs.d.ts +0 -0
- /package/{types → dist}/plugins/index.d.ts +0 -0
- /package/{types → dist}/plugins/katex.browser.d.ts +0 -0
- /package/{types → dist}/plugins/katex.config.d.ts +0 -0
- /package/{types → dist}/plugins/katex.d.ts +0 -0
- /package/{types → dist}/plugins/npm-url.d.ts +0 -0
- /package/{types → dist}/plugins/prism.browser.d.ts +0 -0
- /package/{types → dist}/plugins/prism.config.d.ts +0 -0
- /package/{types → dist}/plugins/prism.d.ts +0 -0
- /package/{types → dist}/transform.d.ts +0 -0
- /package/{types → dist}/types.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,50 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const remarkable = require("remarkable");
|
|
4
|
+
const markmapCommon = require("markmap-common");
|
|
5
|
+
const remarkableKatex = require("remarkable-katex");
|
|
6
|
+
const yaml = require("js-yaml");
|
|
7
|
+
const hljs = require("highlight.js");
|
|
8
|
+
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
|
+
const baseJsPaths = [
|
|
10
|
+
`d3@${"7.8.5"}/dist/d3.min.js`,
|
|
11
|
+
`markmap-view@${"0.15.6-alpha.4"}/dist/browser/index.js`
|
|
12
|
+
];
|
|
13
|
+
const name$3 = "katex";
|
|
14
|
+
const preloadScripts$1 = [
|
|
15
|
+
`katex@${"0.16.8"}/dist/katex.min.js`
|
|
16
|
+
].map((path) => markmapCommon.buildJSItem(path));
|
|
17
|
+
const webfontloader = markmapCommon.buildJSItem(
|
|
18
|
+
`webfontloader@${"1.6.28"}/webfontloader.js`
|
|
19
|
+
);
|
|
17
20
|
webfontloader.data.defer = true;
|
|
18
|
-
const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
|
|
21
|
+
const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
|
|
22
|
+
(path) => markmapCommon.buildCSSItem(path)
|
|
23
|
+
);
|
|
19
24
|
const config$1 = {
|
|
20
25
|
versions: {
|
|
21
|
-
katex: "0.16.8"
|
|
22
|
-
webfontloader: "1.6.28"
|
|
26
|
+
katex: "0.16.8",
|
|
27
|
+
webfontloader: "1.6.28"
|
|
23
28
|
},
|
|
24
29
|
preloadScripts: preloadScripts$1,
|
|
25
|
-
scripts: [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
scripts: [
|
|
31
|
+
{
|
|
32
|
+
type: "iife",
|
|
33
|
+
data: {
|
|
34
|
+
fn: (getMarkmap) => {
|
|
35
|
+
window.WebFontConfig = {
|
|
36
|
+
custom: {
|
|
37
|
+
families: [
|
|
38
|
+
"KaTeX_AMS",
|
|
39
|
+
"KaTeX_Caligraphic:n4,n7",
|
|
40
|
+
"KaTeX_Fraktur:n4,n7",
|
|
41
|
+
"KaTeX_Main:n4,n7,i4,i7",
|
|
42
|
+
"KaTeX_Math:i4,i7",
|
|
43
|
+
"KaTeX_Script",
|
|
44
|
+
"KaTeX_SansSerif:n4,n7,i4",
|
|
45
|
+
"KaTeX_Size1",
|
|
46
|
+
"KaTeX_Size2",
|
|
47
|
+
"KaTeX_Size3",
|
|
48
|
+
"KaTeX_Size4",
|
|
49
|
+
"KaTeX_Typewriter"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
active: () => {
|
|
53
|
+
getMarkmap().refreshHook.call();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
getParams({ getMarkmap }) {
|
|
58
|
+
return [getMarkmap];
|
|
59
|
+
}
|
|
42
60
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
61
|
+
},
|
|
62
|
+
webfontloader
|
|
63
|
+
],
|
|
45
64
|
styles: styles$1
|
|
46
65
|
};
|
|
47
|
-
|
|
48
66
|
function createTransformHooks(transformer) {
|
|
49
67
|
return {
|
|
50
68
|
transformer,
|
|
@@ -55,26 +73,24 @@ function createTransformHooks(transformer) {
|
|
|
55
73
|
retransform: new markmapCommon.Hook()
|
|
56
74
|
};
|
|
57
75
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* This function is only used to help type checking.
|
|
61
|
-
*/
|
|
62
|
-
function definePlugin(plugin) {
|
|
63
|
-
return plugin;
|
|
76
|
+
function definePlugin(plugin2) {
|
|
77
|
+
return plugin2;
|
|
64
78
|
}
|
|
65
|
-
|
|
66
79
|
const plugin$1 = definePlugin({
|
|
67
80
|
name: name$3,
|
|
68
81
|
config: config$1,
|
|
69
82
|
transform(transformHooks) {
|
|
70
|
-
var
|
|
83
|
+
var _a, _b;
|
|
71
84
|
let enableFeature = markmapCommon.noop;
|
|
72
|
-
transformHooks.parser.tap(md => {
|
|
85
|
+
transformHooks.parser.tap((md) => {
|
|
73
86
|
md.use(remarkableKatex);
|
|
74
|
-
md.renderer.rules.katex = markmapCommon.wrapFunction(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
md.renderer.rules.katex = markmapCommon.wrapFunction(
|
|
88
|
+
md.renderer.rules.katex,
|
|
89
|
+
(render, ...args) => {
|
|
90
|
+
enableFeature();
|
|
91
|
+
return render(...args);
|
|
92
|
+
}
|
|
93
|
+
);
|
|
78
94
|
});
|
|
79
95
|
transformHooks.beforeParse.tap((_, context) => {
|
|
80
96
|
enableFeature = () => {
|
|
@@ -82,78 +98,83 @@ const plugin$1 = definePlugin({
|
|
|
82
98
|
};
|
|
83
99
|
});
|
|
84
100
|
return {
|
|
85
|
-
styles: (
|
|
86
|
-
scripts: (
|
|
101
|
+
styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
|
|
102
|
+
scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
|
|
87
103
|
};
|
|
88
104
|
}
|
|
89
105
|
});
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
var frontmatter = definePlugin({
|
|
106
|
+
const name$2 = "frontmatter";
|
|
107
|
+
const frontmatter = definePlugin({
|
|
93
108
|
name: name$2,
|
|
94
109
|
transform(transformHooks) {
|
|
95
110
|
transformHooks.beforeParse.tap((md, context) => {
|
|
96
|
-
const {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
const { content } = context;
|
|
112
|
+
if (!content.startsWith("---\n"))
|
|
113
|
+
return;
|
|
114
|
+
const endOffset = content.indexOf("\n---\n");
|
|
115
|
+
if (endOffset < 0)
|
|
116
|
+
return;
|
|
102
117
|
const raw = content.slice(4, endOffset);
|
|
103
|
-
let
|
|
118
|
+
let frontmatter2;
|
|
104
119
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
frontmatter2 = yaml.load(raw);
|
|
121
|
+
if (frontmatter2 == null ? void 0 : frontmatter2.markmap) {
|
|
122
|
+
frontmatter2.markmap = normalizeMarkmapJsonOptions(
|
|
123
|
+
frontmatter2.markmap
|
|
124
|
+
);
|
|
109
125
|
}
|
|
110
|
-
} catch
|
|
126
|
+
} catch {
|
|
111
127
|
return;
|
|
112
128
|
}
|
|
113
|
-
context.frontmatter =
|
|
129
|
+
context.frontmatter = frontmatter2;
|
|
114
130
|
context.content = content.slice(endOffset + 5);
|
|
115
|
-
context.contentLineOffset = content.slice(0, endOffset).split(
|
|
131
|
+
context.contentLineOffset = content.slice(0, endOffset).split("\n").length + 1;
|
|
116
132
|
});
|
|
117
133
|
return {};
|
|
118
134
|
}
|
|
119
135
|
});
|
|
120
136
|
function normalizeMarkmapJsonOptions(options) {
|
|
121
|
-
if (!options)
|
|
122
|
-
|
|
123
|
-
|
|
137
|
+
if (!options)
|
|
138
|
+
return;
|
|
139
|
+
["color", "extraJs", "extraCss"].forEach((key) => {
|
|
140
|
+
if (options[key] != null)
|
|
141
|
+
options[key] = normalizeStringArray(options[key]);
|
|
124
142
|
});
|
|
125
|
-
[
|
|
126
|
-
if (options[key] != null)
|
|
143
|
+
["duration", "maxWidth", "initialExpandLevel"].forEach((key) => {
|
|
144
|
+
if (options[key] != null)
|
|
145
|
+
options[key] = normalizeNumber(options[key]);
|
|
127
146
|
});
|
|
128
147
|
return options;
|
|
129
148
|
}
|
|
130
149
|
function normalizeStringArray(value) {
|
|
131
|
-
var _result;
|
|
132
150
|
let result;
|
|
133
|
-
if (typeof value ===
|
|
134
|
-
|
|
151
|
+
if (typeof value === "string")
|
|
152
|
+
result = [value];
|
|
153
|
+
else if (Array.isArray(value))
|
|
154
|
+
result = value.filter((item) => item && typeof item === "string");
|
|
155
|
+
return (result == null ? void 0 : result.length) ? result : void 0;
|
|
135
156
|
}
|
|
136
157
|
function normalizeNumber(value) {
|
|
137
|
-
if (isNaN(+value))
|
|
158
|
+
if (isNaN(+value))
|
|
159
|
+
return;
|
|
138
160
|
return +value;
|
|
139
161
|
}
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
var npmUrl = definePlugin({
|
|
162
|
+
const name$1 = "npmUrl";
|
|
163
|
+
const npmUrl = definePlugin({
|
|
143
164
|
name: name$1,
|
|
144
165
|
transform(transformHooks) {
|
|
145
166
|
transformHooks.afterParse.tap((_, context) => {
|
|
146
|
-
const {
|
|
147
|
-
|
|
148
|
-
} = context;
|
|
149
|
-
const markmap = frontmatter == null ? void 0 : frontmatter.markmap;
|
|
167
|
+
const { frontmatter: frontmatter2 } = context;
|
|
168
|
+
const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
|
|
150
169
|
if (markmap) {
|
|
151
|
-
[
|
|
170
|
+
["extraJs", "extraCss"].forEach((key) => {
|
|
152
171
|
const value = markmap[key];
|
|
153
172
|
if (value) {
|
|
154
|
-
markmap[key] = value.map(path => {
|
|
155
|
-
if (path.startsWith(
|
|
156
|
-
return transformHooks.transformer.urlBuilder.getFullUrl(
|
|
173
|
+
markmap[key] = value.map((path) => {
|
|
174
|
+
if (path.startsWith("npm:")) {
|
|
175
|
+
return transformHooks.transformer.urlBuilder.getFullUrl(
|
|
176
|
+
path.slice(4)
|
|
177
|
+
);
|
|
157
178
|
}
|
|
158
179
|
return path;
|
|
159
180
|
});
|
|
@@ -164,31 +185,32 @@ var npmUrl = definePlugin({
|
|
|
164
185
|
return {};
|
|
165
186
|
}
|
|
166
187
|
});
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
188
|
+
const name = "hljs";
|
|
189
|
+
const preloadScripts = [
|
|
190
|
+
`@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
|
|
191
|
+
].map((path) => markmapCommon.buildJSItem(path));
|
|
192
|
+
const styles = [
|
|
193
|
+
`@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
|
|
194
|
+
// `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
|
|
195
|
+
].map((path) => markmapCommon.buildCSSItem(path));
|
|
173
196
|
const config = {
|
|
174
197
|
versions: {
|
|
175
|
-
hljs: "11.8.0"
|
|
198
|
+
hljs: "11.8.0"
|
|
176
199
|
},
|
|
177
200
|
preloadScripts,
|
|
178
201
|
styles
|
|
179
202
|
};
|
|
180
|
-
|
|
181
203
|
const plugin = definePlugin({
|
|
182
204
|
name,
|
|
183
205
|
config,
|
|
184
206
|
transform(transformHooks) {
|
|
185
|
-
var
|
|
207
|
+
var _a;
|
|
186
208
|
let enableFeature = markmapCommon.noop;
|
|
187
|
-
transformHooks.parser.tap(md => {
|
|
209
|
+
transformHooks.parser.tap((md) => {
|
|
188
210
|
md.set({
|
|
189
211
|
highlight: (str, language) => {
|
|
190
212
|
enableFeature();
|
|
191
|
-
return hljs.highlightAuto(str, language ? [language] :
|
|
213
|
+
return hljs.highlightAuto(str, language ? [language] : void 0).value;
|
|
192
214
|
}
|
|
193
215
|
});
|
|
194
216
|
});
|
|
@@ -198,68 +220,70 @@ const plugin = definePlugin({
|
|
|
198
220
|
};
|
|
199
221
|
});
|
|
200
222
|
return {
|
|
201
|
-
styles: (
|
|
223
|
+
styles: (_a = plugin.config) == null ? void 0 : _a.styles
|
|
202
224
|
};
|
|
203
225
|
}
|
|
204
226
|
});
|
|
205
|
-
|
|
206
227
|
const plugins = [frontmatter, plugin$1, plugin, npmUrl];
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
data:
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
228
|
+
function patchJSItem(urlBuilder, item) {
|
|
229
|
+
if (item.type === "script" && item.data.src) {
|
|
230
|
+
return {
|
|
231
|
+
...item,
|
|
232
|
+
data: {
|
|
233
|
+
...item.data,
|
|
234
|
+
src: urlBuilder.getFullUrl(item.data.src)
|
|
235
|
+
}
|
|
236
|
+
};
|
|
215
237
|
}
|
|
216
238
|
return item;
|
|
217
239
|
}
|
|
218
|
-
function patchCSSItem(
|
|
219
|
-
if (item.type ===
|
|
220
|
-
return
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
240
|
+
function patchCSSItem(urlBuilder, item) {
|
|
241
|
+
if (item.type === "stylesheet" && item.data.href) {
|
|
242
|
+
return {
|
|
243
|
+
...item,
|
|
244
|
+
data: {
|
|
245
|
+
...item.data,
|
|
246
|
+
href: urlBuilder.getFullUrl(item.data.href)
|
|
247
|
+
}
|
|
248
|
+
};
|
|
225
249
|
}
|
|
226
250
|
return item;
|
|
227
251
|
}
|
|
228
|
-
|
|
229
252
|
function cleanNode(node) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
node.children = node.children.filter(item => item.type !==
|
|
233
|
-
} else if (node.type ===
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
node.children = node.children.filter(item => {
|
|
237
|
-
if (['paragraph', 'fence'].includes(item.type)) {
|
|
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)) {
|
|
238
259
|
if (!node.content) {
|
|
239
260
|
node.content = item.content;
|
|
240
|
-
node.payload =
|
|
261
|
+
node.payload = {
|
|
262
|
+
...node.payload,
|
|
263
|
+
...item.payload
|
|
264
|
+
};
|
|
241
265
|
}
|
|
242
266
|
return false;
|
|
243
267
|
}
|
|
244
268
|
return true;
|
|
245
269
|
});
|
|
246
|
-
if (((
|
|
270
|
+
if (((_a = node.payload) == null ? void 0 : _a.index) != null) {
|
|
247
271
|
node.content = `${node.payload.index}. ${node.content}`;
|
|
248
272
|
}
|
|
249
|
-
} else if (node.type ===
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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,
|
|
255
279
|
index
|
|
256
|
-
}
|
|
280
|
+
};
|
|
257
281
|
index += 1;
|
|
258
282
|
}
|
|
259
283
|
});
|
|
260
284
|
}
|
|
261
285
|
if (node.children.length > 0) {
|
|
262
|
-
node.children.forEach(child => cleanNode(child));
|
|
286
|
+
node.children.forEach((child) => cleanNode(child));
|
|
263
287
|
if (node.children.length === 1 && !node.children[0].content) {
|
|
264
288
|
node.children = node.children[0].children;
|
|
265
289
|
}
|
|
@@ -267,7 +291,7 @@ function cleanNode(node) {
|
|
|
267
291
|
}
|
|
268
292
|
function resetDepth(node, depth = 0) {
|
|
269
293
|
node.depth = depth;
|
|
270
|
-
node.children.forEach(child => {
|
|
294
|
+
node.children.forEach((child) => {
|
|
271
295
|
resetDepth(child, depth + 1);
|
|
272
296
|
});
|
|
273
297
|
}
|
|
@@ -276,39 +300,36 @@ class Transformer {
|
|
|
276
300
|
this.assetsMap = {};
|
|
277
301
|
this.urlBuilder = new markmapCommon.UrlBuilder();
|
|
278
302
|
this.hooks = createTransformHooks(this);
|
|
279
|
-
this.plugins = plugins$1.map(
|
|
303
|
+
this.plugins = plugins$1.map(
|
|
304
|
+
(plugin2) => typeof plugin2 === "function" ? plugin2() : plugin2
|
|
305
|
+
);
|
|
280
306
|
const assetsMap = {};
|
|
281
|
-
for (const {
|
|
282
|
-
|
|
283
|
-
transform
|
|
284
|
-
} of this.plugins) {
|
|
285
|
-
assetsMap[name] = transform(this.hooks);
|
|
307
|
+
for (const { name: name2, transform } of this.plugins) {
|
|
308
|
+
assetsMap[name2] = transform(this.hooks);
|
|
286
309
|
}
|
|
287
310
|
this.assetsMap = assetsMap;
|
|
288
|
-
const md = new remarkable.Remarkable(
|
|
311
|
+
const md = new remarkable.Remarkable("full", {
|
|
289
312
|
html: true,
|
|
290
313
|
breaks: true,
|
|
291
314
|
maxNesting: Infinity
|
|
292
315
|
});
|
|
293
|
-
md.renderer.rules.htmltag = markmapCommon.wrapFunction(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
args
|
|
297
|
-
result
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
316
|
+
md.renderer.rules.htmltag = markmapCommon.wrapFunction(
|
|
317
|
+
md.renderer.rules.htmltag,
|
|
318
|
+
(render, ...args) => {
|
|
319
|
+
const result = render(...args);
|
|
320
|
+
this.hooks.htmltag.call({ args, result });
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
);
|
|
301
324
|
this.md = md;
|
|
302
325
|
this.hooks.parser.call(md);
|
|
303
326
|
}
|
|
304
327
|
buildTree(tokens) {
|
|
305
|
-
const {
|
|
306
|
-
md
|
|
307
|
-
} = this;
|
|
328
|
+
const { md } = this;
|
|
308
329
|
const root = {
|
|
309
|
-
type:
|
|
330
|
+
type: "root",
|
|
310
331
|
depth: 0,
|
|
311
|
-
content:
|
|
332
|
+
content: "",
|
|
312
333
|
children: [],
|
|
313
334
|
payload: {}
|
|
314
335
|
};
|
|
@@ -320,19 +341,17 @@ class Transformer {
|
|
|
320
341
|
payload.lines = token.lines;
|
|
321
342
|
}
|
|
322
343
|
let current = stack[stack.length - 1];
|
|
323
|
-
if (token.type.endsWith(
|
|
344
|
+
if (token.type.endsWith("_open")) {
|
|
324
345
|
const type = token.type.slice(0, -5);
|
|
325
|
-
if (type ===
|
|
346
|
+
if (type === "heading") {
|
|
326
347
|
depth = token.hLevel;
|
|
327
|
-
while ((
|
|
328
|
-
var _current;
|
|
348
|
+
while ((current == null ? void 0 : current.depth) >= depth) {
|
|
329
349
|
stack.pop();
|
|
330
350
|
current = stack[stack.length - 1];
|
|
331
351
|
}
|
|
332
352
|
} else {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (type === 'ordered_list') {
|
|
353
|
+
depth = Math.max(depth, (current == null ? void 0 : current.depth) || 0) + 1;
|
|
354
|
+
if (type === "ordered_list") {
|
|
336
355
|
payload.startIndex = token.order;
|
|
337
356
|
}
|
|
338
357
|
}
|
|
@@ -340,7 +359,7 @@ class Transformer {
|
|
|
340
359
|
type,
|
|
341
360
|
depth,
|
|
342
361
|
payload,
|
|
343
|
-
content:
|
|
362
|
+
content: "",
|
|
344
363
|
children: []
|
|
345
364
|
};
|
|
346
365
|
current.children.push(item);
|
|
@@ -348,28 +367,29 @@ class Transformer {
|
|
|
348
367
|
} else if (!current) {
|
|
349
368
|
continue;
|
|
350
369
|
} else if (token.type === `${current.type}_close`) {
|
|
351
|
-
if (current.type ===
|
|
370
|
+
if (current.type === "heading") {
|
|
352
371
|
depth = current.depth;
|
|
353
372
|
} else {
|
|
354
373
|
stack.pop();
|
|
355
374
|
depth = 0;
|
|
356
375
|
}
|
|
357
|
-
} else if (token.type ===
|
|
358
|
-
const revoke = this.hooks.htmltag.tap(ctx => {
|
|
359
|
-
var
|
|
360
|
-
const comment = (
|
|
361
|
-
const data = comment == null ? void 0 : comment[1].trim().split(
|
|
362
|
-
if ((data == null ? void 0 : data[0]) ===
|
|
363
|
-
current.payload =
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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 = "";
|
|
367
387
|
}
|
|
368
388
|
});
|
|
369
389
|
const text = md.renderer.render([token], md.options, {});
|
|
370
390
|
revoke();
|
|
371
|
-
current.content = `${current.content ||
|
|
372
|
-
} else if (token.type ===
|
|
391
|
+
current.content = `${current.content || ""}${text}`;
|
|
392
|
+
} else if (token.type === "fence") {
|
|
373
393
|
const result = md.renderer.render([token], md.options, {});
|
|
374
394
|
current.children.push({
|
|
375
395
|
type: token.type,
|
|
@@ -378,12 +398,13 @@ class Transformer {
|
|
|
378
398
|
children: [],
|
|
379
399
|
payload
|
|
380
400
|
});
|
|
381
|
-
} else
|
|
401
|
+
} else
|
|
402
|
+
;
|
|
382
403
|
}
|
|
383
404
|
return root;
|
|
384
405
|
}
|
|
385
406
|
transform(content) {
|
|
386
|
-
var
|
|
407
|
+
var _a;
|
|
387
408
|
const context = {
|
|
388
409
|
content,
|
|
389
410
|
features: {},
|
|
@@ -394,82 +415,84 @@ class Transformer {
|
|
|
394
415
|
this.hooks.afterParse.call(this.md, context);
|
|
395
416
|
let root = this.buildTree(tokens);
|
|
396
417
|
cleanNode(root);
|
|
397
|
-
if (((
|
|
418
|
+
if (((_a = root.children) == null ? void 0 : _a.length) === 1)
|
|
419
|
+
root = root.children[0];
|
|
398
420
|
resetDepth(root);
|
|
399
|
-
return
|
|
400
|
-
root
|
|
401
|
-
});
|
|
421
|
+
return { ...context, root };
|
|
402
422
|
}
|
|
403
|
-
|
|
404
423
|
/**
|
|
405
424
|
* Get all assets from enabled plugins or filter them by plugin names as keys.
|
|
406
425
|
*/
|
|
407
426
|
getAssets(keys) {
|
|
408
|
-
|
|
409
|
-
const styles = [];
|
|
427
|
+
const styles2 = [];
|
|
410
428
|
const scripts = [];
|
|
411
|
-
|
|
412
|
-
for (const assets of keys.map(key => this.assetsMap[key])) {
|
|
429
|
+
keys ?? (keys = this.plugins.map((plugin2) => plugin2.name));
|
|
430
|
+
for (const assets of keys.map((key) => this.assetsMap[key])) {
|
|
413
431
|
if (assets) {
|
|
414
|
-
if (assets.styles)
|
|
415
|
-
|
|
432
|
+
if (assets.styles)
|
|
433
|
+
styles2.push(...assets.styles);
|
|
434
|
+
if (assets.scripts)
|
|
435
|
+
scripts.push(...assets.scripts);
|
|
416
436
|
}
|
|
417
437
|
}
|
|
418
438
|
return {
|
|
419
|
-
styles:
|
|
420
|
-
scripts: scripts.map(item => patchJSItem(this, item))
|
|
439
|
+
styles: styles2.map((item) => patchCSSItem(this.urlBuilder, item)),
|
|
440
|
+
scripts: scripts.map((item) => patchJSItem(this.urlBuilder, item))
|
|
421
441
|
};
|
|
422
442
|
}
|
|
423
|
-
|
|
424
443
|
/**
|
|
425
444
|
* Get used assets by features object returned by `transform`.
|
|
426
445
|
*/
|
|
427
446
|
getUsedAssets(features) {
|
|
428
|
-
const keys = this.plugins.map(
|
|
447
|
+
const keys = this.plugins.map((plugin2) => plugin2.name).filter((name2) => features[name2]);
|
|
429
448
|
return this.getAssets(keys);
|
|
430
449
|
}
|
|
431
450
|
fillTemplate(root, assets, extra) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
} = assets;
|
|
439
|
-
const cssList = [...(styles ? markmapCommon.persistCSS(styles) : [])];
|
|
451
|
+
extra = {
|
|
452
|
+
...extra
|
|
453
|
+
};
|
|
454
|
+
extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => markmapCommon.buildJSItem(path)));
|
|
455
|
+
const { scripts, styles: styles2 } = assets;
|
|
456
|
+
const cssList = [...styles2 ? markmapCommon.persistCSS(styles2) : []];
|
|
440
457
|
const context = {
|
|
441
458
|
getMarkmap: () => window.markmap,
|
|
442
459
|
getOptions: extra.getOptions,
|
|
443
460
|
jsonOptions: extra.jsonOptions,
|
|
444
461
|
root
|
|
445
462
|
};
|
|
446
|
-
const jsList = [
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
463
|
+
const jsList = [
|
|
464
|
+
...markmapCommon.persistJS(
|
|
465
|
+
[
|
|
466
|
+
...extra.baseJs,
|
|
467
|
+
...scripts || [],
|
|
468
|
+
{
|
|
469
|
+
type: "iife",
|
|
470
|
+
data: {
|
|
471
|
+
fn: (getMarkmap, getOptions, root2, jsonOptions) => {
|
|
472
|
+
const markmap = getMarkmap();
|
|
473
|
+
window.mm = markmap.Markmap.create(
|
|
474
|
+
"svg#mindmap",
|
|
475
|
+
(getOptions || markmap.deriveOptions)(jsonOptions),
|
|
476
|
+
root2
|
|
477
|
+
);
|
|
478
|
+
},
|
|
479
|
+
getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
|
|
480
|
+
return [getMarkmap, getOptions, root2, jsonOptions];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
],
|
|
485
|
+
context
|
|
486
|
+
)
|
|
487
|
+
];
|
|
488
|
+
const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
|
|
464
489
|
return html;
|
|
465
490
|
}
|
|
466
491
|
}
|
|
467
|
-
|
|
468
492
|
const transformerVersions = {
|
|
469
|
-
|
|
493
|
+
"markmap-lib": "process.env.VERSION",
|
|
470
494
|
d3: "7.8.5"
|
|
471
495
|
};
|
|
472
|
-
|
|
473
496
|
exports.Transformer = Transformer;
|
|
474
497
|
exports.baseJsPaths = baseJsPaths;
|
|
475
498
|
exports.builtInPlugins = plugins;
|