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