markmap-lib 0.14.5-alpha.19 → 0.14.5-alpha.22
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.js +206 -587
- package/dist/browser/index.mjs +225 -10987
- package/dist/index.js +158 -158
- package/dist/index.mjs +158 -158
- package/package.json +5 -4
- package/types/constants.d.ts +2 -0
- package/types/index.d.ts +1 -1
- package/types/plugins/base.d.ts +3 -3
- package/types/plugins/frontmatter.d.ts +1 -1
- package/types/plugins/hljs.d.ts +2 -0
- package/types/plugins/index.d.ts +1 -1
- package/types/plugins/katex.browser.d.ts +2 -2
- package/types/plugins/katex.config.d.ts +2 -1
- package/types/plugins/katex.d.ts +2 -2
- package/types/plugins/npm-url.d.ts +1 -1
- package/types/plugins/prism.browser.d.ts +2 -2
- package/types/plugins/prism.config.d.ts +2 -1
- package/types/plugins/prism.d.ts +2 -2
- package/types/plugins/util.d.ts +4 -0
- package/types/transform.d.ts +9 -3
- package/types/types.d.ts +5 -1
- package/types/template.d.ts +0 -8
package/dist/index.js
CHANGED
|
@@ -1,89 +1,53 @@
|
|
|
1
|
-
/*! markmap-lib v0.14.5-alpha.
|
|
1
|
+
/*! markmap-lib v0.14.5-alpha.22+04afb38 | MIT License */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
5
|
-
var markmapCommon = require('markmap-common');
|
|
6
5
|
var remarkable = require('remarkable');
|
|
6
|
+
var markmapCommon = require('markmap-common');
|
|
7
7
|
var remarkableKatex = require('remarkable-katex');
|
|
8
|
-
var Prism = require('prismjs');
|
|
9
|
-
var loadLanguages = require('prismjs/components/index.js');
|
|
10
8
|
var yaml = require('js-yaml');
|
|
9
|
+
var hljs = require('highlight.js');
|
|
11
10
|
|
|
12
11
|
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" ;
|
|
13
|
-
const baseJsPaths = [`d3@${"7.8.5"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
root
|
|
28
|
-
};
|
|
29
|
-
const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), {
|
|
12
|
+
const baseJsPaths = [`d3@${"7.8.5"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.22"}/dist/browser/index.js`];
|
|
13
|
+
|
|
14
|
+
const name$3 = 'katex';
|
|
15
|
+
const preloadScripts = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => markmapCommon.buildJSItem(path));
|
|
16
|
+
const webfontloader = markmapCommon.buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
|
|
17
|
+
webfontloader.data.defer = true;
|
|
18
|
+
const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => markmapCommon.buildCSSItem(path));
|
|
19
|
+
const config$1 = {
|
|
20
|
+
versions: {
|
|
21
|
+
katex: "0.16.8" ,
|
|
22
|
+
webfontloader: "1.6.28"
|
|
23
|
+
},
|
|
24
|
+
preloadScripts,
|
|
25
|
+
scripts: [{
|
|
30
26
|
type: 'iife',
|
|
31
27
|
data: {
|
|
32
|
-
fn:
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
fn: getMarkmap => {
|
|
29
|
+
window.WebFontConfig = {
|
|
30
|
+
custom: {
|
|
31
|
+
families: ['KaTeX_AMS', 'KaTeX_Caligraphic:n4,n7', 'KaTeX_Fraktur:n4,n7', 'KaTeX_Main:n4,n7,i4,i7', 'KaTeX_Math:i4,i7', 'KaTeX_Script', 'KaTeX_SansSerif:n4,n7,i4', 'KaTeX_Size1', 'KaTeX_Size2', 'KaTeX_Size3', 'KaTeX_Size4', 'KaTeX_Typewriter']
|
|
32
|
+
},
|
|
33
|
+
active: () => {
|
|
34
|
+
getMarkmap().refreshHook.call();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
35
37
|
},
|
|
36
|
-
getParams
|
|
37
|
-
getMarkmap
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
jsonOptions
|
|
41
|
-
}) => {
|
|
42
|
-
return [getMarkmap, getOptions, root, jsonOptions];
|
|
38
|
+
getParams({
|
|
39
|
+
getMarkmap
|
|
40
|
+
}) {
|
|
41
|
+
return [getMarkmap];
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getConfig$1() {
|
|
51
|
-
const preloadScripts = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => markmapCommon.buildJSItem(path));
|
|
52
|
-
const webfontloader = markmapCommon.buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
|
|
53
|
-
webfontloader.data.defer = true;
|
|
54
|
-
const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => markmapCommon.buildCSSItem(path));
|
|
55
|
-
return {
|
|
56
|
-
versions: {
|
|
57
|
-
katex: "0.16.8" ,
|
|
58
|
-
webfontloader: "1.6.28"
|
|
59
|
-
},
|
|
60
|
-
preloadScripts,
|
|
61
|
-
scripts: [{
|
|
62
|
-
type: 'iife',
|
|
63
|
-
data: {
|
|
64
|
-
fn: getMarkmap => {
|
|
65
|
-
window.WebFontConfig = {
|
|
66
|
-
custom: {
|
|
67
|
-
families: ['KaTeX_AMS', 'KaTeX_Caligraphic:n4,n7', 'KaTeX_Fraktur:n4,n7', 'KaTeX_Main:n4,n7,i4,i7', 'KaTeX_Math:i4,i7', 'KaTeX_Script', 'KaTeX_SansSerif:n4,n7,i4', 'KaTeX_Size1', 'KaTeX_Size2', 'KaTeX_Size3', 'KaTeX_Size4', 'KaTeX_Typewriter']
|
|
68
|
-
},
|
|
69
|
-
active: () => {
|
|
70
|
-
getMarkmap().refreshHook.call();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
getParams({
|
|
75
|
-
getMarkmap
|
|
76
|
-
}) {
|
|
77
|
-
return [getMarkmap];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}, webfontloader],
|
|
81
|
-
styles
|
|
82
|
-
};
|
|
83
|
-
}
|
|
44
|
+
}, webfontloader],
|
|
45
|
+
styles: styles$1
|
|
46
|
+
};
|
|
84
47
|
|
|
85
|
-
function createTransformHooks() {
|
|
48
|
+
function createTransformHooks(transformer) {
|
|
86
49
|
return {
|
|
50
|
+
transformer,
|
|
87
51
|
parser: new markmapCommon.Hook(),
|
|
88
52
|
beforeParse: new markmapCommon.Hook(),
|
|
89
53
|
afterParse: new markmapCommon.Hook(),
|
|
@@ -99,85 +63,34 @@ function definePlugin(plugin) {
|
|
|
99
63
|
return plugin;
|
|
100
64
|
}
|
|
101
65
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
config
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return render(...args);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
117
|
-
enableFeature = () => {
|
|
118
|
-
context.features[name$3] = true;
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
return {
|
|
122
|
-
styles: plugin.config.styles,
|
|
123
|
-
scripts: plugin.config.scripts
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
return plugin;
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
function getConfig() {
|
|
131
|
-
const preloadScripts = [`prismjs@${"1.29.0"}/components/prism-core.min.js`, `prismjs@${"1.29.0"}/plugins/autoloader/prism-autoloader.min.js`].map(path => markmapCommon.buildJSItem(path));
|
|
132
|
-
const styles = [`prismjs@${"1.29.0"}/themes/prism.css`].map(path => markmapCommon.buildCSSItem(path));
|
|
133
|
-
return {
|
|
134
|
-
versions: {
|
|
135
|
-
prismjs: "1.29.0"
|
|
136
|
-
},
|
|
137
|
-
preloadScripts,
|
|
138
|
-
styles
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const name$2 = 'prism';
|
|
143
|
-
var prism = definePlugin(() => {
|
|
144
|
-
const plugin = {
|
|
145
|
-
name: name$2,
|
|
146
|
-
config: getConfig(),
|
|
147
|
-
transform(transformHooks) {
|
|
148
|
-
let enableFeature = markmapCommon.noop;
|
|
149
|
-
transformHooks.parser.tap(md => {
|
|
150
|
-
md.set({
|
|
151
|
-
highlight: (str, lang) => {
|
|
152
|
-
enableFeature();
|
|
153
|
-
let grammar = Prism.languages[lang];
|
|
154
|
-
if (!grammar && lang) {
|
|
155
|
-
loadLanguages([lang]);
|
|
156
|
-
grammar = Prism.languages[lang];
|
|
157
|
-
}
|
|
158
|
-
if (grammar) {
|
|
159
|
-
return Prism.highlight(str, grammar, lang);
|
|
160
|
-
}
|
|
161
|
-
return '';
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
166
|
-
enableFeature = () => {
|
|
167
|
-
context.features[name$2] = true;
|
|
168
|
-
};
|
|
66
|
+
const plugin$1 = definePlugin({
|
|
67
|
+
name: name$3,
|
|
68
|
+
config: config$1,
|
|
69
|
+
transform(transformHooks) {
|
|
70
|
+
var _plugin$config, _plugin$config2;
|
|
71
|
+
let enableFeature = markmapCommon.noop;
|
|
72
|
+
transformHooks.parser.tap(md => {
|
|
73
|
+
md.use(remarkableKatex);
|
|
74
|
+
md.renderer.rules.katex = markmapCommon.wrapFunction(md.renderer.rules.katex, (render, ...args) => {
|
|
75
|
+
enableFeature();
|
|
76
|
+
return render(...args);
|
|
169
77
|
});
|
|
170
|
-
|
|
171
|
-
|
|
78
|
+
});
|
|
79
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
80
|
+
enableFeature = () => {
|
|
81
|
+
context.features[name$3] = true;
|
|
172
82
|
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
styles: (_plugin$config = plugin$1.config) == null ? void 0 : _plugin$config.styles,
|
|
86
|
+
scripts: (_plugin$config2 = plugin$1.config) == null ? void 0 : _plugin$config2.scripts
|
|
87
|
+
};
|
|
88
|
+
}
|
|
176
89
|
});
|
|
177
90
|
|
|
178
|
-
const name$
|
|
91
|
+
const name$2 = 'frontmatter';
|
|
179
92
|
var frontmatter = definePlugin({
|
|
180
|
-
name: name$
|
|
93
|
+
name: name$2,
|
|
181
94
|
transform(transformHooks) {
|
|
182
95
|
transformHooks.beforeParse.tap((md, context) => {
|
|
183
96
|
const {
|
|
@@ -225,9 +138,9 @@ function normalizeNumber(value) {
|
|
|
225
138
|
return +value;
|
|
226
139
|
}
|
|
227
140
|
|
|
228
|
-
const name = 'npmUrl';
|
|
141
|
+
const name$1 = 'npmUrl';
|
|
229
142
|
var npmUrl = definePlugin({
|
|
230
|
-
name,
|
|
143
|
+
name: name$1,
|
|
231
144
|
transform(transformHooks) {
|
|
232
145
|
transformHooks.afterParse.tap((_, context) => {
|
|
233
146
|
const {
|
|
@@ -240,7 +153,7 @@ var npmUrl = definePlugin({
|
|
|
240
153
|
if (value) {
|
|
241
154
|
markmap[key] = value.map(path => {
|
|
242
155
|
if (path.startsWith('npm:')) {
|
|
243
|
-
return
|
|
156
|
+
return transformHooks.transformer.urlBuilder.getFullUrl(path.slice(4));
|
|
244
157
|
}
|
|
245
158
|
return path;
|
|
246
159
|
});
|
|
@@ -252,7 +165,61 @@ var npmUrl = definePlugin({
|
|
|
252
165
|
}
|
|
253
166
|
});
|
|
254
167
|
|
|
255
|
-
const
|
|
168
|
+
const name = 'hljs';
|
|
169
|
+
const styles = [`highlight.js@${"11.8.0"}/styles/default.css`].map(path => markmapCommon.buildCSSItem(path));
|
|
170
|
+
const config = {
|
|
171
|
+
versions: {
|
|
172
|
+
hljs: "11.8.0"
|
|
173
|
+
},
|
|
174
|
+
styles
|
|
175
|
+
};
|
|
176
|
+
const plugin = definePlugin({
|
|
177
|
+
name,
|
|
178
|
+
config,
|
|
179
|
+
transform(transformHooks) {
|
|
180
|
+
var _plugin$config;
|
|
181
|
+
let enableFeature = markmapCommon.noop;
|
|
182
|
+
transformHooks.parser.tap(md => {
|
|
183
|
+
md.set({
|
|
184
|
+
highlight: (str, language) => {
|
|
185
|
+
enableFeature();
|
|
186
|
+
return hljs.highlightAuto(str, language ? [language] : undefined).value;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
191
|
+
enableFeature = () => {
|
|
192
|
+
context.features[name] = true;
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
return {
|
|
196
|
+
styles: (_plugin$config = plugin.config) == null ? void 0 : _plugin$config.styles
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const plugins = [frontmatter, plugin$1, plugin, npmUrl];
|
|
202
|
+
|
|
203
|
+
function patchJSItem(transformer, item) {
|
|
204
|
+
if (item.type === 'script' && item.data.src) {
|
|
205
|
+
return _extends({}, item, {
|
|
206
|
+
data: _extends({}, item.data, {
|
|
207
|
+
src: transformer.urlBuilder.getFullUrl(item.data.src)
|
|
208
|
+
})
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return item;
|
|
212
|
+
}
|
|
213
|
+
function patchCSSItem(transformer, item) {
|
|
214
|
+
if (item.type === 'stylesheet' && item.data.href) {
|
|
215
|
+
return _extends({}, item, {
|
|
216
|
+
data: _extends({}, item.data, {
|
|
217
|
+
href: transformer.urlBuilder.getFullUrl(item.data.href)
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return item;
|
|
222
|
+
}
|
|
256
223
|
|
|
257
224
|
function cleanNode(node) {
|
|
258
225
|
if (node.type === 'heading') {
|
|
@@ -302,7 +269,8 @@ function resetDepth(node, depth = 0) {
|
|
|
302
269
|
class Transformer {
|
|
303
270
|
constructor(plugins$1 = plugins) {
|
|
304
271
|
this.assetsMap = {};
|
|
305
|
-
this.
|
|
272
|
+
this.urlBuilder = new markmapCommon.UrlBuilder();
|
|
273
|
+
this.hooks = createTransformHooks(this);
|
|
306
274
|
this.plugins = plugins$1.map(plugin => typeof plugin === 'function' ? plugin() : plugin);
|
|
307
275
|
const assetsMap = {};
|
|
308
276
|
for (const {
|
|
@@ -397,10 +365,7 @@ class Transformer {
|
|
|
397
365
|
revoke();
|
|
398
366
|
current.content = `${current.content || ''}${text}`;
|
|
399
367
|
} else if (token.type === 'fence') {
|
|
400
|
-
|
|
401
|
-
// Remarkable only adds className to `<code>` but not `<pre>`, copy it to make PrismJS style work.
|
|
402
|
-
const matches = result.match(/<code( class="[^"]*")>/);
|
|
403
|
-
if (matches) result = result.replace('<pre>', `<pre${matches[1]}>`);
|
|
368
|
+
const result = md.renderer.render([token], md.options, {});
|
|
404
369
|
current.children.push({
|
|
405
370
|
type: token.type,
|
|
406
371
|
depth: depth + 1,
|
|
@@ -446,8 +411,8 @@ class Transformer {
|
|
|
446
411
|
}
|
|
447
412
|
}
|
|
448
413
|
return {
|
|
449
|
-
styles,
|
|
450
|
-
scripts
|
|
414
|
+
styles: styles.map(item => patchCSSItem(this, item)),
|
|
415
|
+
scripts: scripts.map(item => patchJSItem(this, item))
|
|
451
416
|
};
|
|
452
417
|
}
|
|
453
418
|
|
|
@@ -458,15 +423,50 @@ class Transformer {
|
|
|
458
423
|
const keys = this.plugins.map(plugin => plugin.name).filter(name => features[name]);
|
|
459
424
|
return this.getAssets(keys);
|
|
460
425
|
}
|
|
426
|
+
fillTemplate(root, assets, extra) {
|
|
427
|
+
var _extra, _extra$baseJs;
|
|
428
|
+
extra = _extends({}, extra);
|
|
429
|
+
(_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => this.urlBuilder.getFullUrl(path)).map(path => markmapCommon.buildJSItem(path));
|
|
430
|
+
const {
|
|
431
|
+
scripts,
|
|
432
|
+
styles
|
|
433
|
+
} = assets;
|
|
434
|
+
const cssList = [...(styles ? markmapCommon.persistCSS(styles) : [])];
|
|
435
|
+
const context = {
|
|
436
|
+
getMarkmap: () => window.markmap,
|
|
437
|
+
getOptions: extra.getOptions,
|
|
438
|
+
jsonOptions: extra.jsonOptions,
|
|
439
|
+
root
|
|
440
|
+
};
|
|
441
|
+
const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), {
|
|
442
|
+
type: 'iife',
|
|
443
|
+
data: {
|
|
444
|
+
fn: (getMarkmap, getOptions, root, jsonOptions) => {
|
|
445
|
+
const markmap = getMarkmap();
|
|
446
|
+
window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root);
|
|
447
|
+
},
|
|
448
|
+
getParams: ({
|
|
449
|
+
getMarkmap,
|
|
450
|
+
getOptions,
|
|
451
|
+
root,
|
|
452
|
+
jsonOptions
|
|
453
|
+
}) => {
|
|
454
|
+
return [getMarkmap, getOptions, root, jsonOptions];
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}], context)];
|
|
458
|
+
const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
|
|
459
|
+
return html;
|
|
460
|
+
}
|
|
461
461
|
}
|
|
462
462
|
|
|
463
463
|
const transformerVersions = {
|
|
464
|
-
'markmap-lib': '0.14.5-alpha.
|
|
464
|
+
'markmap-lib': '0.14.5-alpha.22+04afb38',
|
|
465
465
|
d3: "7.8.5"
|
|
466
466
|
};
|
|
467
467
|
|
|
468
468
|
exports.Transformer = Transformer;
|
|
469
469
|
exports.baseJsPaths = baseJsPaths;
|
|
470
470
|
exports.builtInPlugins = plugins;
|
|
471
|
-
exports.
|
|
471
|
+
exports.template = template;
|
|
472
472
|
exports.transformerVersions = transformerVersions;
|