markmap-lib 0.13.3-alpha.2 → 0.13.4

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.2+a5a159b | MIT License */
1
+ /*! markmap-lib v0.13.4 | 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.2+a5a159b"}`].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"}`].map(src => ({
12
12
  type: 'script',
13
13
  data: {
14
14
  src
@@ -50,7 +50,7 @@ function fillTemplate(root, assets, extra) {
50
50
  return html;
51
51
  }
52
52
 
53
- var options$1 = {
53
+ var config$1 = {
54
54
  preloadScripts: [{
55
55
  type: 'script',
56
56
  data: {
@@ -111,18 +111,19 @@ function transform$2(transformHooks) {
111
111
  };
112
112
  });
113
113
  return {
114
- styles: options$1.styles,
115
- scripts: options$1.scripts
114
+ styles: config$1.styles,
115
+ scripts: config$1.scripts
116
116
  };
117
117
  }
118
118
 
119
119
  var katex = /*#__PURE__*/Object.freeze({
120
120
  __proto__: null,
121
+ config: config$1,
121
122
  name: name$2,
122
123
  transform: transform$2
123
124
  });
124
125
 
125
- var options = {
126
+ var config = {
126
127
  preloadScripts: [{
127
128
  type: 'script',
128
129
  data: {
@@ -171,12 +172,13 @@ function transform$1(transformHooks) {
171
172
  };
172
173
  });
173
174
  return {
174
- styles: options.styles
175
+ styles: config.styles
175
176
  };
176
177
  }
177
178
 
178
179
  var prism = /*#__PURE__*/Object.freeze({
179
180
  __proto__: null,
181
+ config: config,
180
182
  name: name$1,
181
183
  transform: transform$1
182
184
  });
@@ -229,7 +231,7 @@ function createTransformHooks() {
229
231
 
230
232
  const plugins = [katex, prism, frontmatter];
231
233
 
232
- function cleanNode(node, depth = 0) {
234
+ function cleanNode(node) {
233
235
  if (node.type === 'heading') {
234
236
  // drop all paragraphs
235
237
  node.children = node.children.filter(item => item.type !== 'paragraph');
@@ -270,14 +272,21 @@ function cleanNode(node, depth = 0) {
270
272
  if (node.children.length === 0) {
271
273
  delete node.children;
272
274
  } else {
273
- node.children.forEach(child => cleanNode(child, depth + 1));
275
+ node.children.forEach(child => cleanNode(child));
274
276
 
275
277
  if (node.children.length === 1 && !node.children[0].content) {
276
278
  node.children = node.children[0].children;
277
279
  }
278
280
  }
281
+ }
282
+
283
+ function resetDepth(node, depth = 0) {
284
+ var _node$children;
279
285
 
280
286
  node.depth = depth;
287
+ (_node$children = node.children) == null ? void 0 : _node$children.forEach(child => {
288
+ resetDepth(child, depth + 1);
289
+ });
281
290
  }
282
291
 
283
292
  class Transformer {
@@ -373,10 +382,10 @@ class Transformer {
373
382
  } else if (token.type === 'inline') {
374
383
  const revoke = this.hooks.htmltag.tap(ctx => {
375
384
  const comment = ctx.result.match(/^<!--([\s\S]*?)-->$/);
376
- const data = comment == null ? void 0 : comment[1].trim();
385
+ const data = comment == null ? void 0 : comment[1].trim().split(' ');
377
386
 
378
- if (data === 'fold') {
379
- current.payload.fold = true;
387
+ if (data[0] === 'fold') {
388
+ current.payload.fold = ['all', 'recursively'].includes(data[1]) ? 2 : 1;
380
389
  ctx.result = '';
381
390
  }
382
391
  });
@@ -411,6 +420,7 @@ class Transformer {
411
420
  let root = this.buildTree(tokens);
412
421
  cleanNode(root);
413
422
  if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
423
+ resetDepth(root);
414
424
  return _extends({}, context, {
415
425
  root
416
426
  });
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-lib v0.13.3-alpha.2+a5a159b | MIT License */
1
+ /*! markmap-lib v0.13.4 | 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.2+a5a159b"}`].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"}`].map(src => ({
22
22
  type: 'script',
23
23
  data: {
24
24
  src
@@ -60,7 +60,7 @@ function fillTemplate(root, assets, extra) {
60
60
  return html;
61
61
  }
62
62
 
63
- var options$1 = {
63
+ var config$1 = {
64
64
  preloadScripts: [{
65
65
  type: 'script',
66
66
  data: {
@@ -121,18 +121,19 @@ function transform$2(transformHooks) {
121
121
  };
122
122
  });
123
123
  return {
124
- styles: options$1.styles,
125
- scripts: options$1.scripts
124
+ styles: config$1.styles,
125
+ scripts: config$1.scripts
126
126
  };
127
127
  }
128
128
 
129
129
  var katex = /*#__PURE__*/Object.freeze({
130
130
  __proto__: null,
131
+ config: config$1,
131
132
  name: name$2,
132
133
  transform: transform$2
133
134
  });
134
135
 
135
- var options = {
136
+ var config = {
136
137
  preloadScripts: [{
137
138
  type: 'script',
138
139
  data: {
@@ -181,12 +182,13 @@ function transform$1(transformHooks) {
181
182
  };
182
183
  });
183
184
  return {
184
- styles: options.styles
185
+ styles: config.styles
185
186
  };
186
187
  }
187
188
 
188
189
  var prism = /*#__PURE__*/Object.freeze({
189
190
  __proto__: null,
191
+ config: config,
190
192
  name: name$1,
191
193
  transform: transform$1
192
194
  });
@@ -239,7 +241,7 @@ function createTransformHooks() {
239
241
 
240
242
  const plugins = [katex, prism, frontmatter];
241
243
 
242
- function cleanNode(node, depth = 0) {
244
+ function cleanNode(node) {
243
245
  if (node.type === 'heading') {
244
246
  // drop all paragraphs
245
247
  node.children = node.children.filter(item => item.type !== 'paragraph');
@@ -280,14 +282,21 @@ function cleanNode(node, depth = 0) {
280
282
  if (node.children.length === 0) {
281
283
  delete node.children;
282
284
  } else {
283
- node.children.forEach(child => cleanNode(child, depth + 1));
285
+ node.children.forEach(child => cleanNode(child));
284
286
 
285
287
  if (node.children.length === 1 && !node.children[0].content) {
286
288
  node.children = node.children[0].children;
287
289
  }
288
290
  }
291
+ }
292
+
293
+ function resetDepth(node, depth = 0) {
294
+ var _node$children;
289
295
 
290
296
  node.depth = depth;
297
+ (_node$children = node.children) == null ? void 0 : _node$children.forEach(child => {
298
+ resetDepth(child, depth + 1);
299
+ });
291
300
  }
292
301
 
293
302
  class Transformer {
@@ -383,10 +392,10 @@ class Transformer {
383
392
  } else if (token.type === 'inline') {
384
393
  const revoke = this.hooks.htmltag.tap(ctx => {
385
394
  const comment = ctx.result.match(/^<!--([\s\S]*?)-->$/);
386
- const data = comment == null ? void 0 : comment[1].trim();
395
+ const data = comment == null ? void 0 : comment[1].trim().split(' ');
387
396
 
388
- if (data === 'fold') {
389
- current.payload.fold = true;
397
+ if (data[0] === 'fold') {
398
+ current.payload.fold = ['all', 'recursively'].includes(data[1]) ? 2 : 1;
390
399
  ctx.result = '';
391
400
  }
392
401
  });
@@ -421,6 +430,7 @@ class Transformer {
421
430
  let root = this.buildTree(tokens);
422
431
  cleanNode(root);
423
432
  if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
433
+ resetDepth(root);
424
434
  return _extends__default({}, context, {
425
435
  root
426
436
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-lib",
3
- "version": "0.13.3-alpha.2+a5a159b",
3
+ "version": "0.13.4",
4
4
  "description": "Visualize your Markdown as mindmaps with Markmap",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -35,17 +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.2+a5a159b",
38
+ "markmap-view": "^0.13.4",
39
39
  "webfontloader": "^1.6.28"
40
40
  },
41
41
  "dependencies": {
42
42
  "@babel/runtime": "^7.16.3",
43
43
  "js-yaml": "^4.1.0",
44
44
  "katex": "^0.15.1",
45
- "markmap-common": "^0.13.3-alpha.2+a5a159b",
45
+ "markmap-common": "^0.13.4",
46
46
  "prismjs": "^1.25.0",
47
47
  "remarkable": "^2.0.1",
48
48
  "remarkable-katex": "^1.1.8"
49
49
  },
50
- "gitHead": "a5a159bee156ba7c77cf952f6f0f3e450f8c12fa"
50
+ "gitHead": "e79b7c21735205fa02b96d48a564561c9c2ba09f"
51
51
  }
@@ -1,5 +1,5 @@
1
1
  import { IAssets, ITransformHooks } from '../types';
2
- import options from './katex.options';
3
- export { options };
2
+ import config from './katex.config';
3
+ export { config };
4
4
  export declare const name = "katex";
5
5
  export declare function transform(transformHooks: ITransformHooks): IAssets;
@@ -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,5 +1,5 @@
1
1
  import { IAssets, ITransformHooks } from '../types';
2
- import options from './prism.options';
3
- export { options };
2
+ import config from './prism.config';
3
+ export { config };
4
4
  export declare const name = "prism";
5
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;