markmap-lib 0.15.0-alpha.0 → 0.15.0
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 +225 -460
- package/dist/browser/index.mjs +244 -10860
- package/dist/index.js +179 -176
- package/dist/index.mjs +179 -176
- package/package.json +20 -8
- package/types/constants.d.ts +2 -0
- package/types/index.d.ts +2 -2
- 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 +10 -4
- package/types/types.d.ts +6 -2
- package/types/template.d.ts +0 -8
package/dist/index.mjs
CHANGED
|
@@ -1,87 +1,51 @@
|
|
|
1
|
-
/*! markmap-lib v0.15.0
|
|
1
|
+
/*! markmap-lib v0.15.0 | MIT License */
|
|
2
2
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
3
|
-
import { buildJSItem, persistCSS, persistJS, buildCSSItem, Hook, wrapFunction, noop, getFullUrl } from 'markmap-common';
|
|
4
3
|
import { Remarkable } from 'remarkable';
|
|
4
|
+
import { buildJSItem, buildCSSItem, Hook, wrapFunction, noop, UrlBuilder, persistCSS, persistJS } from 'markmap-common';
|
|
5
5
|
import remarkableKatex from 'remarkable-katex';
|
|
6
|
-
import Prism from 'prismjs';
|
|
7
|
-
import loadLanguages from 'prismjs/components/';
|
|
8
6
|
import yaml from 'js-yaml';
|
|
7
|
+
import hljs from 'highlight.js';
|
|
9
8
|
|
|
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";
|
|
11
|
-
const baseJsPaths = [`d3@${"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
root
|
|
26
|
-
};
|
|
27
|
-
const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
|
|
9
|
+
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
|
+
const baseJsPaths = [`d3@${"7.8.5"}/dist/d3.min.js`, `markmap-view@${"0.15.0"}/dist/browser/index.js`];
|
|
11
|
+
|
|
12
|
+
const name$3 = 'katex';
|
|
13
|
+
const preloadScripts = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => buildJSItem(path));
|
|
14
|
+
const webfontloader = buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
|
|
15
|
+
webfontloader.data.defer = true;
|
|
16
|
+
const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => buildCSSItem(path));
|
|
17
|
+
const config$1 = {
|
|
18
|
+
versions: {
|
|
19
|
+
katex: "0.16.8" ,
|
|
20
|
+
webfontloader: "1.6.28"
|
|
21
|
+
},
|
|
22
|
+
preloadScripts,
|
|
23
|
+
scripts: [{
|
|
28
24
|
type: 'iife',
|
|
29
25
|
data: {
|
|
30
|
-
fn:
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
fn: getMarkmap => {
|
|
27
|
+
window.WebFontConfig = {
|
|
28
|
+
custom: {
|
|
29
|
+
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']
|
|
30
|
+
},
|
|
31
|
+
active: () => {
|
|
32
|
+
getMarkmap().refreshHook.call();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
33
35
|
},
|
|
34
|
-
getParams
|
|
35
|
-
getMarkmap
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
jsonOptions
|
|
39
|
-
}) => {
|
|
40
|
-
return [getMarkmap, getOptions, root, jsonOptions];
|
|
36
|
+
getParams({
|
|
37
|
+
getMarkmap
|
|
38
|
+
}) {
|
|
39
|
+
return [getMarkmap];
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getConfig$1() {
|
|
49
|
-
const preloadScripts = [`katex@${"0.16.0"}/dist/katex.min.js`].map(buildJSItem);
|
|
50
|
-
const webfontloader = buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
|
|
51
|
-
webfontloader.data.defer = true;
|
|
52
|
-
const styles = [`katex@${"0.16.0"}/dist/katex.min.css`].map(buildCSSItem);
|
|
53
|
-
return {
|
|
54
|
-
versions: {
|
|
55
|
-
katex: "0.16.0",
|
|
56
|
-
webfontloader: "1.6.28"
|
|
57
|
-
},
|
|
58
|
-
preloadScripts,
|
|
59
|
-
scripts: [{
|
|
60
|
-
type: 'iife',
|
|
61
|
-
data: {
|
|
62
|
-
fn: getMarkmap => {
|
|
63
|
-
window.WebFontConfig = {
|
|
64
|
-
custom: {
|
|
65
|
-
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']
|
|
66
|
-
},
|
|
67
|
-
active: () => {
|
|
68
|
-
getMarkmap().refreshHook.call();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
getParams({
|
|
73
|
-
getMarkmap
|
|
74
|
-
}) {
|
|
75
|
-
return [getMarkmap];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}, webfontloader],
|
|
79
|
-
styles
|
|
80
|
-
};
|
|
81
|
-
}
|
|
42
|
+
}, webfontloader],
|
|
43
|
+
styles: styles$1
|
|
44
|
+
};
|
|
82
45
|
|
|
83
|
-
function createTransformHooks() {
|
|
46
|
+
function createTransformHooks(transformer) {
|
|
84
47
|
return {
|
|
48
|
+
transformer,
|
|
85
49
|
parser: new Hook(),
|
|
86
50
|
beforeParse: new Hook(),
|
|
87
51
|
afterParse: new Hook(),
|
|
@@ -97,85 +61,34 @@ function definePlugin(plugin) {
|
|
|
97
61
|
return plugin;
|
|
98
62
|
}
|
|
99
63
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
config
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return render(...args);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
115
|
-
enableFeature = () => {
|
|
116
|
-
context.features[name$3] = true;
|
|
117
|
-
};
|
|
118
|
-
});
|
|
119
|
-
return {
|
|
120
|
-
styles: plugin.config.styles,
|
|
121
|
-
scripts: plugin.config.scripts
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
return plugin;
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
function getConfig() {
|
|
129
|
-
const preloadScripts = [`prismjs@${"1.28.0"}/components/prism-core.min.js`, `prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`].map(buildJSItem);
|
|
130
|
-
const styles = [`prismjs@${"1.28.0"}/themes/prism.css`].map(buildCSSItem);
|
|
131
|
-
return {
|
|
132
|
-
versions: {
|
|
133
|
-
prismjs: "1.28.0"
|
|
134
|
-
},
|
|
135
|
-
preloadScripts,
|
|
136
|
-
styles
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const name$2 = 'prism';
|
|
141
|
-
var prism = definePlugin(() => {
|
|
142
|
-
const plugin = {
|
|
143
|
-
name: name$2,
|
|
144
|
-
config: getConfig(),
|
|
145
|
-
transform(transformHooks) {
|
|
146
|
-
let enableFeature = noop;
|
|
147
|
-
transformHooks.parser.tap(md => {
|
|
148
|
-
md.set({
|
|
149
|
-
highlight: (str, lang) => {
|
|
150
|
-
enableFeature();
|
|
151
|
-
let grammar = Prism.languages[lang];
|
|
152
|
-
if (!grammar && lang) {
|
|
153
|
-
loadLanguages([lang]);
|
|
154
|
-
grammar = Prism.languages[lang];
|
|
155
|
-
}
|
|
156
|
-
if (grammar) {
|
|
157
|
-
return Prism.highlight(str, grammar, lang);
|
|
158
|
-
}
|
|
159
|
-
return '';
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
transformHooks.beforeParse.tap((_, context) => {
|
|
164
|
-
enableFeature = () => {
|
|
165
|
-
context.features[name$2] = true;
|
|
166
|
-
};
|
|
64
|
+
const plugin$1 = definePlugin({
|
|
65
|
+
name: name$3,
|
|
66
|
+
config: config$1,
|
|
67
|
+
transform(transformHooks) {
|
|
68
|
+
var _plugin$config, _plugin$config2;
|
|
69
|
+
let enableFeature = noop;
|
|
70
|
+
transformHooks.parser.tap(md => {
|
|
71
|
+
md.use(remarkableKatex);
|
|
72
|
+
md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, (render, ...args) => {
|
|
73
|
+
enableFeature();
|
|
74
|
+
return render(...args);
|
|
167
75
|
});
|
|
168
|
-
|
|
169
|
-
|
|
76
|
+
});
|
|
77
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
78
|
+
enableFeature = () => {
|
|
79
|
+
context.features[name$3] = true;
|
|
170
80
|
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
styles: (_plugin$config = plugin$1.config) == null ? void 0 : _plugin$config.styles,
|
|
84
|
+
scripts: (_plugin$config2 = plugin$1.config) == null ? void 0 : _plugin$config2.scripts
|
|
85
|
+
};
|
|
86
|
+
}
|
|
174
87
|
});
|
|
175
88
|
|
|
176
|
-
const name$
|
|
89
|
+
const name$2 = 'frontmatter';
|
|
177
90
|
var frontmatter = definePlugin({
|
|
178
|
-
name: name$
|
|
91
|
+
name: name$2,
|
|
179
92
|
transform(transformHooks) {
|
|
180
93
|
transformHooks.beforeParse.tap((md, context) => {
|
|
181
94
|
const {
|
|
@@ -223,20 +136,22 @@ function normalizeNumber(value) {
|
|
|
223
136
|
return +value;
|
|
224
137
|
}
|
|
225
138
|
|
|
226
|
-
const name = 'npmUrl';
|
|
139
|
+
const name$1 = 'npmUrl';
|
|
227
140
|
var npmUrl = definePlugin({
|
|
228
|
-
name,
|
|
141
|
+
name: name$1,
|
|
229
142
|
transform(transformHooks) {
|
|
230
143
|
transformHooks.afterParse.tap((_, context) => {
|
|
231
144
|
const {
|
|
232
145
|
frontmatter
|
|
233
146
|
} = context;
|
|
234
|
-
|
|
147
|
+
const markmap = frontmatter == null ? void 0 : frontmatter.markmap;
|
|
148
|
+
if (markmap) {
|
|
235
149
|
['extraJs', 'extraCss'].forEach(key => {
|
|
236
|
-
|
|
237
|
-
|
|
150
|
+
const value = markmap[key];
|
|
151
|
+
if (value) {
|
|
152
|
+
markmap[key] = value.map(path => {
|
|
238
153
|
if (path.startsWith('npm:')) {
|
|
239
|
-
return getFullUrl(path.slice(4));
|
|
154
|
+
return transformHooks.transformer.urlBuilder.getFullUrl(path.slice(4));
|
|
240
155
|
}
|
|
241
156
|
return path;
|
|
242
157
|
});
|
|
@@ -248,7 +163,61 @@ var npmUrl = definePlugin({
|
|
|
248
163
|
}
|
|
249
164
|
});
|
|
250
165
|
|
|
251
|
-
const
|
|
166
|
+
const name = 'hljs';
|
|
167
|
+
const styles = [`highlight.js@${"11.8.0"}/styles/default.css`].map(path => buildCSSItem(path));
|
|
168
|
+
const config = {
|
|
169
|
+
versions: {
|
|
170
|
+
hljs: "11.8.0"
|
|
171
|
+
},
|
|
172
|
+
styles
|
|
173
|
+
};
|
|
174
|
+
const plugin = definePlugin({
|
|
175
|
+
name,
|
|
176
|
+
config,
|
|
177
|
+
transform(transformHooks) {
|
|
178
|
+
var _plugin$config;
|
|
179
|
+
let enableFeature = noop;
|
|
180
|
+
transformHooks.parser.tap(md => {
|
|
181
|
+
md.set({
|
|
182
|
+
highlight: (str, language) => {
|
|
183
|
+
enableFeature();
|
|
184
|
+
return hljs.highlightAuto(str, language ? [language] : undefined).value;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
189
|
+
enableFeature = () => {
|
|
190
|
+
context.features[name] = true;
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
return {
|
|
194
|
+
styles: (_plugin$config = plugin.config) == null ? void 0 : _plugin$config.styles
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const plugins = [frontmatter, plugin$1, plugin, npmUrl];
|
|
200
|
+
|
|
201
|
+
function patchJSItem(transformer, item) {
|
|
202
|
+
if (item.type === 'script' && item.data.src) {
|
|
203
|
+
return _extends({}, item, {
|
|
204
|
+
data: _extends({}, item.data, {
|
|
205
|
+
src: transformer.urlBuilder.getFullUrl(item.data.src)
|
|
206
|
+
})
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return item;
|
|
210
|
+
}
|
|
211
|
+
function patchCSSItem(transformer, item) {
|
|
212
|
+
if (item.type === 'stylesheet' && item.data.href) {
|
|
213
|
+
return _extends({}, item, {
|
|
214
|
+
data: _extends({}, item.data, {
|
|
215
|
+
href: transformer.urlBuilder.getFullUrl(item.data.href)
|
|
216
|
+
})
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return item;
|
|
220
|
+
}
|
|
252
221
|
|
|
253
222
|
function cleanNode(node) {
|
|
254
223
|
if (node.type === 'heading') {
|
|
@@ -282,9 +251,7 @@ function cleanNode(node) {
|
|
|
282
251
|
}
|
|
283
252
|
});
|
|
284
253
|
}
|
|
285
|
-
if (node.children.length
|
|
286
|
-
delete node.children;
|
|
287
|
-
} else {
|
|
254
|
+
if (node.children.length > 0) {
|
|
288
255
|
node.children.forEach(child => cleanNode(child));
|
|
289
256
|
if (node.children.length === 1 && !node.children[0].content) {
|
|
290
257
|
node.children = node.children[0].children;
|
|
@@ -292,16 +259,16 @@ function cleanNode(node) {
|
|
|
292
259
|
}
|
|
293
260
|
}
|
|
294
261
|
function resetDepth(node, depth = 0) {
|
|
295
|
-
var _node$children;
|
|
296
262
|
node.depth = depth;
|
|
297
|
-
|
|
263
|
+
node.children.forEach(child => {
|
|
298
264
|
resetDepth(child, depth + 1);
|
|
299
265
|
});
|
|
300
266
|
}
|
|
301
267
|
class Transformer {
|
|
302
268
|
constructor(plugins$1 = plugins) {
|
|
303
269
|
this.assetsMap = {};
|
|
304
|
-
this.
|
|
270
|
+
this.urlBuilder = new UrlBuilder();
|
|
271
|
+
this.hooks = createTransformHooks(this);
|
|
305
272
|
this.plugins = plugins$1.map(plugin => typeof plugin === 'function' ? plugin() : plugin);
|
|
306
273
|
const assetsMap = {};
|
|
307
274
|
for (const {
|
|
@@ -341,13 +308,13 @@ class Transformer {
|
|
|
341
308
|
const stack = [root];
|
|
342
309
|
let depth = 0;
|
|
343
310
|
for (const token of tokens) {
|
|
311
|
+
const payload = {};
|
|
312
|
+
if (token.lines) {
|
|
313
|
+
payload.lines = token.lines;
|
|
314
|
+
}
|
|
344
315
|
let current = stack[stack.length - 1];
|
|
345
316
|
if (token.type.endsWith('_open')) {
|
|
346
317
|
const type = token.type.slice(0, -5);
|
|
347
|
-
const payload = {};
|
|
348
|
-
if (token.lines) {
|
|
349
|
-
payload.lines = token.lines;
|
|
350
|
-
}
|
|
351
318
|
if (type === 'heading') {
|
|
352
319
|
depth = token.hLevel;
|
|
353
320
|
while (((_current = current) == null ? void 0 : _current.depth) >= depth) {
|
|
@@ -382,10 +349,13 @@ class Transformer {
|
|
|
382
349
|
}
|
|
383
350
|
} else if (token.type === 'inline') {
|
|
384
351
|
const revoke = this.hooks.htmltag.tap(ctx => {
|
|
385
|
-
|
|
352
|
+
var _ctx$result;
|
|
353
|
+
const comment = (_ctx$result = ctx.result) == null ? void 0 : _ctx$result.match(/^<!--([\s\S]*?)-->$/);
|
|
386
354
|
const data = comment == null ? void 0 : comment[1].trim().split(' ');
|
|
387
|
-
if (data[0] === 'fold') {
|
|
388
|
-
current.payload
|
|
355
|
+
if ((data == null ? void 0 : data[0]) === 'fold') {
|
|
356
|
+
current.payload = _extends({}, current.payload, {
|
|
357
|
+
fold: ['all', 'recursively'].includes(data[1]) ? 2 : 1
|
|
358
|
+
});
|
|
389
359
|
ctx.result = '';
|
|
390
360
|
}
|
|
391
361
|
});
|
|
@@ -393,15 +363,13 @@ class Transformer {
|
|
|
393
363
|
revoke();
|
|
394
364
|
current.content = `${current.content || ''}${text}`;
|
|
395
365
|
} else if (token.type === 'fence') {
|
|
396
|
-
|
|
397
|
-
// Remarkable only adds className to `<code>` but not `<pre>`, copy it to make PrismJS style work.
|
|
398
|
-
const matches = result.match(/<code( class="[^"]*")>/);
|
|
399
|
-
if (matches) result = result.replace('<pre>', `<pre${matches[1]}>`);
|
|
366
|
+
const result = md.renderer.render([token], md.options, {});
|
|
400
367
|
current.children.push({
|
|
401
368
|
type: token.type,
|
|
402
369
|
depth: depth + 1,
|
|
403
370
|
content: result,
|
|
404
|
-
children: []
|
|
371
|
+
children: [],
|
|
372
|
+
payload
|
|
405
373
|
});
|
|
406
374
|
} else ;
|
|
407
375
|
}
|
|
@@ -441,8 +409,8 @@ class Transformer {
|
|
|
441
409
|
}
|
|
442
410
|
}
|
|
443
411
|
return {
|
|
444
|
-
styles,
|
|
445
|
-
scripts
|
|
412
|
+
styles: styles.map(item => patchCSSItem(this, item)),
|
|
413
|
+
scripts: scripts.map(item => patchJSItem(this, item))
|
|
446
414
|
};
|
|
447
415
|
}
|
|
448
416
|
|
|
@@ -453,11 +421,46 @@ class Transformer {
|
|
|
453
421
|
const keys = this.plugins.map(plugin => plugin.name).filter(name => features[name]);
|
|
454
422
|
return this.getAssets(keys);
|
|
455
423
|
}
|
|
424
|
+
fillTemplate(root, assets, extra) {
|
|
425
|
+
var _extra, _extra$baseJs;
|
|
426
|
+
extra = _extends({}, extra);
|
|
427
|
+
(_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => this.urlBuilder.getFullUrl(path)).map(path => buildJSItem(path));
|
|
428
|
+
const {
|
|
429
|
+
scripts,
|
|
430
|
+
styles
|
|
431
|
+
} = assets;
|
|
432
|
+
const cssList = [...(styles ? persistCSS(styles) : [])];
|
|
433
|
+
const context = {
|
|
434
|
+
getMarkmap: () => window.markmap,
|
|
435
|
+
getOptions: extra.getOptions,
|
|
436
|
+
jsonOptions: extra.jsonOptions,
|
|
437
|
+
root
|
|
438
|
+
};
|
|
439
|
+
const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
|
|
440
|
+
type: 'iife',
|
|
441
|
+
data: {
|
|
442
|
+
fn: (getMarkmap, getOptions, root, jsonOptions) => {
|
|
443
|
+
const markmap = getMarkmap();
|
|
444
|
+
window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root);
|
|
445
|
+
},
|
|
446
|
+
getParams: ({
|
|
447
|
+
getMarkmap,
|
|
448
|
+
getOptions,
|
|
449
|
+
root,
|
|
450
|
+
jsonOptions
|
|
451
|
+
}) => {
|
|
452
|
+
return [getMarkmap, getOptions, root, jsonOptions];
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}], context)];
|
|
456
|
+
const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
|
|
457
|
+
return html;
|
|
458
|
+
}
|
|
456
459
|
}
|
|
457
460
|
|
|
458
461
|
const transformerVersions = {
|
|
459
|
-
'markmap-lib': '0.15.0
|
|
460
|
-
d3: "
|
|
462
|
+
'markmap-lib': '0.15.0',
|
|
463
|
+
d3: "7.8.5"
|
|
461
464
|
};
|
|
462
465
|
|
|
463
|
-
export { Transformer, baseJsPaths, plugins as builtInPlugins,
|
|
466
|
+
export { Transformer, baseJsPaths, plugins as builtInPlugins, template, transformerVersions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-lib",
|
|
3
|
-
"version": "0.15.0
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Visualize your Markdown as mindmaps with Markmap",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"dev": "rollup -wc rollup.conf.js",
|
|
9
9
|
"clean": "del-cli dist types",
|
|
10
10
|
"build:types": "tsc",
|
|
11
|
-
"build:js": "rollup -c
|
|
11
|
+
"build:js": "rollup -c",
|
|
12
|
+
"test": "jest test"
|
|
12
13
|
},
|
|
13
14
|
"publishConfig": {
|
|
14
15
|
"access": "public",
|
|
@@ -47,20 +48,31 @@
|
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/remarkable": "^2.0.3",
|
|
50
|
-
"markmap-common": "0.15.0
|
|
51
|
-
"markmap-view": "0.15.0
|
|
51
|
+
"markmap-common": "0.15.0",
|
|
52
|
+
"markmap-view": "0.15.0",
|
|
52
53
|
"webfontloader": "^1.6.28"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@babel/runtime": "^7.
|
|
56
|
+
"@babel/runtime": "^7.22.6",
|
|
57
|
+
"highlight.js": "^11.8.0",
|
|
56
58
|
"js-yaml": "^4.1.0",
|
|
57
|
-
"katex": "^0.16.
|
|
58
|
-
"prismjs": "^1.
|
|
59
|
+
"katex": "^0.16.8",
|
|
60
|
+
"prismjs": "^1.29.0",
|
|
59
61
|
"remarkable": "^2.0.1",
|
|
60
62
|
"remarkable-katex": "^1.2.1"
|
|
61
63
|
},
|
|
62
64
|
"peerDependencies": {
|
|
63
65
|
"markmap-common": "*"
|
|
64
66
|
},
|
|
65
|
-
"
|
|
67
|
+
"jest": {
|
|
68
|
+
"transform": {
|
|
69
|
+
"\\.ts$": [
|
|
70
|
+
"babel-jest",
|
|
71
|
+
{
|
|
72
|
+
"rootMode": "upward"
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"gitHead": "9c13bae5e28346ec613362046a023839ef64538b"
|
|
66
78
|
}
|
package/types/index.d.ts
CHANGED
package/types/plugins/base.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ITransformHooks, ITransformPlugin } from '../types';
|
|
2
|
-
export declare function createTransformHooks(): ITransformHooks;
|
|
1
|
+
import { ITransformer, ITransformHooks, ITransformPlugin } from '../types';
|
|
2
|
+
export declare function createTransformHooks(transformer: ITransformer): ITransformHooks;
|
|
3
3
|
/**
|
|
4
4
|
* This function is only used to help type checking.
|
|
5
5
|
*/
|
|
6
|
-
export declare function definePlugin(plugin: ITransformPlugin
|
|
6
|
+
export declare function definePlugin(plugin: ITransformPlugin): ITransformPlugin;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../types").ITransformPlugin
|
|
1
|
+
declare const _default: import("../types").ITransformPlugin;
|
|
2
2
|
export default _default;
|
package/types/plugins/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './base';
|
|
2
|
-
export declare const plugins:
|
|
2
|
+
export declare const plugins: import("..").ITransformPlugin[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const plugin: import("../types").ITransformPlugin;
|
|
2
|
+
export default plugin;
|
package/types/plugins/katex.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const plugin: import("../types").ITransformPlugin;
|
|
2
|
+
export default plugin;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("../types").ITransformPlugin
|
|
1
|
+
declare const _default: import("../types").ITransformPlugin;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const plugin: import("../types").ITransformPlugin;
|
|
2
|
+
export default plugin;
|
package/types/plugins/prism.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const plugin: import("../types").ITransformPlugin;
|
|
2
|
+
export default plugin;
|
package/types/plugins/util.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { CSSItem, JSItem } from 'markmap-common';
|
|
2
|
+
import { ITransformer } from '../types';
|
|
1
3
|
/**
|
|
2
4
|
* Find NPM paths and resolve them to full URLs with the same package version as in this library.
|
|
3
5
|
*/
|
|
4
6
|
export declare function addDefaultVersions(paths: string[], name: string, version: string): string[];
|
|
7
|
+
export declare function patchJSItem(transformer: ITransformer, item: JSItem): JSItem;
|
|
8
|
+
export declare function patchCSSItem(transformer: ITransformer, item: CSSItem): CSSItem;
|
package/types/transform.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Remarkable } from 'remarkable';
|
|
2
|
-
import {
|
|
3
|
-
import { ITransformResult, ITransformPlugin, IAssets, ITransformHooks, IFeatures } from './types';
|
|
2
|
+
import { UrlBuilder, JSItem, IMarkmapOptions, IMarkmapJSONOptions, IPureNode } from 'markmap-common';
|
|
3
|
+
import { ITransformResult, ITransformPlugin, IAssets, ITransformHooks, IFeatures, ITransformer } from './types';
|
|
4
4
|
import { plugins as builtInPlugins } from './plugins';
|
|
5
5
|
export { builtInPlugins };
|
|
6
|
-
export declare class Transformer {
|
|
6
|
+
export declare class Transformer implements ITransformer {
|
|
7
7
|
hooks: ITransformHooks;
|
|
8
8
|
md: Remarkable;
|
|
9
9
|
assetsMap: Record<string, IAssets>;
|
|
10
|
+
urlBuilder: UrlBuilder;
|
|
10
11
|
plugins: ITransformPlugin[];
|
|
11
12
|
constructor(plugins?: Array<ITransformPlugin | (() => ITransformPlugin)>);
|
|
12
|
-
buildTree(tokens: Remarkable.Token[]):
|
|
13
|
+
buildTree(tokens: Remarkable.Token[]): IPureNode;
|
|
13
14
|
transform(content: string): ITransformResult;
|
|
14
15
|
/**
|
|
15
16
|
* Get all assets from enabled plugins or filter them by plugin names as keys.
|
|
@@ -19,4 +20,9 @@ export declare class Transformer {
|
|
|
19
20
|
* Get used assets by features object returned by `transform`.
|
|
20
21
|
*/
|
|
21
22
|
getUsedAssets(features: IFeatures): IAssets;
|
|
23
|
+
fillTemplate(root: IPureNode | null, assets: IAssets, extra?: {
|
|
24
|
+
baseJs?: JSItem[];
|
|
25
|
+
jsonOptions?: IMarkmapJSONOptions;
|
|
26
|
+
getOptions?: (jsonOptions: IMarkmapJSONOptions) => Partial<IMarkmapOptions>;
|
|
27
|
+
}): string;
|
|
22
28
|
}
|