markmap-lib 0.13.6-alpha.2 → 0.13.6-alpha.5
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 +25 -20
- package/dist/browser/index.min.js +4 -4
- package/dist/index.esm.js +212 -17
- package/dist/index.js +217 -22
- package/package.json +11 -8
- package/types/types.d.ts +7 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,21 +1,188 @@
|
|
|
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.5+3a7e620 | 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
|
-
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.
|
|
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',
|
|
13
180
|
data: {
|
|
14
181
|
src
|
|
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,24 @@ 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
|
+
/**
|
|
268
|
+
* Find NPM paths and resolve them to full URLs with the same package version as in this library.
|
|
269
|
+
*/
|
|
270
|
+
function resolveNpmPaths(paths, name, version) {
|
|
271
|
+
return paths.map(path => {
|
|
272
|
+
if (typeof path === 'string' && path.startsWith(`${name}/`)) {
|
|
273
|
+
return `https://cdn.jsdelivr.net/npm/${name}@${version}${path.slice(name.length)}`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return path;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
100
280
|
const name$2 = 'katex';
|
|
101
281
|
function transform$2(transformHooks) {
|
|
102
282
|
let enableFeature = () => {};
|
|
@@ -109,11 +289,24 @@ function transform$2(transformHooks) {
|
|
|
109
289
|
}
|
|
110
290
|
});
|
|
111
291
|
});
|
|
112
|
-
transformHooks.
|
|
292
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
113
293
|
enableFeature = () => {
|
|
114
294
|
context.features[name$2] = true;
|
|
115
295
|
};
|
|
116
296
|
});
|
|
297
|
+
transformHooks.afterParse.tap((_, context) => {
|
|
298
|
+
const {
|
|
299
|
+
frontmatter
|
|
300
|
+
} = context;
|
|
301
|
+
|
|
302
|
+
if (frontmatter != null && frontmatter.markmap) {
|
|
303
|
+
['extraJs', 'extraCss'].forEach(key => {
|
|
304
|
+
if (frontmatter.markmap[key]) {
|
|
305
|
+
frontmatter.markmap[key] = resolveNpmPaths(frontmatter.markmap[key], name$2, config$1.versions.katex);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
117
310
|
return {
|
|
118
311
|
styles: config$1.styles,
|
|
119
312
|
scripts: config$1.scripts
|
|
@@ -173,7 +366,7 @@ function transform$1(transformHooks) {
|
|
|
173
366
|
}
|
|
174
367
|
});
|
|
175
368
|
});
|
|
176
|
-
transformHooks.
|
|
369
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
177
370
|
enableFeature = () => {
|
|
178
371
|
context.features[name$1] = true;
|
|
179
372
|
};
|
|
@@ -192,7 +385,7 @@ transform: transform$1
|
|
|
192
385
|
|
|
193
386
|
const name = 'frontmatter';
|
|
194
387
|
function transform(transformHooks) {
|
|
195
|
-
transformHooks.
|
|
388
|
+
transformHooks.beforeParse.tap((md, context) => {
|
|
196
389
|
const origParse = md.parse;
|
|
197
390
|
md.parse = wrapFunction(origParse, {
|
|
198
391
|
before(ctx) {
|
|
@@ -262,7 +455,8 @@ transform: transform
|
|
|
262
455
|
function createTransformHooks() {
|
|
263
456
|
return {
|
|
264
457
|
parser: new Hook(),
|
|
265
|
-
|
|
458
|
+
beforeParse: new Hook(),
|
|
459
|
+
afterParse: new Hook(),
|
|
266
460
|
htmltag: new Hook(),
|
|
267
461
|
retransform: new Hook()
|
|
268
462
|
};
|
|
@@ -282,7 +476,7 @@ function cleanNode(node) {
|
|
|
282
476
|
if (['paragraph', 'fence'].includes(item.type)) {
|
|
283
477
|
if (!node.content) {
|
|
284
478
|
node.content = item.content;
|
|
285
|
-
node.payload = _extends({}, node.payload, item.payload);
|
|
479
|
+
node.payload = _extends$1({}, node.payload, item.payload);
|
|
286
480
|
}
|
|
287
481
|
|
|
288
482
|
return false;
|
|
@@ -300,7 +494,7 @@ function cleanNode(node) {
|
|
|
300
494
|
let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1;
|
|
301
495
|
node.children.forEach(item => {
|
|
302
496
|
if (item.type === 'list_item') {
|
|
303
|
-
item.payload = _extends({}, item.payload, {
|
|
497
|
+
item.payload = _extends$1({}, item.payload, {
|
|
304
498
|
index
|
|
305
499
|
});
|
|
306
500
|
index += 1;
|
|
@@ -454,13 +648,14 @@ class Transformer {
|
|
|
454
648
|
const context = {
|
|
455
649
|
features: {}
|
|
456
650
|
};
|
|
457
|
-
this.hooks.
|
|
651
|
+
this.hooks.beforeParse.call(this.md, context);
|
|
458
652
|
const tokens = this.md.parse(content, {});
|
|
653
|
+
this.hooks.afterParse.call(this.md, context);
|
|
459
654
|
let root = this.buildTree(tokens);
|
|
460
655
|
cleanNode(root);
|
|
461
656
|
if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
|
|
462
657
|
resetDepth(root);
|
|
463
|
-
return _extends({}, context, {
|
|
658
|
+
return _extends$1({}, context, {
|
|
464
659
|
root
|
|
465
660
|
});
|
|
466
661
|
}
|
|
@@ -501,7 +696,7 @@ class Transformer {
|
|
|
501
696
|
}
|
|
502
697
|
|
|
503
698
|
const transformerVersions = {
|
|
504
|
-
'markmap-lib': '0.13.6-alpha.
|
|
699
|
+
'markmap-lib': '0.13.6-alpha.5+3a7e620',
|
|
505
700
|
d3: "6.7.0"
|
|
506
701
|
};
|
|
507
702
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/*! markmap-lib v0.13.6-alpha.
|
|
1
|
+
/*! markmap-lib v0.13.6-alpha.5+3a7e620 | 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,14 +10,182 @@ 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
|
-
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.
|
|
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',
|
|
23
190
|
data: {
|
|
24
191
|
src
|
|
@@ -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,54 @@ 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
|
+
/**
|
|
278
|
+
* Find NPM paths and resolve them to full URLs with the same package version as in this library.
|
|
279
|
+
*/
|
|
280
|
+
function resolveNpmPaths(paths, name, version) {
|
|
281
|
+
return paths.map(path => {
|
|
282
|
+
if (typeof path === 'string' && path.startsWith(`${name}/`)) {
|
|
283
|
+
return `https://cdn.jsdelivr.net/npm/${name}@${version}${path.slice(name.length)}`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return path;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
110
290
|
const name$2 = 'katex';
|
|
111
291
|
function transform$2(transformHooks) {
|
|
112
292
|
let enableFeature = () => {};
|
|
113
293
|
|
|
114
294
|
transformHooks.parser.tap(md => {
|
|
115
295
|
md.use(remarkableKatex__default);
|
|
116
|
-
md.renderer.rules.katex =
|
|
296
|
+
md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, {
|
|
117
297
|
after: () => {
|
|
118
298
|
enableFeature();
|
|
119
299
|
}
|
|
120
300
|
});
|
|
121
301
|
});
|
|
122
|
-
transformHooks.
|
|
302
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
123
303
|
enableFeature = () => {
|
|
124
304
|
context.features[name$2] = true;
|
|
125
305
|
};
|
|
126
306
|
});
|
|
307
|
+
transformHooks.afterParse.tap((_, context) => {
|
|
308
|
+
const {
|
|
309
|
+
frontmatter
|
|
310
|
+
} = context;
|
|
311
|
+
|
|
312
|
+
if (frontmatter != null && frontmatter.markmap) {
|
|
313
|
+
['extraJs', 'extraCss'].forEach(key => {
|
|
314
|
+
if (frontmatter.markmap[key]) {
|
|
315
|
+
frontmatter.markmap[key] = resolveNpmPaths(frontmatter.markmap[key], name$2, config$1.versions.katex);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
});
|
|
127
320
|
return {
|
|
128
321
|
styles: config$1.styles,
|
|
129
322
|
scripts: config$1.scripts
|
|
@@ -183,7 +376,7 @@ function transform$1(transformHooks) {
|
|
|
183
376
|
}
|
|
184
377
|
});
|
|
185
378
|
});
|
|
186
|
-
transformHooks.
|
|
379
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
187
380
|
enableFeature = () => {
|
|
188
381
|
context.features[name$1] = true;
|
|
189
382
|
};
|
|
@@ -202,9 +395,9 @@ transform: transform$1
|
|
|
202
395
|
|
|
203
396
|
const name = 'frontmatter';
|
|
204
397
|
function transform(transformHooks) {
|
|
205
|
-
transformHooks.
|
|
398
|
+
transformHooks.beforeParse.tap((md, context) => {
|
|
206
399
|
const origParse = md.parse;
|
|
207
|
-
md.parse =
|
|
400
|
+
md.parse = wrapFunction(origParse, {
|
|
208
401
|
before(ctx) {
|
|
209
402
|
const [content] = ctx.args;
|
|
210
403
|
if (!content.startsWith('---\n')) return;
|
|
@@ -271,10 +464,11 @@ transform: transform
|
|
|
271
464
|
|
|
272
465
|
function createTransformHooks() {
|
|
273
466
|
return {
|
|
274
|
-
parser: new
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
467
|
+
parser: new Hook(),
|
|
468
|
+
beforeParse: new Hook(),
|
|
469
|
+
afterParse: new Hook(),
|
|
470
|
+
htmltag: new Hook(),
|
|
471
|
+
retransform: new Hook()
|
|
278
472
|
};
|
|
279
473
|
}
|
|
280
474
|
|
|
@@ -357,7 +551,7 @@ class Transformer {
|
|
|
357
551
|
breaks: true,
|
|
358
552
|
maxNesting: Infinity
|
|
359
553
|
});
|
|
360
|
-
md.renderer.rules.htmltag =
|
|
554
|
+
md.renderer.rules.htmltag = wrapFunction(md.renderer.rules.htmltag, {
|
|
361
555
|
after: ctx => {
|
|
362
556
|
this.hooks.htmltag.call(ctx);
|
|
363
557
|
}
|
|
@@ -464,8 +658,9 @@ class Transformer {
|
|
|
464
658
|
const context = {
|
|
465
659
|
features: {}
|
|
466
660
|
};
|
|
467
|
-
this.hooks.
|
|
661
|
+
this.hooks.beforeParse.call(this.md, context);
|
|
468
662
|
const tokens = this.md.parse(content, {});
|
|
663
|
+
this.hooks.afterParse.call(this.md, context);
|
|
469
664
|
let root = this.buildTree(tokens);
|
|
470
665
|
cleanNode(root);
|
|
471
666
|
if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
|
|
@@ -511,7 +706,7 @@ class Transformer {
|
|
|
511
706
|
}
|
|
512
707
|
|
|
513
708
|
const transformerVersions = {
|
|
514
|
-
'markmap-lib': '0.13.6-alpha.
|
|
709
|
+
'markmap-lib': '0.13.6-alpha.5+3a7e620',
|
|
515
710
|
d3: "6.7.0"
|
|
516
711
|
};
|
|
517
712
|
|