markmap-lib 0.13.3-alpha.1 → 0.13.4-alpha.1

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/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-lib v0.13.3-alpha.1+f7f5075 | MIT License */
1
+ /*! markmap-lib v0.13.4-alpha.1+51f8ed9 | MIT License */
2
2
  import _extends from '@babel/runtime/helpers/esm/extends';
3
3
  import { persistCSS, persistJS, wrapFunction, Hook } from 'markmap-common';
4
4
  import { Remarkable } from 'remarkable';
@@ -8,7 +8,7 @@ import loadLanguages from 'prismjs/components/';
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 BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.3-alpha.1+f7f5075"}`].map(src => ({
11
+ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.4-alpha.1+51f8ed9"}`].map(src => ({
12
12
  type: 'script',
13
13
  data: {
14
14
  src
@@ -50,6 +50,49 @@ function fillTemplate(root, assets, extra) {
50
50
  return html;
51
51
  }
52
52
 
53
+ var config$1 = {
54
+ preloadScripts: [{
55
+ type: 'script',
56
+ data: {
57
+ src: `https://cdn.jsdelivr.net/npm/katex@${"0.15.3"}/dist/katex.min.js`
58
+ }
59
+ }],
60
+ scripts: [{
61
+ type: 'iife',
62
+ data: {
63
+ fn: getMarkmap => {
64
+ window.WebFontConfig = {
65
+ custom: {
66
+ 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']
67
+ },
68
+ active: () => {
69
+ getMarkmap().refreshHook.call();
70
+ }
71
+ };
72
+ },
73
+
74
+ getParams({
75
+ getMarkmap
76
+ }) {
77
+ return [getMarkmap];
78
+ }
79
+
80
+ }
81
+ }, {
82
+ type: 'script',
83
+ data: {
84
+ src: `https://cdn.jsdelivr.net/npm/webfontloader@${"1.6.28"}/webfontloader.js`,
85
+ defer: true
86
+ }
87
+ }],
88
+ styles: [{
89
+ type: 'stylesheet',
90
+ data: {
91
+ href: `https://cdn.jsdelivr.net/npm/katex@${"0.15.3"}/dist/katex.min.css`
92
+ }
93
+ }]
94
+ };
95
+
53
96
  const name$2 = 'katex';
54
97
  function transform$2(transformHooks) {
55
98
  let enableFeature = () => {};
@@ -68,49 +111,38 @@ function transform$2(transformHooks) {
68
111
  };
69
112
  });
70
113
  return {
71
- styles: [{
72
- type: 'stylesheet',
73
- data: {
74
- href: 'https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css'
75
- }
76
- }],
77
- scripts: [{
78
- type: 'iife',
79
- data: {
80
- fn: getMarkmap => {
81
- window.WebFontConfig = {
82
- custom: {
83
- 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']
84
- },
85
- active: () => {
86
- getMarkmap().refreshHook.call();
87
- }
88
- };
89
- },
90
-
91
- getParams({
92
- getMarkmap
93
- }) {
94
- return [getMarkmap];
95
- }
96
-
97
- }
98
- }, {
99
- type: 'script',
100
- data: {
101
- src: 'https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.js',
102
- defer: true
103
- }
104
- }]
114
+ styles: config$1.styles,
115
+ scripts: config$1.scripts
105
116
  };
106
117
  }
107
118
 
108
119
  var katex = /*#__PURE__*/Object.freeze({
109
120
  __proto__: null,
121
+ config: config$1,
110
122
  name: name$2,
111
123
  transform: transform$2
112
124
  });
113
125
 
126
+ var config = {
127
+ preloadScripts: [{
128
+ type: 'script',
129
+ data: {
130
+ src: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/components/prism-core.min.js`
131
+ }
132
+ }, {
133
+ type: 'script',
134
+ data: {
135
+ src: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`
136
+ }
137
+ }],
138
+ styles: [{
139
+ type: 'stylesheet',
140
+ data: {
141
+ href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/themes/prism.css`
142
+ }
143
+ }]
144
+ };
145
+
114
146
  const name$1 = 'prism';
115
147
  function transform$1(transformHooks) {
116
148
  let enableFeature = () => {};
@@ -140,17 +172,13 @@ function transform$1(transformHooks) {
140
172
  };
141
173
  });
142
174
  return {
143
- styles: [{
144
- type: 'stylesheet',
145
- data: {
146
- href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.25.0"}/themes/prism.css`
147
- }
148
- }]
175
+ styles: config.styles
149
176
  };
150
177
  }
151
178
 
152
179
  var prism = /*#__PURE__*/Object.freeze({
153
180
  __proto__: null,
181
+ config: config,
154
182
  name: name$1,
155
183
  transform: transform$1
156
184
  });
@@ -203,7 +231,7 @@ function createTransformHooks() {
203
231
 
204
232
  const plugins = [katex, prism, frontmatter];
205
233
 
206
- function cleanNode(node, depth = 0) {
234
+ function cleanNode(node) {
207
235
  if (node.type === 'heading') {
208
236
  // drop all paragraphs
209
237
  node.children = node.children.filter(item => item.type !== 'paragraph');
@@ -244,14 +272,21 @@ function cleanNode(node, depth = 0) {
244
272
  if (node.children.length === 0) {
245
273
  delete node.children;
246
274
  } else {
247
- node.children.forEach(child => cleanNode(child, depth + 1));
275
+ node.children.forEach(child => cleanNode(child));
248
276
 
249
277
  if (node.children.length === 1 && !node.children[0].content) {
250
278
  node.children = node.children[0].children;
251
279
  }
252
280
  }
281
+ }
282
+
283
+ function resetDepth(node, depth = 0) {
284
+ var _node$children;
253
285
 
254
286
  node.depth = depth;
287
+ (_node$children = node.children) == null ? void 0 : _node$children.forEach(child => {
288
+ resetDepth(child, depth + 1);
289
+ });
255
290
  }
256
291
 
257
292
  class Transformer {
@@ -347,10 +382,10 @@ class Transformer {
347
382
  } else if (token.type === 'inline') {
348
383
  const revoke = this.hooks.htmltag.tap(ctx => {
349
384
  const comment = ctx.result.match(/^<!--([\s\S]*?)-->$/);
350
- const data = comment == null ? void 0 : comment[1].trim();
385
+ const data = comment == null ? void 0 : comment[1].trim().split(' ');
351
386
 
352
- if (data === 'fold') {
353
- current.payload.fold = true;
387
+ if (data[0] === 'fold') {
388
+ current.payload.fold = ['all', 'recursively'].includes(data[1]) ? 2 : 1;
354
389
  ctx.result = '';
355
390
  }
356
391
  });
@@ -385,6 +420,7 @@ class Transformer {
385
420
  let root = this.buildTree(tokens);
386
421
  cleanNode(root);
387
422
  if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
423
+ resetDepth(root);
388
424
  return _extends({}, context, {
389
425
  root
390
426
  });
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-lib v0.13.3-alpha.1+f7f5075 | MIT License */
1
+ /*! markmap-lib v0.13.4-alpha.1+51f8ed9 | MIT License */
2
2
  'use strict';
3
3
 
4
4
  var _extends = require('@babel/runtime/helpers/extends');
@@ -18,7 +18,7 @@ var loadLanguages__default = /*#__PURE__*/_interopDefaultLegacy(loadLanguages);
18
18
  var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
19
19
 
20
20
  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.3-alpha.1+f7f5075"}`].map(src => ({
21
+ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.4-alpha.1+51f8ed9"}`].map(src => ({
22
22
  type: 'script',
23
23
  data: {
24
24
  src
@@ -60,6 +60,49 @@ function fillTemplate(root, assets, extra) {
60
60
  return html;
61
61
  }
62
62
 
63
+ var config$1 = {
64
+ preloadScripts: [{
65
+ type: 'script',
66
+ data: {
67
+ src: `https://cdn.jsdelivr.net/npm/katex@${"0.15.3"}/dist/katex.min.js`
68
+ }
69
+ }],
70
+ scripts: [{
71
+ type: 'iife',
72
+ data: {
73
+ fn: getMarkmap => {
74
+ window.WebFontConfig = {
75
+ custom: {
76
+ 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']
77
+ },
78
+ active: () => {
79
+ getMarkmap().refreshHook.call();
80
+ }
81
+ };
82
+ },
83
+
84
+ getParams({
85
+ getMarkmap
86
+ }) {
87
+ return [getMarkmap];
88
+ }
89
+
90
+ }
91
+ }, {
92
+ type: 'script',
93
+ data: {
94
+ src: `https://cdn.jsdelivr.net/npm/webfontloader@${"1.6.28"}/webfontloader.js`,
95
+ defer: true
96
+ }
97
+ }],
98
+ styles: [{
99
+ type: 'stylesheet',
100
+ data: {
101
+ href: `https://cdn.jsdelivr.net/npm/katex@${"0.15.3"}/dist/katex.min.css`
102
+ }
103
+ }]
104
+ };
105
+
63
106
  const name$2 = 'katex';
64
107
  function transform$2(transformHooks) {
65
108
  let enableFeature = () => {};
@@ -78,49 +121,38 @@ function transform$2(transformHooks) {
78
121
  };
79
122
  });
80
123
  return {
81
- styles: [{
82
- type: 'stylesheet',
83
- data: {
84
- href: 'https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css'
85
- }
86
- }],
87
- scripts: [{
88
- type: 'iife',
89
- data: {
90
- fn: getMarkmap => {
91
- window.WebFontConfig = {
92
- custom: {
93
- 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']
94
- },
95
- active: () => {
96
- getMarkmap().refreshHook.call();
97
- }
98
- };
99
- },
100
-
101
- getParams({
102
- getMarkmap
103
- }) {
104
- return [getMarkmap];
105
- }
106
-
107
- }
108
- }, {
109
- type: 'script',
110
- data: {
111
- src: 'https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.js',
112
- defer: true
113
- }
114
- }]
124
+ styles: config$1.styles,
125
+ scripts: config$1.scripts
115
126
  };
116
127
  }
117
128
 
118
129
  var katex = /*#__PURE__*/Object.freeze({
119
130
  __proto__: null,
131
+ config: config$1,
120
132
  name: name$2,
121
133
  transform: transform$2
122
134
  });
123
135
 
136
+ var config = {
137
+ preloadScripts: [{
138
+ type: 'script',
139
+ data: {
140
+ src: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/components/prism-core.min.js`
141
+ }
142
+ }, {
143
+ type: 'script',
144
+ data: {
145
+ src: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`
146
+ }
147
+ }],
148
+ styles: [{
149
+ type: 'stylesheet',
150
+ data: {
151
+ href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/themes/prism.css`
152
+ }
153
+ }]
154
+ };
155
+
124
156
  const name$1 = 'prism';
125
157
  function transform$1(transformHooks) {
126
158
  let enableFeature = () => {};
@@ -150,17 +182,13 @@ function transform$1(transformHooks) {
150
182
  };
151
183
  });
152
184
  return {
153
- styles: [{
154
- type: 'stylesheet',
155
- data: {
156
- href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.25.0"}/themes/prism.css`
157
- }
158
- }]
185
+ styles: config.styles
159
186
  };
160
187
  }
161
188
 
162
189
  var prism = /*#__PURE__*/Object.freeze({
163
190
  __proto__: null,
191
+ config: config,
164
192
  name: name$1,
165
193
  transform: transform$1
166
194
  });
@@ -213,7 +241,7 @@ function createTransformHooks() {
213
241
 
214
242
  const plugins = [katex, prism, frontmatter];
215
243
 
216
- function cleanNode(node, depth = 0) {
244
+ function cleanNode(node) {
217
245
  if (node.type === 'heading') {
218
246
  // drop all paragraphs
219
247
  node.children = node.children.filter(item => item.type !== 'paragraph');
@@ -254,14 +282,21 @@ function cleanNode(node, depth = 0) {
254
282
  if (node.children.length === 0) {
255
283
  delete node.children;
256
284
  } else {
257
- node.children.forEach(child => cleanNode(child, depth + 1));
285
+ node.children.forEach(child => cleanNode(child));
258
286
 
259
287
  if (node.children.length === 1 && !node.children[0].content) {
260
288
  node.children = node.children[0].children;
261
289
  }
262
290
  }
291
+ }
292
+
293
+ function resetDepth(node, depth = 0) {
294
+ var _node$children;
263
295
 
264
296
  node.depth = depth;
297
+ (_node$children = node.children) == null ? void 0 : _node$children.forEach(child => {
298
+ resetDepth(child, depth + 1);
299
+ });
265
300
  }
266
301
 
267
302
  class Transformer {
@@ -357,10 +392,10 @@ class Transformer {
357
392
  } else if (token.type === 'inline') {
358
393
  const revoke = this.hooks.htmltag.tap(ctx => {
359
394
  const comment = ctx.result.match(/^<!--([\s\S]*?)-->$/);
360
- const data = comment == null ? void 0 : comment[1].trim();
395
+ const data = comment == null ? void 0 : comment[1].trim().split(' ');
361
396
 
362
- if (data === 'fold') {
363
- current.payload.fold = true;
397
+ if (data[0] === 'fold') {
398
+ current.payload.fold = ['all', 'recursively'].includes(data[1]) ? 2 : 1;
364
399
  ctx.result = '';
365
400
  }
366
401
  });
@@ -395,6 +430,7 @@ class Transformer {
395
430
  let root = this.buildTree(tokens);
396
431
  cleanNode(root);
397
432
  if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
433
+ resetDepth(root);
398
434
  return _extends__default({}, context, {
399
435
  root
400
436
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-lib",
3
- "version": "0.13.3-alpha.1+f7f5075",
3
+ "version": "0.13.4-alpha.1+51f8ed9",
4
4
  "description": "Visualize your Markdown as mindmaps with Markmap",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -35,16 +35,17 @@
35
35
  "repository": "git@github.com:gera2ld/markmap.git",
36
36
  "devDependencies": {
37
37
  "@types/remarkable": "^2.0.3",
38
- "markmap-view": "^0.13.3-alpha.1+f7f5075"
38
+ "markmap-view": "^0.13.4-alpha.1+51f8ed9",
39
+ "webfontloader": "^1.6.28"
39
40
  },
40
41
  "dependencies": {
41
42
  "@babel/runtime": "^7.16.3",
42
43
  "js-yaml": "^4.1.0",
43
44
  "katex": "^0.15.1",
44
- "markmap-common": "^0.13.3-alpha.1+f7f5075",
45
+ "markmap-common": "^0.13.4-alpha.1+51f8ed9",
45
46
  "prismjs": "^1.25.0",
46
47
  "remarkable": "^2.0.1",
47
48
  "remarkable-katex": "^1.1.8"
48
49
  },
49
- "gitHead": "f7f507547a2e1b2b1637e532a1c67d6ad0eabaf9"
50
+ "gitHead": "51f8ed9512078ad6bd49932bd46c7c5646dbc7d8"
50
51
  }
@@ -1,3 +1,5 @@
1
1
  import { IAssets, ITransformHooks } from '../types';
2
+ import config from './katex.config';
3
+ export { config };
2
4
  export declare const name = "katex";
3
5
  export declare function transform(transformHooks: ITransformHooks): IAssets;
@@ -0,0 +1,7 @@
1
+ import { CSSItem, JSItem } from 'markmap-common';
2
+ declare const _default: {
3
+ preloadScripts: JSItem[];
4
+ scripts: JSItem[];
5
+ styles: CSSItem[];
6
+ };
7
+ export default _default;
@@ -1,3 +1,5 @@
1
1
  import { IAssets, ITransformHooks } from '../types';
2
+ import config from './katex.config';
3
+ export { config };
2
4
  export declare const name = "katex";
3
5
  export declare function transform(transformHooks: ITransformHooks): IAssets;
@@ -1,3 +1,5 @@
1
1
  import { IAssets, ITransformHooks } from '../types';
2
+ import config from './prism.config';
3
+ export { config };
2
4
  export declare const name = "prism";
3
5
  export declare function transform(transformHooks: ITransformHooks): IAssets;
@@ -0,0 +1,6 @@
1
+ import { CSSItem, JSItem } from 'markmap-common';
2
+ declare const _default: {
3
+ preloadScripts: JSItem[];
4
+ styles: CSSItem[];
5
+ };
6
+ export default _default;
@@ -1,3 +1,5 @@
1
1
  import { IAssets, ITransformHooks } from '../types';
2
+ import config from './prism.config';
3
+ export { config };
2
4
  export declare const name = "prism";
3
5
  export declare function transform(transformHooks: ITransformHooks): IAssets;