markmap-lib 0.15.9-alpha.0 → 0.15.9-alpha.11
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 +582 -435
- package/dist/browser/index.mjs +232 -156
- package/dist/index.js +19 -232
- package/dist/index.mjs +20 -233
- package/dist/index.no-plugins.js +185 -0
- package/dist/index.no-plugins.mjs +185 -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/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 +299 -0
- package/dist/plugins.mjs +299 -0
- package/dist/transform.d.ts +1 -2
- package/package.json +18 -6
- 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/{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/index.js
CHANGED
|
@@ -3,229 +3,15 @@ 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
|
-
|
|
6
|
+
const plugins = require("./plugins.js");
|
|
7
|
+
require("js-yaml");
|
|
8
|
+
require("highlight.js");
|
|
9
|
+
require("remarkable-katex");
|
|
9
10
|
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';
|
|
10
11
|
const baseJsPaths = [
|
|
11
12
|
`d3@${"7.8.5"}/dist/d3.min.js`,
|
|
12
|
-
`markmap-view@${"0.15.
|
|
13
|
+
`markmap-view@${"0.15.8"}/dist/browser/index.js`
|
|
13
14
|
];
|
|
14
|
-
const name$3 = "katex";
|
|
15
|
-
const preloadScripts$1 = [
|
|
16
|
-
`katex@${"0.16.8"}/dist/katex.min.js`
|
|
17
|
-
].map((path) => markmapCommon.buildJSItem(path));
|
|
18
|
-
const webfontloader = markmapCommon.buildJSItem(
|
|
19
|
-
`webfontloader@${"1.6.28"}/webfontloader.js`
|
|
20
|
-
);
|
|
21
|
-
webfontloader.data.defer = true;
|
|
22
|
-
const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
|
|
23
|
-
(path) => markmapCommon.buildCSSItem(path)
|
|
24
|
-
);
|
|
25
|
-
const config$1 = {
|
|
26
|
-
versions: {
|
|
27
|
-
katex: "0.16.8",
|
|
28
|
-
webfontloader: "1.6.28"
|
|
29
|
-
},
|
|
30
|
-
preloadScripts: preloadScripts$1,
|
|
31
|
-
scripts: [
|
|
32
|
-
{
|
|
33
|
-
type: "iife",
|
|
34
|
-
data: {
|
|
35
|
-
fn: (getMarkmap) => {
|
|
36
|
-
window.WebFontConfig = {
|
|
37
|
-
custom: {
|
|
38
|
-
families: [
|
|
39
|
-
"KaTeX_AMS",
|
|
40
|
-
"KaTeX_Caligraphic:n4,n7",
|
|
41
|
-
"KaTeX_Fraktur:n4,n7",
|
|
42
|
-
"KaTeX_Main:n4,n7,i4,i7",
|
|
43
|
-
"KaTeX_Math:i4,i7",
|
|
44
|
-
"KaTeX_Script",
|
|
45
|
-
"KaTeX_SansSerif:n4,n7,i4",
|
|
46
|
-
"KaTeX_Size1",
|
|
47
|
-
"KaTeX_Size2",
|
|
48
|
-
"KaTeX_Size3",
|
|
49
|
-
"KaTeX_Size4",
|
|
50
|
-
"KaTeX_Typewriter"
|
|
51
|
-
]
|
|
52
|
-
},
|
|
53
|
-
active: () => {
|
|
54
|
-
getMarkmap().refreshHook.call();
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
getParams({ getMarkmap }) {
|
|
59
|
-
return [getMarkmap];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
webfontloader
|
|
64
|
-
],
|
|
65
|
-
styles: styles$1
|
|
66
|
-
};
|
|
67
|
-
function createTransformHooks(transformer) {
|
|
68
|
-
return {
|
|
69
|
-
transformer,
|
|
70
|
-
parser: new markmapCommon.Hook(),
|
|
71
|
-
beforeParse: new markmapCommon.Hook(),
|
|
72
|
-
afterParse: new markmapCommon.Hook(),
|
|
73
|
-
htmltag: new markmapCommon.Hook(),
|
|
74
|
-
retransform: new markmapCommon.Hook()
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function definePlugin(plugin2) {
|
|
78
|
-
return plugin2;
|
|
79
|
-
}
|
|
80
|
-
const plugin$1 = definePlugin({
|
|
81
|
-
name: name$3,
|
|
82
|
-
config: config$1,
|
|
83
|
-
transform(transformHooks) {
|
|
84
|
-
var _a, _b;
|
|
85
|
-
let enableFeature = markmapCommon.noop;
|
|
86
|
-
transformHooks.parser.tap((md) => {
|
|
87
|
-
md.use(remarkableKatex);
|
|
88
|
-
md.renderer.rules.katex = markmapCommon.wrapFunction(
|
|
89
|
-
md.renderer.rules.katex,
|
|
90
|
-
(render, ...args) => {
|
|
91
|
-
enableFeature();
|
|
92
|
-
return render(...args);
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
97
|
-
enableFeature = () => {
|
|
98
|
-
context.features[name$3] = true;
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
return {
|
|
102
|
-
styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
|
|
103
|
-
scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
const name$2 = "frontmatter";
|
|
108
|
-
const frontmatter = definePlugin({
|
|
109
|
-
name: name$2,
|
|
110
|
-
transform(transformHooks) {
|
|
111
|
-
transformHooks.beforeParse.tap((md, context) => {
|
|
112
|
-
const { content } = context;
|
|
113
|
-
if (!/^---\r?\n/.test(content))
|
|
114
|
-
return;
|
|
115
|
-
const match = /\n---\r?\n/.exec(content);
|
|
116
|
-
if (!match)
|
|
117
|
-
return;
|
|
118
|
-
const raw = content.slice(4, match.index);
|
|
119
|
-
let frontmatter2;
|
|
120
|
-
try {
|
|
121
|
-
frontmatter2 = yaml.load(raw);
|
|
122
|
-
if (frontmatter2 == null ? void 0 : frontmatter2.markmap) {
|
|
123
|
-
frontmatter2.markmap = normalizeMarkmapJsonOptions(
|
|
124
|
-
frontmatter2.markmap
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
} catch {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
context.frontmatter = frontmatter2;
|
|
131
|
-
context.content = content.slice(match.index + match[0].length);
|
|
132
|
-
context.contentLineOffset = content.slice(0, match.index).split("\n").length + 1;
|
|
133
|
-
});
|
|
134
|
-
return {};
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
function normalizeMarkmapJsonOptions(options) {
|
|
138
|
-
if (!options)
|
|
139
|
-
return;
|
|
140
|
-
["color", "extraJs", "extraCss"].forEach((key) => {
|
|
141
|
-
if (options[key] != null)
|
|
142
|
-
options[key] = normalizeStringArray(options[key]);
|
|
143
|
-
});
|
|
144
|
-
["duration", "maxWidth", "initialExpandLevel"].forEach((key) => {
|
|
145
|
-
if (options[key] != null)
|
|
146
|
-
options[key] = normalizeNumber(options[key]);
|
|
147
|
-
});
|
|
148
|
-
return options;
|
|
149
|
-
}
|
|
150
|
-
function normalizeStringArray(value) {
|
|
151
|
-
let result;
|
|
152
|
-
if (typeof value === "string")
|
|
153
|
-
result = [value];
|
|
154
|
-
else if (Array.isArray(value))
|
|
155
|
-
result = value.filter((item) => item && typeof item === "string");
|
|
156
|
-
return (result == null ? void 0 : result.length) ? result : void 0;
|
|
157
|
-
}
|
|
158
|
-
function normalizeNumber(value) {
|
|
159
|
-
if (isNaN(+value))
|
|
160
|
-
return;
|
|
161
|
-
return +value;
|
|
162
|
-
}
|
|
163
|
-
const name$1 = "npmUrl";
|
|
164
|
-
const npmUrl = definePlugin({
|
|
165
|
-
name: name$1,
|
|
166
|
-
transform(transformHooks) {
|
|
167
|
-
transformHooks.afterParse.tap((_, context) => {
|
|
168
|
-
const { frontmatter: frontmatter2 } = context;
|
|
169
|
-
const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
|
|
170
|
-
if (markmap) {
|
|
171
|
-
["extraJs", "extraCss"].forEach((key) => {
|
|
172
|
-
const value = markmap[key];
|
|
173
|
-
if (value) {
|
|
174
|
-
markmap[key] = value.map((path) => {
|
|
175
|
-
if (path.startsWith("npm:")) {
|
|
176
|
-
return transformHooks.transformer.urlBuilder.getFullUrl(
|
|
177
|
-
path.slice(4)
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
return path;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
return {};
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
const name = "hljs";
|
|
190
|
-
const preloadScripts = [
|
|
191
|
-
`@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
|
|
192
|
-
].map((path) => markmapCommon.buildJSItem(path));
|
|
193
|
-
const styles = [
|
|
194
|
-
`@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
|
|
195
|
-
// `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
|
|
196
|
-
].map((path) => markmapCommon.buildCSSItem(path));
|
|
197
|
-
const config = {
|
|
198
|
-
versions: {
|
|
199
|
-
hljs: "11.8.0"
|
|
200
|
-
},
|
|
201
|
-
preloadScripts,
|
|
202
|
-
styles
|
|
203
|
-
};
|
|
204
|
-
const plugin = definePlugin({
|
|
205
|
-
name,
|
|
206
|
-
config,
|
|
207
|
-
transform(transformHooks) {
|
|
208
|
-
var _a;
|
|
209
|
-
let enableFeature = markmapCommon.noop;
|
|
210
|
-
transformHooks.parser.tap((md) => {
|
|
211
|
-
md.set({
|
|
212
|
-
highlight: (str, language) => {
|
|
213
|
-
enableFeature();
|
|
214
|
-
return hljs.highlightAuto(str, language ? [language] : void 0).value;
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
219
|
-
enableFeature = () => {
|
|
220
|
-
context.features[name] = true;
|
|
221
|
-
};
|
|
222
|
-
});
|
|
223
|
-
return {
|
|
224
|
-
styles: (_a = plugin.config) == null ? void 0 : _a.styles
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
const plugins = [frontmatter, plugin$1, plugin, npmUrl];
|
|
229
15
|
function patchJSItem(urlBuilder, item) {
|
|
230
16
|
if (item.type === "script" && item.data.src) {
|
|
231
17
|
return {
|
|
@@ -250,6 +36,7 @@ function patchCSSItem(urlBuilder, item) {
|
|
|
250
36
|
}
|
|
251
37
|
return item;
|
|
252
38
|
}
|
|
39
|
+
const builtInPlugins = plugins.plugins;
|
|
253
40
|
function cleanNode(node) {
|
|
254
41
|
while (!node.content && node.children.length === 1) {
|
|
255
42
|
node = node.children[0];
|
|
@@ -266,16 +53,16 @@ function cleanNode(node) {
|
|
|
266
53
|
};
|
|
267
54
|
}
|
|
268
55
|
class Transformer {
|
|
269
|
-
constructor(plugins$1 =
|
|
56
|
+
constructor(plugins$1 = builtInPlugins) {
|
|
270
57
|
this.assetsMap = {};
|
|
271
58
|
this.urlBuilder = new markmapCommon.UrlBuilder();
|
|
272
|
-
this.hooks = createTransformHooks(this);
|
|
59
|
+
this.hooks = plugins.createTransformHooks(this);
|
|
273
60
|
this.plugins = plugins$1.map(
|
|
274
|
-
(
|
|
61
|
+
(plugin) => typeof plugin === "function" ? plugin() : plugin
|
|
275
62
|
);
|
|
276
63
|
const assetsMap = {};
|
|
277
|
-
for (const { name
|
|
278
|
-
assetsMap[
|
|
64
|
+
for (const { name, transform } of this.plugins) {
|
|
65
|
+
assetsMap[name] = transform(this.hooks);
|
|
279
66
|
}
|
|
280
67
|
this.assetsMap = assetsMap;
|
|
281
68
|
const md = new remarkable.Remarkable("full", {
|
|
@@ -316,19 +103,19 @@ class Transformer {
|
|
|
316
103
|
* Get all assets from enabled plugins or filter them by plugin names as keys.
|
|
317
104
|
*/
|
|
318
105
|
getAssets(keys) {
|
|
319
|
-
const
|
|
106
|
+
const styles = [];
|
|
320
107
|
const scripts = [];
|
|
321
|
-
keys ?? (keys = this.plugins.map((
|
|
108
|
+
keys ?? (keys = this.plugins.map((plugin) => plugin.name));
|
|
322
109
|
for (const assets of keys.map((key) => this.assetsMap[key])) {
|
|
323
110
|
if (assets) {
|
|
324
111
|
if (assets.styles)
|
|
325
|
-
|
|
112
|
+
styles.push(...assets.styles);
|
|
326
113
|
if (assets.scripts)
|
|
327
114
|
scripts.push(...assets.scripts);
|
|
328
115
|
}
|
|
329
116
|
}
|
|
330
117
|
return {
|
|
331
|
-
styles:
|
|
118
|
+
styles: styles.map((item) => patchCSSItem(this.urlBuilder, item)),
|
|
332
119
|
scripts: scripts.map((item) => patchJSItem(this.urlBuilder, item))
|
|
333
120
|
};
|
|
334
121
|
}
|
|
@@ -336,7 +123,7 @@ class Transformer {
|
|
|
336
123
|
* Get used assets by features object returned by `transform`.
|
|
337
124
|
*/
|
|
338
125
|
getUsedAssets(features) {
|
|
339
|
-
const keys = this.plugins.map((
|
|
126
|
+
const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
|
|
340
127
|
return this.getAssets(keys);
|
|
341
128
|
}
|
|
342
129
|
fillTemplate(root, assets, extra) {
|
|
@@ -344,8 +131,8 @@ class Transformer {
|
|
|
344
131
|
...extra
|
|
345
132
|
};
|
|
346
133
|
extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => markmapCommon.buildJSItem(path)));
|
|
347
|
-
const { scripts, styles
|
|
348
|
-
const cssList = [...
|
|
134
|
+
const { scripts, styles } = assets;
|
|
135
|
+
const cssList = [...styles ? markmapCommon.persistCSS(styles) : []];
|
|
349
136
|
const context = {
|
|
350
137
|
getMarkmap: () => window.markmap,
|
|
351
138
|
getOptions: extra.getOptions,
|
|
@@ -387,6 +174,6 @@ const transformerVersions = {
|
|
|
387
174
|
};
|
|
388
175
|
exports.Transformer = Transformer;
|
|
389
176
|
exports.baseJsPaths = baseJsPaths;
|
|
390
|
-
exports.builtInPlugins =
|
|
177
|
+
exports.builtInPlugins = builtInPlugins;
|
|
391
178
|
exports.template = template;
|
|
392
179
|
exports.transformerVersions = transformerVersions;
|
package/dist/index.mjs
CHANGED
|
@@ -1,229 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UrlBuilder, wrapFunction, buildJSItem, persistCSS, persistJS } from "markmap-common";
|
|
2
2
|
import { buildTree } from "markmap-html-parser";
|
|
3
3
|
import { Remarkable } from "remarkable";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
4
|
+
import { plugins, createTransformHooks } from "./plugins.mjs";
|
|
5
|
+
import "js-yaml";
|
|
6
|
+
import "highlight.js";
|
|
7
|
+
import "remarkable-katex";
|
|
7
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';
|
|
8
9
|
const baseJsPaths = [
|
|
9
10
|
`d3@${"7.8.5"}/dist/d3.min.js`,
|
|
10
|
-
`markmap-view@${"0.15.
|
|
11
|
+
`markmap-view@${"0.15.8"}/dist/browser/index.js`
|
|
11
12
|
];
|
|
12
|
-
const name$3 = "katex";
|
|
13
|
-
const preloadScripts$1 = [
|
|
14
|
-
`katex@${"0.16.8"}/dist/katex.min.js`
|
|
15
|
-
].map((path) => buildJSItem(path));
|
|
16
|
-
const webfontloader = buildJSItem(
|
|
17
|
-
`webfontloader@${"1.6.28"}/webfontloader.js`
|
|
18
|
-
);
|
|
19
|
-
webfontloader.data.defer = true;
|
|
20
|
-
const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
|
|
21
|
-
(path) => buildCSSItem(path)
|
|
22
|
-
);
|
|
23
|
-
const config$1 = {
|
|
24
|
-
versions: {
|
|
25
|
-
katex: "0.16.8",
|
|
26
|
-
webfontloader: "1.6.28"
|
|
27
|
-
},
|
|
28
|
-
preloadScripts: preloadScripts$1,
|
|
29
|
-
scripts: [
|
|
30
|
-
{
|
|
31
|
-
type: "iife",
|
|
32
|
-
data: {
|
|
33
|
-
fn: (getMarkmap) => {
|
|
34
|
-
window.WebFontConfig = {
|
|
35
|
-
custom: {
|
|
36
|
-
families: [
|
|
37
|
-
"KaTeX_AMS",
|
|
38
|
-
"KaTeX_Caligraphic:n4,n7",
|
|
39
|
-
"KaTeX_Fraktur:n4,n7",
|
|
40
|
-
"KaTeX_Main:n4,n7,i4,i7",
|
|
41
|
-
"KaTeX_Math:i4,i7",
|
|
42
|
-
"KaTeX_Script",
|
|
43
|
-
"KaTeX_SansSerif:n4,n7,i4",
|
|
44
|
-
"KaTeX_Size1",
|
|
45
|
-
"KaTeX_Size2",
|
|
46
|
-
"KaTeX_Size3",
|
|
47
|
-
"KaTeX_Size4",
|
|
48
|
-
"KaTeX_Typewriter"
|
|
49
|
-
]
|
|
50
|
-
},
|
|
51
|
-
active: () => {
|
|
52
|
-
getMarkmap().refreshHook.call();
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
getParams({ getMarkmap }) {
|
|
57
|
-
return [getMarkmap];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
webfontloader
|
|
62
|
-
],
|
|
63
|
-
styles: styles$1
|
|
64
|
-
};
|
|
65
|
-
function createTransformHooks(transformer) {
|
|
66
|
-
return {
|
|
67
|
-
transformer,
|
|
68
|
-
parser: new Hook(),
|
|
69
|
-
beforeParse: new Hook(),
|
|
70
|
-
afterParse: new Hook(),
|
|
71
|
-
htmltag: new Hook(),
|
|
72
|
-
retransform: new Hook()
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function definePlugin(plugin2) {
|
|
76
|
-
return plugin2;
|
|
77
|
-
}
|
|
78
|
-
const plugin$1 = definePlugin({
|
|
79
|
-
name: name$3,
|
|
80
|
-
config: config$1,
|
|
81
|
-
transform(transformHooks) {
|
|
82
|
-
var _a, _b;
|
|
83
|
-
let enableFeature = noop;
|
|
84
|
-
transformHooks.parser.tap((md) => {
|
|
85
|
-
md.use(remarkableKatex);
|
|
86
|
-
md.renderer.rules.katex = wrapFunction(
|
|
87
|
-
md.renderer.rules.katex,
|
|
88
|
-
(render, ...args) => {
|
|
89
|
-
enableFeature();
|
|
90
|
-
return render(...args);
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
95
|
-
enableFeature = () => {
|
|
96
|
-
context.features[name$3] = true;
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
|
|
101
|
-
scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
const name$2 = "frontmatter";
|
|
106
|
-
const frontmatter = definePlugin({
|
|
107
|
-
name: name$2,
|
|
108
|
-
transform(transformHooks) {
|
|
109
|
-
transformHooks.beforeParse.tap((md, context) => {
|
|
110
|
-
const { content } = context;
|
|
111
|
-
if (!/^---\r?\n/.test(content))
|
|
112
|
-
return;
|
|
113
|
-
const match = /\n---\r?\n/.exec(content);
|
|
114
|
-
if (!match)
|
|
115
|
-
return;
|
|
116
|
-
const raw = content.slice(4, match.index);
|
|
117
|
-
let frontmatter2;
|
|
118
|
-
try {
|
|
119
|
-
frontmatter2 = yaml.load(raw);
|
|
120
|
-
if (frontmatter2 == null ? void 0 : frontmatter2.markmap) {
|
|
121
|
-
frontmatter2.markmap = normalizeMarkmapJsonOptions(
|
|
122
|
-
frontmatter2.markmap
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
} catch {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
context.frontmatter = frontmatter2;
|
|
129
|
-
context.content = content.slice(match.index + match[0].length);
|
|
130
|
-
context.contentLineOffset = content.slice(0, match.index).split("\n").length + 1;
|
|
131
|
-
});
|
|
132
|
-
return {};
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
function normalizeMarkmapJsonOptions(options) {
|
|
136
|
-
if (!options)
|
|
137
|
-
return;
|
|
138
|
-
["color", "extraJs", "extraCss"].forEach((key) => {
|
|
139
|
-
if (options[key] != null)
|
|
140
|
-
options[key] = normalizeStringArray(options[key]);
|
|
141
|
-
});
|
|
142
|
-
["duration", "maxWidth", "initialExpandLevel"].forEach((key) => {
|
|
143
|
-
if (options[key] != null)
|
|
144
|
-
options[key] = normalizeNumber(options[key]);
|
|
145
|
-
});
|
|
146
|
-
return options;
|
|
147
|
-
}
|
|
148
|
-
function normalizeStringArray(value) {
|
|
149
|
-
let result;
|
|
150
|
-
if (typeof value === "string")
|
|
151
|
-
result = [value];
|
|
152
|
-
else if (Array.isArray(value))
|
|
153
|
-
result = value.filter((item) => item && typeof item === "string");
|
|
154
|
-
return (result == null ? void 0 : result.length) ? result : void 0;
|
|
155
|
-
}
|
|
156
|
-
function normalizeNumber(value) {
|
|
157
|
-
if (isNaN(+value))
|
|
158
|
-
return;
|
|
159
|
-
return +value;
|
|
160
|
-
}
|
|
161
|
-
const name$1 = "npmUrl";
|
|
162
|
-
const npmUrl = definePlugin({
|
|
163
|
-
name: name$1,
|
|
164
|
-
transform(transformHooks) {
|
|
165
|
-
transformHooks.afterParse.tap((_, context) => {
|
|
166
|
-
const { frontmatter: frontmatter2 } = context;
|
|
167
|
-
const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
|
|
168
|
-
if (markmap) {
|
|
169
|
-
["extraJs", "extraCss"].forEach((key) => {
|
|
170
|
-
const value = markmap[key];
|
|
171
|
-
if (value) {
|
|
172
|
-
markmap[key] = value.map((path) => {
|
|
173
|
-
if (path.startsWith("npm:")) {
|
|
174
|
-
return transformHooks.transformer.urlBuilder.getFullUrl(
|
|
175
|
-
path.slice(4)
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
return path;
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
return {};
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
const name = "hljs";
|
|
188
|
-
const preloadScripts = [
|
|
189
|
-
`@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
|
|
190
|
-
].map((path) => buildJSItem(path));
|
|
191
|
-
const styles = [
|
|
192
|
-
`@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
|
|
193
|
-
// `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
|
|
194
|
-
].map((path) => buildCSSItem(path));
|
|
195
|
-
const config = {
|
|
196
|
-
versions: {
|
|
197
|
-
hljs: "11.8.0"
|
|
198
|
-
},
|
|
199
|
-
preloadScripts,
|
|
200
|
-
styles
|
|
201
|
-
};
|
|
202
|
-
const plugin = definePlugin({
|
|
203
|
-
name,
|
|
204
|
-
config,
|
|
205
|
-
transform(transformHooks) {
|
|
206
|
-
var _a;
|
|
207
|
-
let enableFeature = noop;
|
|
208
|
-
transformHooks.parser.tap((md) => {
|
|
209
|
-
md.set({
|
|
210
|
-
highlight: (str, language) => {
|
|
211
|
-
enableFeature();
|
|
212
|
-
return hljs.highlightAuto(str, language ? [language] : void 0).value;
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
217
|
-
enableFeature = () => {
|
|
218
|
-
context.features[name] = true;
|
|
219
|
-
};
|
|
220
|
-
});
|
|
221
|
-
return {
|
|
222
|
-
styles: (_a = plugin.config) == null ? void 0 : _a.styles
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
const plugins = [frontmatter, plugin$1, plugin, npmUrl];
|
|
227
13
|
function patchJSItem(urlBuilder, item) {
|
|
228
14
|
if (item.type === "script" && item.data.src) {
|
|
229
15
|
return {
|
|
@@ -248,6 +34,7 @@ function patchCSSItem(urlBuilder, item) {
|
|
|
248
34
|
}
|
|
249
35
|
return item;
|
|
250
36
|
}
|
|
37
|
+
const builtInPlugins = plugins;
|
|
251
38
|
function cleanNode(node) {
|
|
252
39
|
while (!node.content && node.children.length === 1) {
|
|
253
40
|
node = node.children[0];
|
|
@@ -264,16 +51,16 @@ function cleanNode(node) {
|
|
|
264
51
|
};
|
|
265
52
|
}
|
|
266
53
|
class Transformer {
|
|
267
|
-
constructor(
|
|
54
|
+
constructor(plugins2 = builtInPlugins) {
|
|
268
55
|
this.assetsMap = {};
|
|
269
56
|
this.urlBuilder = new UrlBuilder();
|
|
270
57
|
this.hooks = createTransformHooks(this);
|
|
271
|
-
this.plugins =
|
|
272
|
-
(
|
|
58
|
+
this.plugins = plugins2.map(
|
|
59
|
+
(plugin) => typeof plugin === "function" ? plugin() : plugin
|
|
273
60
|
);
|
|
274
61
|
const assetsMap = {};
|
|
275
|
-
for (const { name
|
|
276
|
-
assetsMap[
|
|
62
|
+
for (const { name, transform } of this.plugins) {
|
|
63
|
+
assetsMap[name] = transform(this.hooks);
|
|
277
64
|
}
|
|
278
65
|
this.assetsMap = assetsMap;
|
|
279
66
|
const md = new Remarkable("full", {
|
|
@@ -314,19 +101,19 @@ class Transformer {
|
|
|
314
101
|
* Get all assets from enabled plugins or filter them by plugin names as keys.
|
|
315
102
|
*/
|
|
316
103
|
getAssets(keys) {
|
|
317
|
-
const
|
|
104
|
+
const styles = [];
|
|
318
105
|
const scripts = [];
|
|
319
|
-
keys ?? (keys = this.plugins.map((
|
|
106
|
+
keys ?? (keys = this.plugins.map((plugin) => plugin.name));
|
|
320
107
|
for (const assets of keys.map((key) => this.assetsMap[key])) {
|
|
321
108
|
if (assets) {
|
|
322
109
|
if (assets.styles)
|
|
323
|
-
|
|
110
|
+
styles.push(...assets.styles);
|
|
324
111
|
if (assets.scripts)
|
|
325
112
|
scripts.push(...assets.scripts);
|
|
326
113
|
}
|
|
327
114
|
}
|
|
328
115
|
return {
|
|
329
|
-
styles:
|
|
116
|
+
styles: styles.map((item) => patchCSSItem(this.urlBuilder, item)),
|
|
330
117
|
scripts: scripts.map((item) => patchJSItem(this.urlBuilder, item))
|
|
331
118
|
};
|
|
332
119
|
}
|
|
@@ -334,7 +121,7 @@ class Transformer {
|
|
|
334
121
|
* Get used assets by features object returned by `transform`.
|
|
335
122
|
*/
|
|
336
123
|
getUsedAssets(features) {
|
|
337
|
-
const keys = this.plugins.map((
|
|
124
|
+
const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
|
|
338
125
|
return this.getAssets(keys);
|
|
339
126
|
}
|
|
340
127
|
fillTemplate(root, assets, extra) {
|
|
@@ -342,8 +129,8 @@ class Transformer {
|
|
|
342
129
|
...extra
|
|
343
130
|
};
|
|
344
131
|
extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => buildJSItem(path)));
|
|
345
|
-
const { scripts, styles
|
|
346
|
-
const cssList = [...
|
|
132
|
+
const { scripts, styles } = assets;
|
|
133
|
+
const cssList = [...styles ? persistCSS(styles) : []];
|
|
347
134
|
const context = {
|
|
348
135
|
getMarkmap: () => window.markmap,
|
|
349
136
|
getOptions: extra.getOptions,
|
|
@@ -386,7 +173,7 @@ const transformerVersions = {
|
|
|
386
173
|
export {
|
|
387
174
|
Transformer,
|
|
388
175
|
baseJsPaths,
|
|
389
|
-
|
|
176
|
+
builtInPlugins,
|
|
390
177
|
template,
|
|
391
178
|
transformerVersions
|
|
392
179
|
};
|