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