markmap-lib 0.12.0 → 0.13.0-alpha.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/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-lib v0.12.0 | MIT License */
1
+ /*! markmap-lib v0.13.0-alpha.0 | 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,19 +8,16 @@ 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.2.7"}`].map(src => ({
11
+ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.0-alpha.0"}`].map(src => ({
12
12
  type: 'script',
13
13
  data: {
14
14
  src
15
15
  }
16
16
  }));
17
- function fillTemplate(root, assets, extra) {
18
- if (typeof extra === 'function') {
19
- extra = {
20
- getOptions: extra
21
- };
22
- }
23
17
 
18
+ const defaultGetOptions = (markmap, jsonOptions) => markmap.deriveOptions(jsonOptions);
19
+
20
+ function fillTemplate(root, assets, extra) {
24
21
  extra = _extends({
25
22
  baseJs: BASE_JS
26
23
  }, extra);
@@ -31,24 +28,24 @@ function fillTemplate(root, assets, extra) {
31
28
  const cssList = [...(styles ? persistCSS(styles) : [])];
32
29
  const context = {
33
30
  getMarkmap: () => window.markmap,
34
- getOptions: extra.getOptions,
35
- data: root
31
+ getOptions: extra.getOptions || defaultGetOptions,
32
+ jsonOptions: extra.jsonOptions,
33
+ root
36
34
  };
37
- const jsList = [...persistJS(extra.baseJs), ...persistJS([...(scripts || []), {
35
+ const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
38
36
  type: 'iife',
39
37
  data: {
40
- fn: (getMarkmap, getOptions, data) => {
41
- const {
42
- Markmap
43
- } = getMarkmap();
44
- window.mm = Markmap.create('svg#mindmap', getOptions == null ? void 0 : getOptions(), data);
38
+ fn: (getMarkmap, getOptions, root, jsonOptions) => {
39
+ const markmap = getMarkmap();
40
+ window.mm = markmap.Markmap.create('svg#mindmap', getOptions == null ? void 0 : getOptions(markmap, jsonOptions), root);
45
41
  },
46
42
  getParams: ({
47
43
  getMarkmap,
48
44
  getOptions,
49
- data
45
+ root,
46
+ jsonOptions
50
47
  }) => {
51
- return [getMarkmap, getOptions, data];
48
+ return [getMarkmap, getOptions, root, jsonOptions];
52
49
  }
53
50
  }
54
51
  }], context)];
@@ -127,7 +124,7 @@ function transform$1(transformHooks) {
127
124
  enableFeature();
128
125
  let grammar = Prism.languages[lang];
129
126
 
130
- if (!grammar) {
127
+ if (!grammar && lang) {
131
128
  loadLanguages([lang]);
132
129
  grammar = Prism.languages[lang];
133
130
  }
@@ -149,7 +146,7 @@ function transform$1(transformHooks) {
149
146
  styles: [{
150
147
  type: 'stylesheet',
151
148
  data: {
152
- href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.25.0"}/themes/prism.css`
149
+ href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/themes/prism.css`
153
150
  }
154
151
  }]
155
152
  };
@@ -210,18 +207,18 @@ function createTransformHooks() {
210
207
  const plugins = [katex, prism, frontmatter];
211
208
 
212
209
  function cleanNode(node, depth = 0) {
213
- if (node.t === 'heading') {
210
+ if (node.type === 'heading') {
214
211
  // drop all paragraphs
215
- node.c = node.c.filter(item => item.t !== 'paragraph');
216
- } else if (node.t === 'list_item') {
217
- var _node$p;
212
+ node.children = node.children.filter(item => item.type !== 'paragraph');
213
+ } else if (node.type === 'list_item') {
214
+ var _node$payload;
218
215
 
219
216
  // keep first paragraph as content of list_item, drop others
220
- node.c = node.c.filter(item => {
221
- if (['paragraph', 'fence'].includes(item.t)) {
222
- if (!node.v) {
223
- node.v = item.v;
224
- node.p = _extends({}, node.p, item.p);
217
+ node.children = node.children.filter(item => {
218
+ if (['paragraph', 'fence'].includes(item.type)) {
219
+ if (!node.content) {
220
+ node.content = item.content;
221
+ node.payload = _extends({}, node.payload, item.payload);
225
222
  }
226
223
 
227
224
  return false;
@@ -230,16 +227,16 @@ function cleanNode(node, depth = 0) {
230
227
  return true;
231
228
  });
232
229
 
233
- if (((_node$p = node.p) == null ? void 0 : _node$p.index) != null) {
234
- node.v = `${node.p.index}. ${node.v}`;
230
+ if (((_node$payload = node.payload) == null ? void 0 : _node$payload.index) != null) {
231
+ node.content = `${node.payload.index}. ${node.content}`;
235
232
  }
236
- } else if (node.t === 'ordered_list') {
237
- var _node$p$start, _node$p2;
233
+ } else if (node.type === 'ordered_list') {
234
+ var _node$payload$startIn, _node$payload2;
238
235
 
239
- let index = (_node$p$start = (_node$p2 = node.p) == null ? void 0 : _node$p2.start) != null ? _node$p$start : 1;
240
- node.c.forEach(item => {
241
- if (item.t === 'list_item') {
242
- item.p = _extends({}, item.p, {
236
+ let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1;
237
+ node.children.forEach(item => {
238
+ if (item.type === 'list_item') {
239
+ item.payload = _extends({}, item.payload, {
243
240
  index
244
241
  });
245
242
  index += 1;
@@ -247,17 +244,17 @@ function cleanNode(node, depth = 0) {
247
244
  });
248
245
  }
249
246
 
250
- if (node.c.length === 0) {
251
- delete node.c;
247
+ if (node.children.length === 0) {
248
+ delete node.children;
252
249
  } else {
253
- node.c.forEach(child => cleanNode(child, depth + 1));
250
+ node.children.forEach(child => cleanNode(child, depth + 1));
254
251
 
255
- if (node.c.length === 1 && !node.c[0].v) {
256
- node.c = node.c[0].c;
252
+ if (node.children.length === 1 && !node.children[0].content) {
253
+ node.children = node.children[0].children;
257
254
  }
258
255
  }
259
256
 
260
- node.d = depth;
257
+ node.depth = depth;
261
258
  }
262
259
 
263
260
  class Transformer {
@@ -274,12 +271,11 @@ class Transformer {
274
271
  }
275
272
 
276
273
  this.assetsMap = assetsMap;
277
- const md = new Remarkable({
274
+ const md = new Remarkable('full', {
278
275
  html: true,
279
276
  breaks: true,
280
277
  maxNesting: Infinity
281
278
  });
282
- md.block.ruler.enable(['deflist']);
283
279
  md.renderer.rules.htmltag = wrapFunction(md.renderer.rules.htmltag, {
284
280
  after: ctx => {
285
281
  this.hooks.htmltag.call(ctx);
@@ -292,14 +288,13 @@ class Transformer {
292
288
  buildTree(tokens) {
293
289
  const {
294
290
  md
295
- } = this; // TODO deal with <dl><dt>
296
-
291
+ } = this;
297
292
  const root = {
298
- t: 'root',
299
- d: 0,
300
- v: '',
301
- c: [],
302
- p: {}
293
+ type: 'root',
294
+ depth: 0,
295
+ content: '',
296
+ children: [],
297
+ payload: {}
303
298
  };
304
299
  const stack = [root];
305
300
  let depth = 0;
@@ -318,7 +313,7 @@ class Transformer {
318
313
  if (type === 'heading') {
319
314
  depth = token.hLevel;
320
315
 
321
- while (((_current = current) == null ? void 0 : _current.d) >= depth) {
316
+ while (((_current = current) == null ? void 0 : _current.depth) >= depth) {
322
317
  var _current;
323
318
 
324
319
  stack.pop();
@@ -327,27 +322,27 @@ class Transformer {
327
322
  } else {
328
323
  var _current2;
329
324
 
330
- depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.d) || 0) + 1;
325
+ depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.depth) || 0) + 1;
331
326
 
332
327
  if (type === 'ordered_list') {
333
- payload.start = token.order;
328
+ payload.startIndex = token.order;
334
329
  }
335
330
  }
336
331
 
337
332
  const item = {
338
- t: type,
339
- d: depth,
340
- p: payload,
341
- v: '',
342
- c: []
333
+ type,
334
+ depth,
335
+ payload,
336
+ content: '',
337
+ children: []
343
338
  };
344
- current.c.push(item);
339
+ current.children.push(item);
345
340
  stack.push(item);
346
341
  } else if (!current) {
347
342
  continue;
348
- } else if (token.type === `${current.t}_close`) {
349
- if (current.t === 'heading') {
350
- depth = current.d;
343
+ } else if (token.type === `${current.type}_close`) {
344
+ if (current.type === 'heading') {
345
+ depth = current.depth;
351
346
  } else {
352
347
  stack.pop();
353
348
  depth = 0;
@@ -358,23 +353,23 @@ class Transformer {
358
353
  const data = comment == null ? void 0 : comment[1].trim();
359
354
 
360
355
  if (data === 'fold') {
361
- current.p.f = true;
356
+ current.payload.fold = true;
362
357
  ctx.result = '';
363
358
  }
364
359
  });
365
360
  const text = md.renderer.render([token], md.options, {});
366
361
  revoke();
367
- current.v = `${current.v || ''}${text}`;
362
+ current.content = `${current.content || ''}${text}`;
368
363
  } else if (token.type === 'fence') {
369
364
  let result = md.renderer.render([token], md.options, {}); // Remarkable only adds className to `<code>` but not `<pre>`, copy it to make PrismJS style work.
370
365
 
371
366
  const matches = result.match(/<code( class="[^"]*")>/);
372
367
  if (matches) result = result.replace('<pre>', `<pre${matches[1]}>`);
373
- current.c.push({
374
- t: token.type,
375
- d: depth + 1,
376
- v: result,
377
- c: []
368
+ current.children.push({
369
+ type: token.type,
370
+ depth: depth + 1,
371
+ content: result,
372
+ children: []
378
373
  });
379
374
  } else ;
380
375
  }
@@ -383,7 +378,7 @@ class Transformer {
383
378
  }
384
379
 
385
380
  transform(content) {
386
- var _root$c;
381
+ var _root$children;
387
382
 
388
383
  const context = {
389
384
  features: {}
@@ -392,7 +387,7 @@ class Transformer {
392
387
  const tokens = this.md.parse(content, {});
393
388
  let root = this.buildTree(tokens);
394
389
  cleanNode(root);
395
- if (((_root$c = root.c) == null ? void 0 : _root$c.length) === 1) root = root.c[0];
390
+ if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
396
391
  return _extends({}, context, {
397
392
  root
398
393
  });
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-lib v0.12.0 | MIT License */
1
+ /*! markmap-lib v0.13.0-alpha.0 | MIT License */
2
2
  'use strict';
3
3
 
4
4
  var _extends = require('@babel/runtime/helpers/extends');
@@ -18,19 +18,16 @@ 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.2.7"}`].map(src => ({
21
+ const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.0-alpha.0"}`].map(src => ({
22
22
  type: 'script',
23
23
  data: {
24
24
  src
25
25
  }
26
26
  }));
27
- function fillTemplate(root, assets, extra) {
28
- if (typeof extra === 'function') {
29
- extra = {
30
- getOptions: extra
31
- };
32
- }
33
27
 
28
+ const defaultGetOptions = (markmap, jsonOptions) => markmap.deriveOptions(jsonOptions);
29
+
30
+ function fillTemplate(root, assets, extra) {
34
31
  extra = _extends__default({
35
32
  baseJs: BASE_JS
36
33
  }, extra);
@@ -41,24 +38,24 @@ function fillTemplate(root, assets, extra) {
41
38
  const cssList = [...(styles ? markmapCommon.persistCSS(styles) : [])];
42
39
  const context = {
43
40
  getMarkmap: () => window.markmap,
44
- getOptions: extra.getOptions,
45
- data: root
41
+ getOptions: extra.getOptions || defaultGetOptions,
42
+ jsonOptions: extra.jsonOptions,
43
+ root
46
44
  };
47
- const jsList = [...markmapCommon.persistJS(extra.baseJs), ...markmapCommon.persistJS([...(scripts || []), {
45
+ const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), {
48
46
  type: 'iife',
49
47
  data: {
50
- fn: (getMarkmap, getOptions, data) => {
51
- const {
52
- Markmap
53
- } = getMarkmap();
54
- window.mm = Markmap.create('svg#mindmap', getOptions == null ? void 0 : getOptions(), data);
48
+ fn: (getMarkmap, getOptions, root, jsonOptions) => {
49
+ const markmap = getMarkmap();
50
+ window.mm = markmap.Markmap.create('svg#mindmap', getOptions == null ? void 0 : getOptions(markmap, jsonOptions), root);
55
51
  },
56
52
  getParams: ({
57
53
  getMarkmap,
58
54
  getOptions,
59
- data
55
+ root,
56
+ jsonOptions
60
57
  }) => {
61
- return [getMarkmap, getOptions, data];
58
+ return [getMarkmap, getOptions, root, jsonOptions];
62
59
  }
63
60
  }
64
61
  }], context)];
@@ -137,7 +134,7 @@ function transform$1(transformHooks) {
137
134
  enableFeature();
138
135
  let grammar = Prism__default.languages[lang];
139
136
 
140
- if (!grammar) {
137
+ if (!grammar && lang) {
141
138
  loadLanguages__default([lang]);
142
139
  grammar = Prism__default.languages[lang];
143
140
  }
@@ -159,7 +156,7 @@ function transform$1(transformHooks) {
159
156
  styles: [{
160
157
  type: 'stylesheet',
161
158
  data: {
162
- href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.25.0"}/themes/prism.css`
159
+ href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/themes/prism.css`
163
160
  }
164
161
  }]
165
162
  };
@@ -220,18 +217,18 @@ function createTransformHooks() {
220
217
  const plugins = [katex, prism, frontmatter];
221
218
 
222
219
  function cleanNode(node, depth = 0) {
223
- if (node.t === 'heading') {
220
+ if (node.type === 'heading') {
224
221
  // drop all paragraphs
225
- node.c = node.c.filter(item => item.t !== 'paragraph');
226
- } else if (node.t === 'list_item') {
227
- var _node$p;
222
+ node.children = node.children.filter(item => item.type !== 'paragraph');
223
+ } else if (node.type === 'list_item') {
224
+ var _node$payload;
228
225
 
229
226
  // keep first paragraph as content of list_item, drop others
230
- node.c = node.c.filter(item => {
231
- if (['paragraph', 'fence'].includes(item.t)) {
232
- if (!node.v) {
233
- node.v = item.v;
234
- node.p = _extends__default({}, node.p, item.p);
227
+ node.children = node.children.filter(item => {
228
+ if (['paragraph', 'fence'].includes(item.type)) {
229
+ if (!node.content) {
230
+ node.content = item.content;
231
+ node.payload = _extends__default({}, node.payload, item.payload);
235
232
  }
236
233
 
237
234
  return false;
@@ -240,16 +237,16 @@ function cleanNode(node, depth = 0) {
240
237
  return true;
241
238
  });
242
239
 
243
- if (((_node$p = node.p) == null ? void 0 : _node$p.index) != null) {
244
- node.v = `${node.p.index}. ${node.v}`;
240
+ if (((_node$payload = node.payload) == null ? void 0 : _node$payload.index) != null) {
241
+ node.content = `${node.payload.index}. ${node.content}`;
245
242
  }
246
- } else if (node.t === 'ordered_list') {
247
- var _node$p$start, _node$p2;
243
+ } else if (node.type === 'ordered_list') {
244
+ var _node$payload$startIn, _node$payload2;
248
245
 
249
- let index = (_node$p$start = (_node$p2 = node.p) == null ? void 0 : _node$p2.start) != null ? _node$p$start : 1;
250
- node.c.forEach(item => {
251
- if (item.t === 'list_item') {
252
- item.p = _extends__default({}, item.p, {
246
+ let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1;
247
+ node.children.forEach(item => {
248
+ if (item.type === 'list_item') {
249
+ item.payload = _extends__default({}, item.payload, {
253
250
  index
254
251
  });
255
252
  index += 1;
@@ -257,17 +254,17 @@ function cleanNode(node, depth = 0) {
257
254
  });
258
255
  }
259
256
 
260
- if (node.c.length === 0) {
261
- delete node.c;
257
+ if (node.children.length === 0) {
258
+ delete node.children;
262
259
  } else {
263
- node.c.forEach(child => cleanNode(child, depth + 1));
260
+ node.children.forEach(child => cleanNode(child, depth + 1));
264
261
 
265
- if (node.c.length === 1 && !node.c[0].v) {
266
- node.c = node.c[0].c;
262
+ if (node.children.length === 1 && !node.children[0].content) {
263
+ node.children = node.children[0].children;
267
264
  }
268
265
  }
269
266
 
270
- node.d = depth;
267
+ node.depth = depth;
271
268
  }
272
269
 
273
270
  class Transformer {
@@ -284,12 +281,11 @@ class Transformer {
284
281
  }
285
282
 
286
283
  this.assetsMap = assetsMap;
287
- const md = new remarkable.Remarkable({
284
+ const md = new remarkable.Remarkable('full', {
288
285
  html: true,
289
286
  breaks: true,
290
287
  maxNesting: Infinity
291
288
  });
292
- md.block.ruler.enable(['deflist']);
293
289
  md.renderer.rules.htmltag = markmapCommon.wrapFunction(md.renderer.rules.htmltag, {
294
290
  after: ctx => {
295
291
  this.hooks.htmltag.call(ctx);
@@ -302,14 +298,13 @@ class Transformer {
302
298
  buildTree(tokens) {
303
299
  const {
304
300
  md
305
- } = this; // TODO deal with <dl><dt>
306
-
301
+ } = this;
307
302
  const root = {
308
- t: 'root',
309
- d: 0,
310
- v: '',
311
- c: [],
312
- p: {}
303
+ type: 'root',
304
+ depth: 0,
305
+ content: '',
306
+ children: [],
307
+ payload: {}
313
308
  };
314
309
  const stack = [root];
315
310
  let depth = 0;
@@ -328,7 +323,7 @@ class Transformer {
328
323
  if (type === 'heading') {
329
324
  depth = token.hLevel;
330
325
 
331
- while (((_current = current) == null ? void 0 : _current.d) >= depth) {
326
+ while (((_current = current) == null ? void 0 : _current.depth) >= depth) {
332
327
  var _current;
333
328
 
334
329
  stack.pop();
@@ -337,27 +332,27 @@ class Transformer {
337
332
  } else {
338
333
  var _current2;
339
334
 
340
- depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.d) || 0) + 1;
335
+ depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.depth) || 0) + 1;
341
336
 
342
337
  if (type === 'ordered_list') {
343
- payload.start = token.order;
338
+ payload.startIndex = token.order;
344
339
  }
345
340
  }
346
341
 
347
342
  const item = {
348
- t: type,
349
- d: depth,
350
- p: payload,
351
- v: '',
352
- c: []
343
+ type,
344
+ depth,
345
+ payload,
346
+ content: '',
347
+ children: []
353
348
  };
354
- current.c.push(item);
349
+ current.children.push(item);
355
350
  stack.push(item);
356
351
  } else if (!current) {
357
352
  continue;
358
- } else if (token.type === `${current.t}_close`) {
359
- if (current.t === 'heading') {
360
- depth = current.d;
353
+ } else if (token.type === `${current.type}_close`) {
354
+ if (current.type === 'heading') {
355
+ depth = current.depth;
361
356
  } else {
362
357
  stack.pop();
363
358
  depth = 0;
@@ -368,23 +363,23 @@ class Transformer {
368
363
  const data = comment == null ? void 0 : comment[1].trim();
369
364
 
370
365
  if (data === 'fold') {
371
- current.p.f = true;
366
+ current.payload.fold = true;
372
367
  ctx.result = '';
373
368
  }
374
369
  });
375
370
  const text = md.renderer.render([token], md.options, {});
376
371
  revoke();
377
- current.v = `${current.v || ''}${text}`;
372
+ current.content = `${current.content || ''}${text}`;
378
373
  } else if (token.type === 'fence') {
379
374
  let result = md.renderer.render([token], md.options, {}); // Remarkable only adds className to `<code>` but not `<pre>`, copy it to make PrismJS style work.
380
375
 
381
376
  const matches = result.match(/<code( class="[^"]*")>/);
382
377
  if (matches) result = result.replace('<pre>', `<pre${matches[1]}>`);
383
- current.c.push({
384
- t: token.type,
385
- d: depth + 1,
386
- v: result,
387
- c: []
378
+ current.children.push({
379
+ type: token.type,
380
+ depth: depth + 1,
381
+ content: result,
382
+ children: []
388
383
  });
389
384
  } else ;
390
385
  }
@@ -393,7 +388,7 @@ class Transformer {
393
388
  }
394
389
 
395
390
  transform(content) {
396
- var _root$c;
391
+ var _root$children;
397
392
 
398
393
  const context = {
399
394
  features: {}
@@ -402,7 +397,7 @@ class Transformer {
402
397
  const tokens = this.md.parse(content, {});
403
398
  let root = this.buildTree(tokens);
404
399
  cleanNode(root);
405
- if (((_root$c = root.c) == null ? void 0 : _root$c.length) === 1) root = root.c[0];
400
+ if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
406
401
  return _extends__default({}, context, {
407
402
  root
408
403
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-lib",
3
- "version": "0.12.0",
3
+ "version": "0.13.0-alpha.0",
4
4
  "description": "Visualize your Markdown as mindmaps with Markmap",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -35,16 +35,16 @@
35
35
  "repository": "git@github.com:gera2ld/markmap.git",
36
36
  "devDependencies": {
37
37
  "@types/remarkable": "^2.0.3",
38
- "markmap-view": "^0.2.7"
38
+ "markmap-view": "^0.13.0-alpha.0"
39
39
  },
40
40
  "dependencies": {
41
41
  "@babel/runtime": "^7.16.3",
42
42
  "js-yaml": "^4.1.0",
43
43
  "katex": "^0.15.1",
44
- "markmap-common": "^0.1.6",
44
+ "markmap-common": "^0.13.0-alpha.0",
45
45
  "prismjs": "^1.25.0",
46
46
  "remarkable": "^2.0.1",
47
47
  "remarkable-katex": "^1.1.8"
48
48
  },
49
- "gitHead": "fbec667e1706813f9f60bea6a971f3820858ca40"
49
+ "gitHead": "969aa149f36580954e77b7ba434e5c48b409cfc2"
50
50
  }
@@ -1,6 +1,8 @@
1
1
  import { JSItem, INode } from 'markmap-common';
2
+ import type { IMarkmapOptions, IMarkmapJSONOptions } from 'markmap-view';
2
3
  import { IAssets } from './types';
3
4
  export declare function fillTemplate(root: INode | undefined, assets: IAssets, extra?: {
4
5
  baseJs?: JSItem[];
5
- getOptions?: () => any;
6
- } | (() => any)): string;
6
+ jsonOptions?: IMarkmapJSONOptions;
7
+ getOptions?: (markmap: typeof window.markmap, jsonOptions: IMarkmapJSONOptions) => Partial<IMarkmapOptions>;
8
+ }): string;
package/types/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Remarkable } from 'remarkable';
2
2
  import { CSSItem, JSItem, INode, IWrapContext, Hook } from 'markmap-common';
3
+ declare type Htmltag = Remarkable.Rule<Remarkable.HtmlTagToken, string>;
3
4
  export interface ITransformHooks {
4
5
  /**
5
6
  * Tapped once when the parser is created.
@@ -12,7 +13,7 @@ export interface ITransformHooks {
12
13
  /**
13
14
  * Tapped when Remarkable renders an HTML tag in Markdown.
14
15
  */
15
- htmltag: Hook<[ctx: IWrapContext<any>]>;
16
+ htmltag: Hook<[ctx: IWrapContext<Parameters<Htmltag>, ReturnType<Htmltag>>]>;
16
17
  /**
17
18
  * Indicate that the last transformation is not complete for reasons like
18
19
  * lack of resources and is called when it is ready for a new transformation.
@@ -42,7 +43,7 @@ export interface IFeatures {
42
43
  }
43
44
  export interface ITransformContext {
44
45
  features: IFeatures;
45
- frontmatter?: any;
46
+ frontmatter?: unknown;
46
47
  }
47
48
  export interface ITransformResult extends ITransformContext {
48
49
  root: INode;
@@ -51,3 +52,4 @@ export interface ITransformPlugin {
51
52
  name: string;
52
53
  transform: (transformHooks: ITransformHooks) => IAssets;
53
54
  }
55
+ export {};