markmap-lib 0.14.4-alpha.1 → 0.14.5-alpha.13
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/README.md +1 -3
- package/dist/browser/index.js +1735 -3601
- package/dist/browser/index.mjs +11134 -0
- package/dist/index.js +175 -234
- package/dist/{index.esm.js → index.mjs} +173 -225
- package/package.json +19 -15
- package/types/plugins/base.d.ts +1 -1
- package/types/plugins/frontmatter.d.ts +1 -1
- package/types/plugins/index.d.ts +1 -1
- package/types/plugins/katex.browser.d.ts +1 -1
- package/types/plugins/katex.config.d.ts +4 -5
- package/types/plugins/katex.d.ts +1 -1
- package/types/plugins/npm-url.d.ts +2 -0
- package/types/plugins/prism.browser.d.ts +1 -1
- package/types/plugins/prism.config.d.ts +3 -5
- package/types/plugins/prism.d.ts +1 -1
- package/types/plugins/util.d.ts +1 -1
- package/types/template.d.ts +1 -0
- package/types/transform.d.ts +2 -2
- package/types/types.d.ts +5 -2
- package/dist/browser/index.min.js +0 -4
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
/*! markmap-lib v0.14.
|
|
1
|
+
/*! markmap-lib v0.14.5-alpha.13+50ca560 | MIT License */
|
|
2
2
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
3
|
-
import { persistCSS, persistJS, Hook, wrapFunction } from 'markmap-common';
|
|
3
|
+
import { buildJSItem, persistCSS, persistJS, buildCSSItem, Hook, wrapFunction, noop, getFullUrl } from 'markmap-common';
|
|
4
4
|
import { Remarkable } from 'remarkable';
|
|
5
5
|
import remarkableKatex from 'remarkable-katex';
|
|
6
6
|
import Prism from 'prismjs';
|
|
7
|
-
import loadLanguages from 'prismjs/components/';
|
|
7
|
+
import loadLanguages from 'prismjs/components/index.js';
|
|
8
8
|
import yaml from 'js-yaml';
|
|
9
9
|
|
|
10
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
|
|
12
|
-
type: 'script',
|
|
13
|
-
data: {
|
|
14
|
-
src
|
|
15
|
-
}
|
|
16
|
-
}));
|
|
11
|
+
const baseJsPaths = [`d3@${"6.2.0"}`, `markmap-view@${"0.14.5-alpha.13+50ca560"}`];
|
|
17
12
|
function fillTemplate(root, assets, extra) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
var _extra, _extra$baseJs;
|
|
14
|
+
extra = _extends({}, extra);
|
|
15
|
+
(_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(buildJSItem);
|
|
21
16
|
const {
|
|
22
17
|
scripts,
|
|
23
18
|
styles
|
|
@@ -50,52 +45,40 @@ function fillTemplate(root, assets, extra) {
|
|
|
50
45
|
return html;
|
|
51
46
|
}
|
|
52
47
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
}
|
|
82
77
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
data: {
|
|
88
|
-
src: `https://cdn.jsdelivr.net/npm/webfontloader@${"1.6.28"}/webfontloader.js`,
|
|
89
|
-
defer: true
|
|
90
|
-
}
|
|
91
|
-
}],
|
|
92
|
-
styles: [{
|
|
93
|
-
type: 'stylesheet',
|
|
94
|
-
data: {
|
|
95
|
-
href: `https://cdn.jsdelivr.net/npm/katex@${"0.16.0"}/dist/katex.min.css`
|
|
96
|
-
}
|
|
97
|
-
}]
|
|
98
|
-
};
|
|
78
|
+
}, webfontloader],
|
|
79
|
+
styles
|
|
80
|
+
};
|
|
81
|
+
}
|
|
99
82
|
|
|
100
83
|
function createTransformHooks() {
|
|
101
84
|
return {
|
|
@@ -106,149 +89,119 @@ function createTransformHooks() {
|
|
|
106
89
|
retransform: new Hook()
|
|
107
90
|
};
|
|
108
91
|
}
|
|
92
|
+
|
|
109
93
|
/**
|
|
110
94
|
* This function is only used to help type checking.
|
|
111
95
|
*/
|
|
112
|
-
|
|
113
96
|
function definePlugin(plugin) {
|
|
114
97
|
return plugin;
|
|
115
98
|
}
|
|
116
99
|
|
|
117
|
-
const name$
|
|
118
|
-
var katex = definePlugin({
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, {
|
|
128
|
-
after: () => {
|
|
100
|
+
const name$3 = 'katex';
|
|
101
|
+
var katex = definePlugin(() => {
|
|
102
|
+
const plugin = {
|
|
103
|
+
name: name$3,
|
|
104
|
+
config: getConfig$1(),
|
|
105
|
+
transform(transformHooks) {
|
|
106
|
+
let enableFeature = noop;
|
|
107
|
+
transformHooks.parser.tap(md => {
|
|
108
|
+
md.use(remarkableKatex);
|
|
109
|
+
md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, (render, ...args) => {
|
|
129
110
|
enableFeature();
|
|
130
|
-
|
|
111
|
+
return render(...args);
|
|
112
|
+
});
|
|
131
113
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
|
136
122
|
};
|
|
137
|
-
});
|
|
138
|
-
return {
|
|
139
|
-
styles: config$1.styles,
|
|
140
|
-
scripts: config$1.scripts
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
var config = {
|
|
147
|
-
versions: {
|
|
148
|
-
prismjs: "1.28.0"
|
|
149
|
-
},
|
|
150
|
-
preloadScripts: [{
|
|
151
|
-
type: 'script',
|
|
152
|
-
data: {
|
|
153
|
-
src: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/components/prism-core.min.js`
|
|
154
|
-
}
|
|
155
|
-
}, {
|
|
156
|
-
type: 'script',
|
|
157
|
-
data: {
|
|
158
|
-
src: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`
|
|
159
|
-
}
|
|
160
|
-
}],
|
|
161
|
-
styles: [{
|
|
162
|
-
type: 'stylesheet',
|
|
163
|
-
data: {
|
|
164
|
-
href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/themes/prism.css`
|
|
165
123
|
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const name$1 = 'prism';
|
|
170
|
-
var prism = definePlugin({
|
|
171
|
-
name: name$1,
|
|
172
|
-
config,
|
|
173
|
-
|
|
174
|
-
transform(transformHooks) {
|
|
175
|
-
let enableFeature = () => {};
|
|
176
|
-
|
|
177
|
-
transformHooks.parser.tap(md => {
|
|
178
|
-
md.set({
|
|
179
|
-
highlight: (str, lang) => {
|
|
180
|
-
enableFeature();
|
|
181
|
-
let grammar = Prism.languages[lang];
|
|
124
|
+
};
|
|
125
|
+
return plugin;
|
|
126
|
+
});
|
|
182
127
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
+
}
|
|
187
139
|
|
|
188
|
-
|
|
189
|
-
|
|
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 '';
|
|
190
160
|
}
|
|
191
|
-
|
|
192
|
-
return '';
|
|
193
|
-
}
|
|
161
|
+
});
|
|
194
162
|
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
163
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
164
|
+
enableFeature = () => {
|
|
165
|
+
context.features[name$2] = true;
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
return {
|
|
169
|
+
styles: plugin.config.styles
|
|
199
170
|
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return plugin;
|
|
206
174
|
});
|
|
207
175
|
|
|
208
|
-
const name = 'frontmatter';
|
|
176
|
+
const name$1 = 'frontmatter';
|
|
209
177
|
var frontmatter = definePlugin({
|
|
210
|
-
name,
|
|
211
|
-
|
|
178
|
+
name: name$1,
|
|
212
179
|
transform(transformHooks) {
|
|
213
180
|
transformHooks.beforeParse.tap((md, context) => {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
frontmatter = yaml.load(raw);
|
|
228
|
-
|
|
229
|
-
if ((_frontmatter = frontmatter) != null && _frontmatter.markmap) {
|
|
230
|
-
frontmatter.markmap = normalizeMarkmapJsonOptions(frontmatter.markmap);
|
|
231
|
-
}
|
|
232
|
-
} catch (_unused) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
context.frontmatter = frontmatter;
|
|
237
|
-
const offset = endOffset + 5;
|
|
238
|
-
ctx.args[0] = content.slice(offset);
|
|
239
|
-
},
|
|
240
|
-
|
|
241
|
-
after() {
|
|
242
|
-
md.parse = origParse;
|
|
181
|
+
const {
|
|
182
|
+
content
|
|
183
|
+
} = context;
|
|
184
|
+
if (!content.startsWith('---\n')) return;
|
|
185
|
+
const endOffset = content.indexOf('\n---\n');
|
|
186
|
+
if (endOffset < 0) return;
|
|
187
|
+
const raw = content.slice(4, endOffset);
|
|
188
|
+
let frontmatter;
|
|
189
|
+
try {
|
|
190
|
+
var _frontmatter;
|
|
191
|
+
frontmatter = yaml.load(raw);
|
|
192
|
+
if ((_frontmatter = frontmatter) != null && _frontmatter.markmap) {
|
|
193
|
+
frontmatter.markmap = normalizeMarkmapJsonOptions(frontmatter.markmap);
|
|
243
194
|
}
|
|
244
|
-
|
|
245
|
-
|
|
195
|
+
} catch (_unused) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
context.frontmatter = frontmatter;
|
|
199
|
+
context.content = content.slice(endOffset + 5);
|
|
200
|
+
context.contentLineOffset = content.slice(0, endOffset).split('\n').length + 1;
|
|
246
201
|
});
|
|
247
202
|
return {};
|
|
248
203
|
}
|
|
249
|
-
|
|
250
204
|
});
|
|
251
|
-
|
|
252
205
|
function normalizeMarkmapJsonOptions(options) {
|
|
253
206
|
if (!options) return;
|
|
254
207
|
['color', 'extraJs', 'extraCss'].forEach(key => {
|
|
@@ -259,21 +212,43 @@ function normalizeMarkmapJsonOptions(options) {
|
|
|
259
212
|
});
|
|
260
213
|
return options;
|
|
261
214
|
}
|
|
262
|
-
|
|
263
215
|
function normalizeStringArray(value) {
|
|
264
216
|
var _result;
|
|
265
|
-
|
|
266
217
|
let result;
|
|
267
218
|
if (typeof value === 'string') result = [value];else if (Array.isArray(value)) result = value.filter(item => item && typeof item === 'string');
|
|
268
219
|
return (_result = result) != null && _result.length ? result : undefined;
|
|
269
220
|
}
|
|
270
|
-
|
|
271
221
|
function normalizeNumber(value) {
|
|
272
222
|
if (isNaN(+value)) return;
|
|
273
223
|
return +value;
|
|
274
224
|
}
|
|
275
225
|
|
|
276
|
-
const
|
|
226
|
+
const name = 'npmUrl';
|
|
227
|
+
var npmUrl = definePlugin({
|
|
228
|
+
name,
|
|
229
|
+
transform(transformHooks) {
|
|
230
|
+
transformHooks.afterParse.tap((_, context) => {
|
|
231
|
+
const {
|
|
232
|
+
frontmatter
|
|
233
|
+
} = context;
|
|
234
|
+
if (frontmatter != null && frontmatter.markmap) {
|
|
235
|
+
['extraJs', 'extraCss'].forEach(key => {
|
|
236
|
+
if (frontmatter.markmap[key]) {
|
|
237
|
+
frontmatter.markmap[key] = frontmatter.markmap[key].map(path => {
|
|
238
|
+
if (path.startsWith('npm:')) {
|
|
239
|
+
return getFullUrl(path.slice(4));
|
|
240
|
+
}
|
|
241
|
+
return path;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
return {};
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const plugins = [frontmatter, katex, prism, npmUrl];
|
|
277
252
|
|
|
278
253
|
function cleanNode(node) {
|
|
279
254
|
if (node.type === 'heading') {
|
|
@@ -281,7 +256,6 @@ function cleanNode(node) {
|
|
|
281
256
|
node.children = node.children.filter(item => item.type !== 'paragraph');
|
|
282
257
|
} else if (node.type === 'list_item') {
|
|
283
258
|
var _node$payload;
|
|
284
|
-
|
|
285
259
|
// keep first paragraph as content of list_item, drop others
|
|
286
260
|
node.children = node.children.filter(item => {
|
|
287
261
|
if (['paragraph', 'fence'].includes(item.type)) {
|
|
@@ -289,19 +263,15 @@ function cleanNode(node) {
|
|
|
289
263
|
node.content = item.content;
|
|
290
264
|
node.payload = _extends({}, node.payload, item.payload);
|
|
291
265
|
}
|
|
292
|
-
|
|
293
266
|
return false;
|
|
294
267
|
}
|
|
295
|
-
|
|
296
268
|
return true;
|
|
297
269
|
});
|
|
298
|
-
|
|
299
270
|
if (((_node$payload = node.payload) == null ? void 0 : _node$payload.index) != null) {
|
|
300
271
|
node.content = `${node.payload.index}. ${node.content}`;
|
|
301
272
|
}
|
|
302
273
|
} else if (node.type === 'ordered_list') {
|
|
303
274
|
var _node$payload$startIn, _node$payload2;
|
|
304
|
-
|
|
305
275
|
let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1;
|
|
306
276
|
node.children.forEach(item => {
|
|
307
277
|
if (item.type === 'list_item') {
|
|
@@ -312,56 +282,51 @@ function cleanNode(node) {
|
|
|
312
282
|
}
|
|
313
283
|
});
|
|
314
284
|
}
|
|
315
|
-
|
|
316
285
|
if (node.children.length === 0) {
|
|
317
286
|
delete node.children;
|
|
318
287
|
} else {
|
|
319
288
|
node.children.forEach(child => cleanNode(child));
|
|
320
|
-
|
|
321
289
|
if (node.children.length === 1 && !node.children[0].content) {
|
|
322
290
|
node.children = node.children[0].children;
|
|
323
291
|
}
|
|
324
292
|
}
|
|
325
293
|
}
|
|
326
|
-
|
|
327
294
|
function resetDepth(node, depth = 0) {
|
|
328
295
|
var _node$children;
|
|
329
|
-
|
|
330
296
|
node.depth = depth;
|
|
331
297
|
(_node$children = node.children) == null ? void 0 : _node$children.forEach(child => {
|
|
332
298
|
resetDepth(child, depth + 1);
|
|
333
299
|
});
|
|
334
300
|
}
|
|
335
|
-
|
|
336
301
|
class Transformer {
|
|
337
302
|
constructor(plugins$1 = plugins) {
|
|
338
303
|
this.assetsMap = {};
|
|
339
|
-
this.plugins = plugins$1;
|
|
340
304
|
this.hooks = createTransformHooks();
|
|
305
|
+
this.plugins = plugins$1.map(plugin => typeof plugin === 'function' ? plugin() : plugin);
|
|
341
306
|
const assetsMap = {};
|
|
342
|
-
|
|
343
307
|
for (const {
|
|
344
308
|
name,
|
|
345
309
|
transform
|
|
346
|
-
} of plugins
|
|
310
|
+
} of this.plugins) {
|
|
347
311
|
assetsMap[name] = transform(this.hooks);
|
|
348
312
|
}
|
|
349
|
-
|
|
350
313
|
this.assetsMap = assetsMap;
|
|
351
314
|
const md = new Remarkable('full', {
|
|
352
315
|
html: true,
|
|
353
316
|
breaks: true,
|
|
354
317
|
maxNesting: Infinity
|
|
355
318
|
});
|
|
356
|
-
md.renderer.rules.htmltag = wrapFunction(md.renderer.rules.htmltag, {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
319
|
+
md.renderer.rules.htmltag = wrapFunction(md.renderer.rules.htmltag, (render, ...args) => {
|
|
320
|
+
const result = render(...args);
|
|
321
|
+
this.hooks.htmltag.call({
|
|
322
|
+
args,
|
|
323
|
+
result
|
|
324
|
+
});
|
|
325
|
+
return result;
|
|
360
326
|
});
|
|
361
327
|
this.md = md;
|
|
362
328
|
this.hooks.parser.call(md);
|
|
363
329
|
}
|
|
364
|
-
|
|
365
330
|
buildTree(tokens) {
|
|
366
331
|
const {
|
|
367
332
|
md
|
|
@@ -375,37 +340,28 @@ class Transformer {
|
|
|
375
340
|
};
|
|
376
341
|
const stack = [root];
|
|
377
342
|
let depth = 0;
|
|
378
|
-
|
|
379
343
|
for (const token of tokens) {
|
|
380
344
|
let current = stack[stack.length - 1];
|
|
381
|
-
|
|
382
345
|
if (token.type.endsWith('_open')) {
|
|
383
346
|
const type = token.type.slice(0, -5);
|
|
384
347
|
const payload = {};
|
|
385
|
-
|
|
386
348
|
if (token.lines) {
|
|
387
349
|
payload.lines = token.lines;
|
|
388
350
|
}
|
|
389
|
-
|
|
390
351
|
if (type === 'heading') {
|
|
391
352
|
depth = token.hLevel;
|
|
392
|
-
|
|
393
353
|
while (((_current = current) == null ? void 0 : _current.depth) >= depth) {
|
|
394
354
|
var _current;
|
|
395
|
-
|
|
396
355
|
stack.pop();
|
|
397
356
|
current = stack[stack.length - 1];
|
|
398
357
|
}
|
|
399
358
|
} else {
|
|
400
359
|
var _current2;
|
|
401
|
-
|
|
402
360
|
depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.depth) || 0) + 1;
|
|
403
|
-
|
|
404
361
|
if (type === 'ordered_list') {
|
|
405
362
|
payload.startIndex = token.order;
|
|
406
363
|
}
|
|
407
364
|
}
|
|
408
|
-
|
|
409
365
|
const item = {
|
|
410
366
|
type,
|
|
411
367
|
depth,
|
|
@@ -428,7 +384,6 @@ class Transformer {
|
|
|
428
384
|
const revoke = this.hooks.htmltag.tap(ctx => {
|
|
429
385
|
const comment = ctx.result.match(/^<!--([\s\S]*?)-->$/);
|
|
430
386
|
const data = comment == null ? void 0 : comment[1].trim().split(' ');
|
|
431
|
-
|
|
432
387
|
if (data[0] === 'fold') {
|
|
433
388
|
current.payload.fold = ['all', 'recursively'].includes(data[1]) ? 2 : 1;
|
|
434
389
|
ctx.result = '';
|
|
@@ -438,8 +393,8 @@ class Transformer {
|
|
|
438
393
|
revoke();
|
|
439
394
|
current.content = `${current.content || ''}${text}`;
|
|
440
395
|
} else if (token.type === 'fence') {
|
|
441
|
-
let result = md.renderer.render([token], md.options, {});
|
|
442
|
-
|
|
396
|
+
let result = md.renderer.render([token], md.options, {});
|
|
397
|
+
// Remarkable only adds className to `<code>` but not `<pre>`, copy it to make PrismJS style work.
|
|
443
398
|
const matches = result.match(/<code( class="[^"]*")>/);
|
|
444
399
|
if (matches) result = result.replace('<pre>', `<pre${matches[1]}>`);
|
|
445
400
|
current.children.push({
|
|
@@ -450,18 +405,17 @@ class Transformer {
|
|
|
450
405
|
});
|
|
451
406
|
} else ;
|
|
452
407
|
}
|
|
453
|
-
|
|
454
408
|
return root;
|
|
455
409
|
}
|
|
456
|
-
|
|
457
410
|
transform(content) {
|
|
458
411
|
var _root$children;
|
|
459
|
-
|
|
460
412
|
const context = {
|
|
461
|
-
|
|
413
|
+
content,
|
|
414
|
+
features: {},
|
|
415
|
+
contentLineOffset: 0
|
|
462
416
|
};
|
|
463
417
|
this.hooks.beforeParse.call(this.md, context);
|
|
464
|
-
const tokens = this.md.parse(content, {});
|
|
418
|
+
const tokens = this.md.parse(context.content, {});
|
|
465
419
|
this.hooks.afterParse.call(this.md, context);
|
|
466
420
|
let root = this.buildTree(tokens);
|
|
467
421
|
cleanNode(root);
|
|
@@ -471,45 +425,39 @@ class Transformer {
|
|
|
471
425
|
root
|
|
472
426
|
});
|
|
473
427
|
}
|
|
428
|
+
|
|
474
429
|
/**
|
|
475
430
|
* Get all assets from enabled plugins or filter them by plugin names as keys.
|
|
476
431
|
*/
|
|
477
|
-
|
|
478
|
-
|
|
479
432
|
getAssets(keys) {
|
|
480
433
|
var _keys;
|
|
481
|
-
|
|
482
434
|
const styles = [];
|
|
483
435
|
const scripts = [];
|
|
484
436
|
(_keys = keys) != null ? _keys : keys = this.plugins.map(plugin => plugin.name);
|
|
485
|
-
|
|
486
437
|
for (const assets of keys.map(key => this.assetsMap[key])) {
|
|
487
438
|
if (assets) {
|
|
488
439
|
if (assets.styles) styles.push(...assets.styles);
|
|
489
440
|
if (assets.scripts) scripts.push(...assets.scripts);
|
|
490
441
|
}
|
|
491
442
|
}
|
|
492
|
-
|
|
493
443
|
return {
|
|
494
444
|
styles,
|
|
495
445
|
scripts
|
|
496
446
|
};
|
|
497
447
|
}
|
|
448
|
+
|
|
498
449
|
/**
|
|
499
450
|
* Get used assets by features object returned by `transform`.
|
|
500
451
|
*/
|
|
501
|
-
|
|
502
|
-
|
|
503
452
|
getUsedAssets(features) {
|
|
504
453
|
const keys = this.plugins.map(plugin => plugin.name).filter(name => features[name]);
|
|
505
454
|
return this.getAssets(keys);
|
|
506
455
|
}
|
|
507
|
-
|
|
508
456
|
}
|
|
509
457
|
|
|
510
458
|
const transformerVersions = {
|
|
511
|
-
'markmap-lib': '0.14.
|
|
512
|
-
d3: "6.
|
|
459
|
+
'markmap-lib': '0.14.5-alpha.13+50ca560',
|
|
460
|
+
d3: "6.2.0"
|
|
513
461
|
};
|
|
514
462
|
|
|
515
|
-
export { Transformer, plugins as builtInPlugins, fillTemplate, transformerVersions };
|
|
463
|
+
export { Transformer, baseJsPaths, plugins as builtInPlugins, fillTemplate, transformerVersions };
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-lib",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.5-alpha.13+50ca560",
|
|
4
4
|
"description": "Visualize your Markdown as mindmaps with Markmap",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"engines": {
|
|
8
|
-
"node": ">=10"
|
|
9
|
-
},
|
|
10
7
|
"scripts": {
|
|
11
8
|
"dev": "rollup -wc rollup.conf.js",
|
|
12
9
|
"clean": "del-cli dist types",
|
|
@@ -18,19 +15,19 @@
|
|
|
18
15
|
"registry": "https://registry.npmjs.org/"
|
|
19
16
|
},
|
|
20
17
|
"main": "dist/index.js",
|
|
21
|
-
"module": "dist/index.
|
|
22
|
-
"unpkg": "dist/browser/index.
|
|
23
|
-
"jsdelivr": "dist/browser/index.
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"unpkg": "dist/browser/index.js",
|
|
20
|
+
"jsdelivr": "dist/browser/index.js",
|
|
24
21
|
"exports": {
|
|
25
22
|
".": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
23
|
+
"types": "./types/index.d.ts",
|
|
24
|
+
"browser": "./dist/browser/index.mjs",
|
|
28
25
|
"require": "./dist/index.js",
|
|
29
|
-
"default": "./dist/index.
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
30
27
|
},
|
|
31
28
|
"./package.json": "./package.json"
|
|
32
29
|
},
|
|
33
|
-
"
|
|
30
|
+
"types": "types/index.d.ts",
|
|
34
31
|
"files": [
|
|
35
32
|
"dist",
|
|
36
33
|
"types"
|
|
@@ -40,11 +37,18 @@
|
|
|
40
37
|
"markmap",
|
|
41
38
|
"mindmap"
|
|
42
39
|
],
|
|
43
|
-
"
|
|
40
|
+
"homepage": "https://github.com/markmap/markmap/packages/markmap-lib#readme",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/markmap/markmap.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/markmap/markmap/issues"
|
|
47
|
+
},
|
|
44
48
|
"devDependencies": {
|
|
45
49
|
"@types/remarkable": "^2.0.3",
|
|
46
|
-
"markmap-common": "
|
|
47
|
-
"markmap-view": "
|
|
50
|
+
"markmap-common": "0.14.5-alpha.13+50ca560",
|
|
51
|
+
"markmap-view": "0.14.5-alpha.13+50ca560",
|
|
48
52
|
"webfontloader": "^1.6.28"
|
|
49
53
|
},
|
|
50
54
|
"dependencies": {
|
|
@@ -58,5 +62,5 @@
|
|
|
58
62
|
"peerDependencies": {
|
|
59
63
|
"markmap-common": "*"
|
|
60
64
|
},
|
|
61
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "50ca5603019498f93dba6485c96d0a5630b221e5"
|
|
62
66
|
}
|