markmap-lib 0.13.6-alpha.3 → 0.13.6-alpha.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.js +23 -15
- package/dist/browser/index.min.js +4 -4
- package/dist/index.esm.js +217 -16
- package/dist/index.js +222 -21
- package/package.json +10 -7
- package/types/types.d.ts +7 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,12 +1,179 @@
|
|
|
1
|
-
/*! markmap-lib v0.13.6-alpha.
|
|
2
|
-
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
3
|
-
import { persistCSS, persistJS, wrapFunction, Hook } from 'markmap-common';
|
|
1
|
+
/*! markmap-lib v0.13.6-alpha.6+e810c56 | MIT License */
|
|
2
|
+
import _extends$1 from '@babel/runtime/helpers/esm/extends';
|
|
4
3
|
import { Remarkable } from 'remarkable';
|
|
5
4
|
import remarkableKatex from 'remarkable-katex';
|
|
6
5
|
import Prism from 'prismjs';
|
|
7
6
|
import loadLanguages from 'prismjs/components/';
|
|
8
7
|
import yaml from 'js-yaml';
|
|
9
8
|
|
|
9
|
+
/*! markmap-common v0.13.4 | MIT License */
|
|
10
|
+
class Hook {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.listeners = [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
tap(fn) {
|
|
16
|
+
this.listeners.push(fn);
|
|
17
|
+
return () => this.revoke(fn);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
revoke(fn) {
|
|
21
|
+
const i = this.listeners.indexOf(fn);
|
|
22
|
+
if (i >= 0) this.listeners.splice(i, 1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
revokeAll() {
|
|
26
|
+
this.listeners.splice(0);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
call(...args) {
|
|
30
|
+
for (const fn of this.listeners) {
|
|
31
|
+
fn(...args);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function _extends() {
|
|
38
|
+
_extends = Object.assign || function (target) {
|
|
39
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
40
|
+
var source = arguments[i];
|
|
41
|
+
|
|
42
|
+
for (var key in source) {
|
|
43
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
44
|
+
target[key] = source[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return target;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return _extends.apply(this, arguments);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
56
|
+
if (source == null) return {};
|
|
57
|
+
var target = {};
|
|
58
|
+
var sourceKeys = Object.keys(source);
|
|
59
|
+
var key, i;
|
|
60
|
+
|
|
61
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
62
|
+
key = sourceKeys[i];
|
|
63
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
64
|
+
target[key] = source[key];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return target;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const _excluded = ["textContent"];
|
|
71
|
+
|
|
72
|
+
function escapeHtml(html) {
|
|
73
|
+
return html.replace(/[&<"]/g, m => ({
|
|
74
|
+
'&': '&',
|
|
75
|
+
'<': '<',
|
|
76
|
+
'"': '"'
|
|
77
|
+
})[m]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function escapeScript(content) {
|
|
81
|
+
return content.replace(/<(\/script>)/g, '\\x3c$2');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function htmlOpen(tagName, attrs) {
|
|
85
|
+
const attrStr = attrs ? Object.entries(attrs).map(([key, value]) => {
|
|
86
|
+
if (value == null || value === false) return;
|
|
87
|
+
key = ` ${escapeHtml(key)}`;
|
|
88
|
+
if (value === true) return key;
|
|
89
|
+
return `${key}="${escapeHtml(value)}"`;
|
|
90
|
+
}).filter(Boolean).join('') : '';
|
|
91
|
+
return `<${tagName}${attrStr}>`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function htmlClose(tagName) {
|
|
95
|
+
return `</${tagName}>`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function wrapHtml(tagName, content, attrs) {
|
|
99
|
+
if (content == null) return htmlOpen(tagName, attrs);
|
|
100
|
+
return htmlOpen(tagName, attrs) + (content || '') + htmlClose(tagName);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function buildCode(fn, args) {
|
|
104
|
+
const params = args.map(arg => {
|
|
105
|
+
if (typeof arg === 'function') return arg.toString();
|
|
106
|
+
return JSON.stringify(arg != null ? arg : null);
|
|
107
|
+
}).join(',');
|
|
108
|
+
return `(${fn.toString()})(${params})`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function persistJS(items, context) {
|
|
112
|
+
return items.map(item => {
|
|
113
|
+
if (item.type === 'script') {
|
|
114
|
+
const _item$data = item.data,
|
|
115
|
+
{
|
|
116
|
+
textContent
|
|
117
|
+
} = _item$data,
|
|
118
|
+
rest = _objectWithoutPropertiesLoose(_item$data, _excluded);
|
|
119
|
+
|
|
120
|
+
return wrapHtml('script', textContent || '', rest);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (item.type === 'iife') {
|
|
124
|
+
const {
|
|
125
|
+
fn,
|
|
126
|
+
getParams
|
|
127
|
+
} = item.data;
|
|
128
|
+
return wrapHtml('script', escapeScript(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || [])));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return '';
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function persistCSS(items) {
|
|
136
|
+
return items.map(item => {
|
|
137
|
+
if (item.type === 'stylesheet') {
|
|
138
|
+
return wrapHtml('link', null, _extends({
|
|
139
|
+
rel: 'stylesheet'
|
|
140
|
+
}, item.data));
|
|
141
|
+
}
|
|
142
|
+
/* else if (item.type === 'style') */
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
return wrapHtml('style', item.data);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
Math.random().toString(36).slice(2, 8);
|
|
150
|
+
|
|
151
|
+
function wrapFunction(fn, {
|
|
152
|
+
before,
|
|
153
|
+
after
|
|
154
|
+
}) {
|
|
155
|
+
return function wrapped(...args) {
|
|
156
|
+
const ctx = {
|
|
157
|
+
args,
|
|
158
|
+
thisObj: this
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
if (before) before(ctx);
|
|
163
|
+
} catch (_unused) {// ignore
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
ctx.result = fn.apply(ctx.thisObj, ctx.args);
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
if (after) after(ctx);
|
|
170
|
+
} catch (_unused2) {// ignore
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return ctx.result;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
10
177
|
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";
|
|
11
178
|
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.5"}`].map(src => ({
|
|
12
179
|
type: 'script',
|
|
@@ -15,7 +182,7 @@ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsde
|
|
|
15
182
|
}
|
|
16
183
|
}));
|
|
17
184
|
function fillTemplate(root, assets, extra) {
|
|
18
|
-
extra = _extends({
|
|
185
|
+
extra = _extends$1({
|
|
19
186
|
baseJs: BASE_JS
|
|
20
187
|
}, extra);
|
|
21
188
|
const {
|
|
@@ -52,13 +219,13 @@ function fillTemplate(root, assets, extra) {
|
|
|
52
219
|
|
|
53
220
|
var config$1 = {
|
|
54
221
|
versions: {
|
|
55
|
-
katex: "0.
|
|
222
|
+
katex: "0.16.0",
|
|
56
223
|
webfontloader: "1.6.28"
|
|
57
224
|
},
|
|
58
225
|
preloadScripts: [{
|
|
59
226
|
type: 'script',
|
|
60
227
|
data: {
|
|
61
|
-
src: `https://cdn.jsdelivr.net/npm/katex@${"0.
|
|
228
|
+
src: `https://cdn.jsdelivr.net/npm/katex@${"0.16.0"}/dist/katex.min.js`
|
|
62
229
|
}
|
|
63
230
|
}],
|
|
64
231
|
scripts: [{
|
|
@@ -92,11 +259,30 @@ var config$1 = {
|
|
|
92
259
|
styles: [{
|
|
93
260
|
type: 'stylesheet',
|
|
94
261
|
data: {
|
|
95
|
-
href: `https://cdn.jsdelivr.net/npm/katex@${"0.
|
|
262
|
+
href: `https://cdn.jsdelivr.net/npm/katex@${"0.16.0"}/dist/katex.min.css`
|
|
96
263
|
}
|
|
97
264
|
}]
|
|
98
265
|
};
|
|
99
266
|
|
|
267
|
+
const npmPrefix = 'https://cdn.jsdelivr.net/npm/';
|
|
268
|
+
/**
|
|
269
|
+
* Find NPM paths and resolve them to full URLs with the same package version as in this library.
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
function resolveNpmPaths(paths, name, version) {
|
|
273
|
+
return paths.map(path => {
|
|
274
|
+
if (typeof path === 'string') {
|
|
275
|
+
if (path.startsWith(`${name}/`)) {
|
|
276
|
+
path = `${npmPrefix}${name}@${version}${path.slice(name.length)}`;
|
|
277
|
+
} else if (path.startsWith(`${name}@`)) {
|
|
278
|
+
path = `${npmPrefix}${path}`;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return path;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
100
286
|
const name$2 = 'katex';
|
|
101
287
|
function transform$2(transformHooks) {
|
|
102
288
|
let enableFeature = () => {};
|
|
@@ -109,11 +295,24 @@ function transform$2(transformHooks) {
|
|
|
109
295
|
}
|
|
110
296
|
});
|
|
111
297
|
});
|
|
112
|
-
transformHooks.
|
|
298
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
113
299
|
enableFeature = () => {
|
|
114
300
|
context.features[name$2] = true;
|
|
115
301
|
};
|
|
116
302
|
});
|
|
303
|
+
transformHooks.afterParse.tap((_, context) => {
|
|
304
|
+
const {
|
|
305
|
+
frontmatter
|
|
306
|
+
} = context;
|
|
307
|
+
|
|
308
|
+
if (frontmatter != null && frontmatter.markmap) {
|
|
309
|
+
['extraJs', 'extraCss'].forEach(key => {
|
|
310
|
+
if (frontmatter.markmap[key]) {
|
|
311
|
+
frontmatter.markmap[key] = resolveNpmPaths(frontmatter.markmap[key], name$2, config$1.versions.katex);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
});
|
|
117
316
|
return {
|
|
118
317
|
styles: config$1.styles,
|
|
119
318
|
scripts: config$1.scripts
|
|
@@ -173,7 +372,7 @@ function transform$1(transformHooks) {
|
|
|
173
372
|
}
|
|
174
373
|
});
|
|
175
374
|
});
|
|
176
|
-
transformHooks.
|
|
375
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
177
376
|
enableFeature = () => {
|
|
178
377
|
context.features[name$1] = true;
|
|
179
378
|
};
|
|
@@ -192,7 +391,7 @@ transform: transform$1
|
|
|
192
391
|
|
|
193
392
|
const name = 'frontmatter';
|
|
194
393
|
function transform(transformHooks) {
|
|
195
|
-
transformHooks.
|
|
394
|
+
transformHooks.beforeParse.tap((md, context) => {
|
|
196
395
|
const origParse = md.parse;
|
|
197
396
|
md.parse = wrapFunction(origParse, {
|
|
198
397
|
before(ctx) {
|
|
@@ -262,7 +461,8 @@ transform: transform
|
|
|
262
461
|
function createTransformHooks() {
|
|
263
462
|
return {
|
|
264
463
|
parser: new Hook(),
|
|
265
|
-
|
|
464
|
+
beforeParse: new Hook(),
|
|
465
|
+
afterParse: new Hook(),
|
|
266
466
|
htmltag: new Hook(),
|
|
267
467
|
retransform: new Hook()
|
|
268
468
|
};
|
|
@@ -282,7 +482,7 @@ function cleanNode(node) {
|
|
|
282
482
|
if (['paragraph', 'fence'].includes(item.type)) {
|
|
283
483
|
if (!node.content) {
|
|
284
484
|
node.content = item.content;
|
|
285
|
-
node.payload = _extends({}, node.payload, item.payload);
|
|
485
|
+
node.payload = _extends$1({}, node.payload, item.payload);
|
|
286
486
|
}
|
|
287
487
|
|
|
288
488
|
return false;
|
|
@@ -300,7 +500,7 @@ function cleanNode(node) {
|
|
|
300
500
|
let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1;
|
|
301
501
|
node.children.forEach(item => {
|
|
302
502
|
if (item.type === 'list_item') {
|
|
303
|
-
item.payload = _extends({}, item.payload, {
|
|
503
|
+
item.payload = _extends$1({}, item.payload, {
|
|
304
504
|
index
|
|
305
505
|
});
|
|
306
506
|
index += 1;
|
|
@@ -454,13 +654,14 @@ class Transformer {
|
|
|
454
654
|
const context = {
|
|
455
655
|
features: {}
|
|
456
656
|
};
|
|
457
|
-
this.hooks.
|
|
657
|
+
this.hooks.beforeParse.call(this.md, context);
|
|
458
658
|
const tokens = this.md.parse(content, {});
|
|
659
|
+
this.hooks.afterParse.call(this.md, context);
|
|
459
660
|
let root = this.buildTree(tokens);
|
|
460
661
|
cleanNode(root);
|
|
461
662
|
if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
|
|
462
663
|
resetDepth(root);
|
|
463
|
-
return _extends({}, context, {
|
|
664
|
+
return _extends$1({}, context, {
|
|
464
665
|
root
|
|
465
666
|
});
|
|
466
667
|
}
|
|
@@ -501,7 +702,7 @@ class Transformer {
|
|
|
501
702
|
}
|
|
502
703
|
|
|
503
704
|
const transformerVersions = {
|
|
504
|
-
'markmap-lib': '0.13.6-alpha.
|
|
705
|
+
'markmap-lib': '0.13.6-alpha.6+e810c56',
|
|
505
706
|
d3: "6.7.0"
|
|
506
707
|
};
|
|
507
708
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/*! markmap-lib v0.13.6-alpha.
|
|
1
|
+
/*! markmap-lib v0.13.6-alpha.6+e810c56 | MIT License */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var _extends = require('@babel/runtime/helpers/extends');
|
|
5
|
-
var markmapCommon = require('markmap-common');
|
|
4
|
+
var _extends$1 = require('@babel/runtime/helpers/extends');
|
|
6
5
|
var remarkable = require('remarkable');
|
|
7
6
|
var remarkableKatex = require('remarkable-katex');
|
|
8
7
|
var Prism = require('prismjs');
|
|
@@ -11,12 +10,180 @@ var yaml = require('js-yaml');
|
|
|
11
10
|
|
|
12
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
13
12
|
|
|
14
|
-
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
13
|
+
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends$1);
|
|
15
14
|
var remarkableKatex__default = /*#__PURE__*/_interopDefaultLegacy(remarkableKatex);
|
|
16
15
|
var Prism__default = /*#__PURE__*/_interopDefaultLegacy(Prism);
|
|
17
16
|
var loadLanguages__default = /*#__PURE__*/_interopDefaultLegacy(loadLanguages);
|
|
18
17
|
var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
|
|
19
18
|
|
|
19
|
+
/*! markmap-common v0.13.4 | MIT License */
|
|
20
|
+
class Hook {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.listeners = [];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
tap(fn) {
|
|
26
|
+
this.listeners.push(fn);
|
|
27
|
+
return () => this.revoke(fn);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
revoke(fn) {
|
|
31
|
+
const i = this.listeners.indexOf(fn);
|
|
32
|
+
if (i >= 0) this.listeners.splice(i, 1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
revokeAll() {
|
|
36
|
+
this.listeners.splice(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
call(...args) {
|
|
40
|
+
for (const fn of this.listeners) {
|
|
41
|
+
fn(...args);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function _extends() {
|
|
48
|
+
_extends = Object.assign || function (target) {
|
|
49
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
50
|
+
var source = arguments[i];
|
|
51
|
+
|
|
52
|
+
for (var key in source) {
|
|
53
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
54
|
+
target[key] = source[key];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return target;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return _extends.apply(this, arguments);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
66
|
+
if (source == null) return {};
|
|
67
|
+
var target = {};
|
|
68
|
+
var sourceKeys = Object.keys(source);
|
|
69
|
+
var key, i;
|
|
70
|
+
|
|
71
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
72
|
+
key = sourceKeys[i];
|
|
73
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
74
|
+
target[key] = source[key];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return target;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const _excluded = ["textContent"];
|
|
81
|
+
|
|
82
|
+
function escapeHtml(html) {
|
|
83
|
+
return html.replace(/[&<"]/g, m => ({
|
|
84
|
+
'&': '&',
|
|
85
|
+
'<': '<',
|
|
86
|
+
'"': '"'
|
|
87
|
+
})[m]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function escapeScript(content) {
|
|
91
|
+
return content.replace(/<(\/script>)/g, '\\x3c$2');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function htmlOpen(tagName, attrs) {
|
|
95
|
+
const attrStr = attrs ? Object.entries(attrs).map(([key, value]) => {
|
|
96
|
+
if (value == null || value === false) return;
|
|
97
|
+
key = ` ${escapeHtml(key)}`;
|
|
98
|
+
if (value === true) return key;
|
|
99
|
+
return `${key}="${escapeHtml(value)}"`;
|
|
100
|
+
}).filter(Boolean).join('') : '';
|
|
101
|
+
return `<${tagName}${attrStr}>`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function htmlClose(tagName) {
|
|
105
|
+
return `</${tagName}>`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function wrapHtml(tagName, content, attrs) {
|
|
109
|
+
if (content == null) return htmlOpen(tagName, attrs);
|
|
110
|
+
return htmlOpen(tagName, attrs) + (content || '') + htmlClose(tagName);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function buildCode(fn, args) {
|
|
114
|
+
const params = args.map(arg => {
|
|
115
|
+
if (typeof arg === 'function') return arg.toString();
|
|
116
|
+
return JSON.stringify(arg != null ? arg : null);
|
|
117
|
+
}).join(',');
|
|
118
|
+
return `(${fn.toString()})(${params})`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function persistJS(items, context) {
|
|
122
|
+
return items.map(item => {
|
|
123
|
+
if (item.type === 'script') {
|
|
124
|
+
const _item$data = item.data,
|
|
125
|
+
{
|
|
126
|
+
textContent
|
|
127
|
+
} = _item$data,
|
|
128
|
+
rest = _objectWithoutPropertiesLoose(_item$data, _excluded);
|
|
129
|
+
|
|
130
|
+
return wrapHtml('script', textContent || '', rest);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (item.type === 'iife') {
|
|
134
|
+
const {
|
|
135
|
+
fn,
|
|
136
|
+
getParams
|
|
137
|
+
} = item.data;
|
|
138
|
+
return wrapHtml('script', escapeScript(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || [])));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return '';
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function persistCSS(items) {
|
|
146
|
+
return items.map(item => {
|
|
147
|
+
if (item.type === 'stylesheet') {
|
|
148
|
+
return wrapHtml('link', null, _extends({
|
|
149
|
+
rel: 'stylesheet'
|
|
150
|
+
}, item.data));
|
|
151
|
+
}
|
|
152
|
+
/* else if (item.type === 'style') */
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
return wrapHtml('style', item.data);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
Math.random().toString(36).slice(2, 8);
|
|
160
|
+
|
|
161
|
+
function wrapFunction(fn, {
|
|
162
|
+
before,
|
|
163
|
+
after
|
|
164
|
+
}) {
|
|
165
|
+
return function wrapped(...args) {
|
|
166
|
+
const ctx = {
|
|
167
|
+
args,
|
|
168
|
+
thisObj: this
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
if (before) before(ctx);
|
|
173
|
+
} catch (_unused) {// ignore
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
ctx.result = fn.apply(ctx.thisObj, ctx.args);
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
if (after) after(ctx);
|
|
180
|
+
} catch (_unused2) {// ignore
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return ctx.result;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
20
187
|
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";
|
|
21
188
|
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.5"}`].map(src => ({
|
|
22
189
|
type: 'script',
|
|
@@ -32,14 +199,14 @@ function fillTemplate(root, assets, extra) {
|
|
|
32
199
|
scripts,
|
|
33
200
|
styles
|
|
34
201
|
} = assets;
|
|
35
|
-
const cssList = [...(styles ?
|
|
202
|
+
const cssList = [...(styles ? persistCSS(styles) : [])];
|
|
36
203
|
const context = {
|
|
37
204
|
getMarkmap: () => window.markmap,
|
|
38
205
|
getOptions: extra.getOptions,
|
|
39
206
|
jsonOptions: extra.jsonOptions,
|
|
40
207
|
root
|
|
41
208
|
};
|
|
42
|
-
const jsList = [...
|
|
209
|
+
const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
|
|
43
210
|
type: 'iife',
|
|
44
211
|
data: {
|
|
45
212
|
fn: (getMarkmap, getOptions, root, jsonOptions) => {
|
|
@@ -62,13 +229,13 @@ function fillTemplate(root, assets, extra) {
|
|
|
62
229
|
|
|
63
230
|
var config$1 = {
|
|
64
231
|
versions: {
|
|
65
|
-
katex: "0.
|
|
232
|
+
katex: "0.16.0",
|
|
66
233
|
webfontloader: "1.6.28"
|
|
67
234
|
},
|
|
68
235
|
preloadScripts: [{
|
|
69
236
|
type: 'script',
|
|
70
237
|
data: {
|
|
71
|
-
src: `https://cdn.jsdelivr.net/npm/katex@${"0.
|
|
238
|
+
src: `https://cdn.jsdelivr.net/npm/katex@${"0.16.0"}/dist/katex.min.js`
|
|
72
239
|
}
|
|
73
240
|
}],
|
|
74
241
|
scripts: [{
|
|
@@ -102,28 +269,60 @@ var config$1 = {
|
|
|
102
269
|
styles: [{
|
|
103
270
|
type: 'stylesheet',
|
|
104
271
|
data: {
|
|
105
|
-
href: `https://cdn.jsdelivr.net/npm/katex@${"0.
|
|
272
|
+
href: `https://cdn.jsdelivr.net/npm/katex@${"0.16.0"}/dist/katex.min.css`
|
|
106
273
|
}
|
|
107
274
|
}]
|
|
108
275
|
};
|
|
109
276
|
|
|
277
|
+
const npmPrefix = 'https://cdn.jsdelivr.net/npm/';
|
|
278
|
+
/**
|
|
279
|
+
* Find NPM paths and resolve them to full URLs with the same package version as in this library.
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
function resolveNpmPaths(paths, name, version) {
|
|
283
|
+
return paths.map(path => {
|
|
284
|
+
if (typeof path === 'string') {
|
|
285
|
+
if (path.startsWith(`${name}/`)) {
|
|
286
|
+
path = `${npmPrefix}${name}@${version}${path.slice(name.length)}`;
|
|
287
|
+
} else if (path.startsWith(`${name}@`)) {
|
|
288
|
+
path = `${npmPrefix}${path}`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return path;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
110
296
|
const name$2 = 'katex';
|
|
111
297
|
function transform$2(transformHooks) {
|
|
112
298
|
let enableFeature = () => {};
|
|
113
299
|
|
|
114
300
|
transformHooks.parser.tap(md => {
|
|
115
301
|
md.use(remarkableKatex__default);
|
|
116
|
-
md.renderer.rules.katex =
|
|
302
|
+
md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, {
|
|
117
303
|
after: () => {
|
|
118
304
|
enableFeature();
|
|
119
305
|
}
|
|
120
306
|
});
|
|
121
307
|
});
|
|
122
|
-
transformHooks.
|
|
308
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
123
309
|
enableFeature = () => {
|
|
124
310
|
context.features[name$2] = true;
|
|
125
311
|
};
|
|
126
312
|
});
|
|
313
|
+
transformHooks.afterParse.tap((_, context) => {
|
|
314
|
+
const {
|
|
315
|
+
frontmatter
|
|
316
|
+
} = context;
|
|
317
|
+
|
|
318
|
+
if (frontmatter != null && frontmatter.markmap) {
|
|
319
|
+
['extraJs', 'extraCss'].forEach(key => {
|
|
320
|
+
if (frontmatter.markmap[key]) {
|
|
321
|
+
frontmatter.markmap[key] = resolveNpmPaths(frontmatter.markmap[key], name$2, config$1.versions.katex);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
});
|
|
127
326
|
return {
|
|
128
327
|
styles: config$1.styles,
|
|
129
328
|
scripts: config$1.scripts
|
|
@@ -183,7 +382,7 @@ function transform$1(transformHooks) {
|
|
|
183
382
|
}
|
|
184
383
|
});
|
|
185
384
|
});
|
|
186
|
-
transformHooks.
|
|
385
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
187
386
|
enableFeature = () => {
|
|
188
387
|
context.features[name$1] = true;
|
|
189
388
|
};
|
|
@@ -202,9 +401,9 @@ transform: transform$1
|
|
|
202
401
|
|
|
203
402
|
const name = 'frontmatter';
|
|
204
403
|
function transform(transformHooks) {
|
|
205
|
-
transformHooks.
|
|
404
|
+
transformHooks.beforeParse.tap((md, context) => {
|
|
206
405
|
const origParse = md.parse;
|
|
207
|
-
md.parse =
|
|
406
|
+
md.parse = wrapFunction(origParse, {
|
|
208
407
|
before(ctx) {
|
|
209
408
|
const [content] = ctx.args;
|
|
210
409
|
if (!content.startsWith('---\n')) return;
|
|
@@ -271,10 +470,11 @@ transform: transform
|
|
|
271
470
|
|
|
272
471
|
function createTransformHooks() {
|
|
273
472
|
return {
|
|
274
|
-
parser: new
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
473
|
+
parser: new Hook(),
|
|
474
|
+
beforeParse: new Hook(),
|
|
475
|
+
afterParse: new Hook(),
|
|
476
|
+
htmltag: new Hook(),
|
|
477
|
+
retransform: new Hook()
|
|
278
478
|
};
|
|
279
479
|
}
|
|
280
480
|
|
|
@@ -357,7 +557,7 @@ class Transformer {
|
|
|
357
557
|
breaks: true,
|
|
358
558
|
maxNesting: Infinity
|
|
359
559
|
});
|
|
360
|
-
md.renderer.rules.htmltag =
|
|
560
|
+
md.renderer.rules.htmltag = wrapFunction(md.renderer.rules.htmltag, {
|
|
361
561
|
after: ctx => {
|
|
362
562
|
this.hooks.htmltag.call(ctx);
|
|
363
563
|
}
|
|
@@ -464,8 +664,9 @@ class Transformer {
|
|
|
464
664
|
const context = {
|
|
465
665
|
features: {}
|
|
466
666
|
};
|
|
467
|
-
this.hooks.
|
|
667
|
+
this.hooks.beforeParse.call(this.md, context);
|
|
468
668
|
const tokens = this.md.parse(content, {});
|
|
669
|
+
this.hooks.afterParse.call(this.md, context);
|
|
469
670
|
let root = this.buildTree(tokens);
|
|
470
671
|
cleanNode(root);
|
|
471
672
|
if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
|
|
@@ -511,7 +712,7 @@ class Transformer {
|
|
|
511
712
|
}
|
|
512
713
|
|
|
513
714
|
const transformerVersions = {
|
|
514
|
-
'markmap-lib': '0.13.6-alpha.
|
|
715
|
+
'markmap-lib': '0.13.6-alpha.6+e810c56',
|
|
515
716
|
d3: "6.7.0"
|
|
516
717
|
};
|
|
517
718
|
|