markmap-lib 0.15.9-alpha.0 → 0.15.9-alpha.5

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.
@@ -3,8 +3,10 @@
3
3
  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';
4
4
  const baseJsPaths = [
5
5
  `d3@${"7.8.5"}/dist/d3.min.js`,
6
- `markmap-view@${"0.15.9-alpha.0"}/dist/browser/index.js`
6
+ `markmap-view@${"0.15.9-alpha.5"}/dist/browser/index.js`
7
7
  ];
8
+ const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
9
+ const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
8
10
  const testPath = "npm2url/dist/index.cjs";
9
11
  const defaultProviders = {
10
12
  jsdelivr: (path) => `https://cdn.jsdelivr.net/npm/${path}`,
@@ -14066,12 +14068,14 @@
14066
14068
  const parse = getParse((content, options, isDocument2, context) => options.xmlMode || options._useHtmlParser2 ? parseDocument(content, options) : parseWithParse5(content, options, isDocument2, context));
14067
14069
  const load$2 = getLoad(parse, (dom, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom, options) : renderWithParse5(dom));
14068
14070
  load$2([]);
14071
+ const MARKMAP_COMMENT_PREFIX = "markmap: ";
14069
14072
  const SELECTOR_HEADING = /^h[1-6]$/;
14070
14073
  const SELECTOR_LIST = /^[uo]l$/;
14071
14074
  const SELECTOR_LIST_ITEM = /^li$/;
14072
14075
  const defaultOptions = {
14073
14076
  selector: "h1,h2,h3,h4,h5,h6,ul,ol,li,table,pre,p>img:first-child:last-child",
14074
- selectorPreserveContent: "table,pre",
14077
+ selectorWrapper: "div,p",
14078
+ selectorNesting: "ul,ol,li",
14075
14079
  selectorPreserveTag: "table,pre,img"
14076
14080
  };
14077
14081
  function getLevel(tagName) {
@@ -14089,71 +14093,130 @@
14089
14093
  ...opts
14090
14094
  };
14091
14095
  const $2 = load$2(html2);
14096
+ const $root = $2("body");
14092
14097
  let id = 0;
14093
- const elMap = {
14094
- [id]: $2("<div>")
14095
- };
14096
- const root2 = {
14098
+ const rootNode = {
14097
14099
  id,
14098
14100
  tag: "",
14099
14101
  html: "",
14100
14102
  level: 0,
14103
+ parent: 0,
14101
14104
  childrenLevel: 0,
14102
- children: [],
14103
- parent: 0
14105
+ children: []
14104
14106
  };
14105
- const nodeMap = {
14106
- [id]: root2
14107
+ const elMap = {
14108
+ [id]: $2("<div>")
14107
14109
  };
14108
- let cur = root2;
14109
- $2(options.selector).each((_, el) => {
14110
+ const headingStack = [];
14111
+ let skippingHeading = 0;
14112
+ checkNode($root);
14113
+ walkTree(rootNode, (node, next2) => {
14114
+ next2();
14115
+ const $el = elMap[node.id];
14116
+ $el.contents().each((_, child) => {
14117
+ if (child.type === "comment") {
14118
+ const data2 = child.data.trim();
14119
+ if (data2.startsWith(MARKMAP_COMMENT_PREFIX)) {
14120
+ node.comments || (node.comments = []);
14121
+ node.comments.push(data2.slice(MARKMAP_COMMENT_PREFIX.length).trim());
14122
+ $2(child).remove();
14123
+ }
14124
+ }
14125
+ });
14126
+ node.html = (($el.is(options.selectorPreserveTag) ? $2.html($el) : $el.html()) || "").trimEnd();
14127
+ });
14128
+ return rootNode;
14129
+ function addChild($child, parent2, nesting) {
14130
+ const child = $child[0];
14110
14131
  const node = {
14111
14132
  id: ++id,
14112
- tag: el.tagName,
14133
+ tag: child.tagName,
14113
14134
  html: "",
14114
- level: getLevel(el.tagName),
14135
+ level: getLevel(child.tagName),
14115
14136
  childrenLevel: 0,
14116
- children: $2(el).is(options.selectorPreserveContent) ? void 0 : [],
14117
- parent: 0
14137
+ children: nesting ? [] : void 0,
14138
+ parent: parent2.id
14118
14139
  };
14119
- elMap[node.id] = $2(el);
14120
- nodeMap[node.id] = node;
14121
- if (node.level <= 6) {
14122
- while (cur !== root2 && (cur.level > 6 || cur.tag >= node.tag)) {
14123
- cur = nodeMap[cur.parent];
14140
+ if (parent2.children) {
14141
+ if (parent2.childrenLevel === 0 || parent2.childrenLevel > node.level) {
14142
+ parent2.children = [];
14143
+ parent2.childrenLevel = node.level;
14124
14144
  }
14125
- } else {
14126
- while (cur !== root2 && cur.level > 6 && !elMap[cur.id].find(el).length) {
14127
- cur = nodeMap[cur.parent];
14145
+ if (parent2.childrenLevel === node.level) {
14146
+ parent2.children.push(node);
14128
14147
  }
14129
14148
  }
14130
- if (cur.children) {
14131
- node.parent = cur.id;
14132
- const level = getLevel(node.tag);
14133
- if (!cur.childrenLevel || cur.childrenLevel > level) {
14134
- cur.childrenLevel = level;
14135
- cur.children = [];
14149
+ elMap[node.id] = $child;
14150
+ return node;
14151
+ }
14152
+ function getCurrentHeading(level) {
14153
+ let heading2;
14154
+ while ((heading2 = headingStack.at(-1)) && heading2.level >= level) {
14155
+ headingStack.pop();
14156
+ }
14157
+ return heading2 || rootNode;
14158
+ }
14159
+ function checkNode($el, node) {
14160
+ $el.children().each((_, child) => {
14161
+ const $child = $2(child);
14162
+ if ($child.is(options.selectorWrapper)) {
14163
+ checkNode($child);
14164
+ return;
14165
+ }
14166
+ if (!$child.is(options.selector)) {
14167
+ const level2 = getLevel(child.tagName);
14168
+ if (level2 <= 6) {
14169
+ skippingHeading = level2;
14170
+ }
14171
+ return;
14136
14172
  }
14137
- if (cur.childrenLevel === level) {
14138
- cur.children.push(node);
14173
+ const level = getLevel(child.tagName);
14174
+ if (skippingHeading > 0 && level > skippingHeading) {
14175
+ return;
14176
+ }
14177
+ skippingHeading = 0;
14178
+ if ($child.is(options.selectorNesting)) {
14179
+ const childNode2 = addChild(
14180
+ $child,
14181
+ node || getCurrentHeading(level),
14182
+ true
14183
+ );
14184
+ if (childNode2) {
14185
+ checkNode($child, childNode2);
14186
+ $child.remove();
14187
+ }
14188
+ return;
14189
+ }
14190
+ const isHeading = level <= 6;
14191
+ const childNode = addChild(
14192
+ $child,
14193
+ node || getCurrentHeading(level),
14194
+ isHeading
14195
+ );
14196
+ if (isHeading)
14197
+ headingStack.push(childNode);
14198
+ });
14199
+ }
14200
+ }
14201
+ function convertNode(htmlRoot) {
14202
+ return walkTree(htmlRoot, (htmlNode, next2) => {
14203
+ const node = {
14204
+ content: htmlNode.html,
14205
+ children: next2() || []
14206
+ };
14207
+ if (htmlNode.comments) {
14208
+ if (htmlNode.comments.includes("foldAll")) {
14209
+ node.payload = { fold: 2 };
14210
+ } else if (htmlNode.comments.includes("fold")) {
14211
+ node.payload = { fold: 1 };
14139
14212
  }
14140
- cur = node;
14141
14213
  }
14214
+ return node;
14142
14215
  });
14143
- walkTree(root2, (node, next2) => {
14144
- next2();
14145
- const $el = elMap[node.id];
14146
- $el.remove();
14147
- node.html = (($el.is(options.selectorPreserveTag) ? $2.html($el) : $el.html()) || "").trimEnd();
14148
- });
14149
- return root2;
14150
14216
  }
14151
14217
  function buildTree(html2, opts) {
14152
14218
  const htmlRoot = parseHtml(html2, opts);
14153
- return walkTree(htmlRoot, (node, next2) => ({
14154
- content: node.html,
14155
- children: next2() || []
14156
- }));
14219
+ return convertNode(htmlRoot);
14157
14220
  }
14158
14221
  var textarea;
14159
14222
  function decodeEntity(name2) {
@@ -18092,7 +18155,7 @@
18092
18155
  };
18093
18156
  var remarkableKatex = rkatex;
18094
18157
  const remarkableKatex$1 = /* @__PURE__ */ getDefaultExportFromCjs(remarkableKatex);
18095
- const name$3 = "katex";
18158
+ const name$4 = "katex";
18096
18159
  const preloadScripts$1 = [
18097
18160
  `katex@${"0.16.8"}/dist/katex.min.js`
18098
18161
  ].map((path) => buildJSItem(path));
@@ -18198,13 +18261,13 @@
18198
18261
  function definePlugin(plugin2) {
18199
18262
  return plugin2;
18200
18263
  }
18201
- const plugin$1 = definePlugin({
18202
- name: name$3,
18264
+ const plugin$2 = definePlugin({
18265
+ name: name$4,
18203
18266
  config: config$1,
18204
18267
  transform(transformHooks) {
18205
18268
  var _a2, _b, _c, _d;
18206
18269
  let loading;
18207
- const preloadScripts2 = ((_b = (_a2 = plugin$1.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
18270
+ const preloadScripts2 = ((_b = (_a2 = plugin$2.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
18208
18271
  (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
18209
18272
  )) || [];
18210
18273
  const autoload = () => {
@@ -18235,7 +18298,7 @@
18235
18298
  });
18236
18299
  transformHooks.beforeParse.tap((_, context) => {
18237
18300
  enableFeature = () => {
18238
- context.features[name$3] = true;
18301
+ context.features[name$4] = true;
18239
18302
  };
18240
18303
  });
18241
18304
  transformHooks.afterParse.tap((_, context) => {
@@ -18248,16 +18311,16 @@
18248
18311
  if (value) {
18249
18312
  markmap[key] = addDefaultVersions(
18250
18313
  value,
18251
- name$3,
18252
- ((_b2 = (_a4 = plugin$1.config) == null ? void 0 : _a4.versions) == null ? void 0 : _b2.katex) || ""
18314
+ name$4,
18315
+ ((_b2 = (_a4 = plugin$2.config) == null ? void 0 : _a4.versions) == null ? void 0 : _b2.katex) || ""
18253
18316
  );
18254
18317
  }
18255
18318
  });
18256
18319
  }
18257
18320
  });
18258
18321
  return {
18259
- styles: (_c = plugin$1.config) == null ? void 0 : _c.styles,
18260
- scripts: (_d = plugin$1.config) == null ? void 0 : _d.scripts
18322
+ styles: (_c = plugin$2.config) == null ? void 0 : _c.styles,
18323
+ scripts: (_d = plugin$2.config) == null ? void 0 : _d.scripts
18261
18324
  };
18262
18325
  }
18263
18326
  });
@@ -20949,9 +21012,9 @@
20949
21012
  safeLoadAll,
20950
21013
  safeDump
20951
21014
  };
20952
- const name$2 = "frontmatter";
21015
+ const name$3 = "frontmatter";
20953
21016
  const frontmatter = definePlugin({
20954
- name: name$2,
21017
+ name: name$3,
20955
21018
  transform(transformHooks) {
20956
21019
  transformHooks.beforeParse.tap((md, context) => {
20957
21020
  const { content } = context;
@@ -21005,9 +21068,9 @@
21005
21068
  return;
21006
21069
  return +value;
21007
21070
  }
21008
- const name$1 = "npmUrl";
21071
+ const name$2 = "npmUrl";
21009
21072
  const npmUrl = definePlugin({
21010
- name: name$1,
21073
+ name: name$2,
21011
21074
  transform(transformHooks) {
21012
21075
  transformHooks.afterParse.tap((_, context) => {
21013
21076
  const { frontmatter: frontmatter2 } = context;
@@ -21031,7 +21094,7 @@
21031
21094
  return {};
21032
21095
  }
21033
21096
  });
21034
- const name = "hljs";
21097
+ const name$1 = "hljs";
21035
21098
  const preloadScripts = [
21036
21099
  `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
21037
21100
  ].map((path) => buildJSItem(path));
@@ -21046,13 +21109,13 @@
21046
21109
  preloadScripts,
21047
21110
  styles
21048
21111
  };
21049
- const plugin = definePlugin({
21050
- name,
21112
+ const plugin$1 = definePlugin({
21113
+ name: name$1,
21051
21114
  config,
21052
21115
  transform(transformHooks) {
21053
21116
  var _a2, _b, _c;
21054
21117
  let loading;
21055
- const preloadScripts2 = ((_b = (_a2 = plugin.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
21118
+ const preloadScripts2 = ((_b = (_a2 = plugin$1.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
21056
21119
  (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
21057
21120
  )) || [];
21058
21121
  const autoload = () => {
@@ -21077,15 +21140,46 @@
21077
21140
  });
21078
21141
  transformHooks.beforeParse.tap((_, context) => {
21079
21142
  enableFeature = () => {
21080
- context.features[name] = true;
21143
+ context.features[name$1] = true;
21081
21144
  };
21082
21145
  });
21083
21146
  return {
21084
- styles: (_c = plugin.config) == null ? void 0 : _c.styles
21147
+ styles: (_c = plugin$1.config) == null ? void 0 : _c.styles
21085
21148
  };
21086
21149
  }
21087
21150
  });
21088
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
21151
+ const name = "checkbox";
21152
+ const plugin = definePlugin({
21153
+ name,
21154
+ transform(transformHooks) {
21155
+ transformHooks.parser.tap((md) => {
21156
+ md.core.ruler.before(
21157
+ "inline",
21158
+ "checkbox",
21159
+ (state) => {
21160
+ for (let i2 = 2; i2 < state.tokens.length; i2 += 1) {
21161
+ const token = state.tokens[i2];
21162
+ if (token.type === "inline" && token.content) {
21163
+ const prevType = state.tokens[i2 - 1].type;
21164
+ const prevPrevType = state.tokens[i2 - 2].type;
21165
+ if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
21166
+ if (token.content.startsWith("[ ]")) {
21167
+ token.content = `${svg_unmarked} ${token.content.slice(3)}`;
21168
+ } else if (token.content.startsWith("[x]")) {
21169
+ token.content = `${svg_marked} ${token.content.slice(3)}`;
21170
+ }
21171
+ }
21172
+ }
21173
+ }
21174
+ return false;
21175
+ },
21176
+ {}
21177
+ );
21178
+ });
21179
+ return {};
21180
+ }
21181
+ });
21182
+ const plugins = [frontmatter, plugin$2, plugin$1, npmUrl, plugin];
21089
21183
  function cleanNode(node) {
21090
21184
  while (!node.content && node.children.length === 1) {
21091
21185
  node = node.children[0];
@@ -21224,6 +21318,8 @@
21224
21318
  exports.Transformer = Transformer;
21225
21319
  exports.baseJsPaths = baseJsPaths;
21226
21320
  exports.builtInPlugins = plugins;
21321
+ exports.svg_marked = svg_marked;
21322
+ exports.svg_unmarked = svg_unmarked;
21227
21323
  exports.template = template;
21228
21324
  exports.transformerVersions = transformerVersions;
21229
21325
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -6,9 +6,11 @@ import yaml from "js-yaml";
6
6
  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';
7
7
  const baseJsPaths = [
8
8
  `d3@${"7.8.5"}/dist/d3.min.js`,
9
- `markmap-view@${"0.15.9-alpha.0"}/dist/browser/index.js`
9
+ `markmap-view@${"0.15.9-alpha.5"}/dist/browser/index.js`
10
10
  ];
11
- const name$3 = "katex";
11
+ const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
12
+ const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
13
+ const name$4 = "katex";
12
14
  const preloadScripts$1 = [
13
15
  `katex@${"0.16.8"}/dist/katex.min.js`
14
16
  ].map((path) => buildJSItem(path));
@@ -114,13 +116,13 @@ function createTransformHooks(transformer) {
114
116
  function definePlugin(plugin2) {
115
117
  return plugin2;
116
118
  }
117
- const plugin$1 = definePlugin({
118
- name: name$3,
119
+ const plugin$2 = definePlugin({
120
+ name: name$4,
119
121
  config: config$1,
120
122
  transform(transformHooks) {
121
123
  var _a, _b, _c, _d;
122
124
  let loading;
123
- const preloadScripts2 = ((_b = (_a = plugin$1.config) == null ? void 0 : _a.preloadScripts) == null ? void 0 : _b.map(
125
+ const preloadScripts2 = ((_b = (_a = plugin$2.config) == null ? void 0 : _a.preloadScripts) == null ? void 0 : _b.map(
124
126
  (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
125
127
  )) || [];
126
128
  const autoload = () => {
@@ -151,7 +153,7 @@ const plugin$1 = definePlugin({
151
153
  });
152
154
  transformHooks.beforeParse.tap((_, context) => {
153
155
  enableFeature = () => {
154
- context.features[name$3] = true;
156
+ context.features[name$4] = true;
155
157
  };
156
158
  });
157
159
  transformHooks.afterParse.tap((_, context) => {
@@ -164,22 +166,22 @@ const plugin$1 = definePlugin({
164
166
  if (value) {
165
167
  markmap[key] = addDefaultVersions(
166
168
  value,
167
- name$3,
168
- ((_b2 = (_a3 = plugin$1.config) == null ? void 0 : _a3.versions) == null ? void 0 : _b2.katex) || ""
169
+ name$4,
170
+ ((_b2 = (_a3 = plugin$2.config) == null ? void 0 : _a3.versions) == null ? void 0 : _b2.katex) || ""
169
171
  );
170
172
  }
171
173
  });
172
174
  }
173
175
  });
174
176
  return {
175
- styles: (_c = plugin$1.config) == null ? void 0 : _c.styles,
176
- scripts: (_d = plugin$1.config) == null ? void 0 : _d.scripts
177
+ styles: (_c = plugin$2.config) == null ? void 0 : _c.styles,
178
+ scripts: (_d = plugin$2.config) == null ? void 0 : _d.scripts
177
179
  };
178
180
  }
179
181
  });
180
- const name$2 = "frontmatter";
182
+ const name$3 = "frontmatter";
181
183
  const frontmatter = definePlugin({
182
- name: name$2,
184
+ name: name$3,
183
185
  transform(transformHooks) {
184
186
  transformHooks.beforeParse.tap((md, context) => {
185
187
  const { content } = context;
@@ -233,9 +235,9 @@ function normalizeNumber(value) {
233
235
  return;
234
236
  return +value;
235
237
  }
236
- const name$1 = "npmUrl";
238
+ const name$2 = "npmUrl";
237
239
  const npmUrl = definePlugin({
238
- name: name$1,
240
+ name: name$2,
239
241
  transform(transformHooks) {
240
242
  transformHooks.afterParse.tap((_, context) => {
241
243
  const { frontmatter: frontmatter2 } = context;
@@ -259,7 +261,7 @@ const npmUrl = definePlugin({
259
261
  return {};
260
262
  }
261
263
  });
262
- const name = "hljs";
264
+ const name$1 = "hljs";
263
265
  const preloadScripts = [
264
266
  `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
265
267
  ].map((path) => buildJSItem(path));
@@ -274,13 +276,13 @@ const config = {
274
276
  preloadScripts,
275
277
  styles
276
278
  };
277
- const plugin = definePlugin({
278
- name,
279
+ const plugin$1 = definePlugin({
280
+ name: name$1,
279
281
  config,
280
282
  transform(transformHooks) {
281
283
  var _a, _b, _c;
282
284
  let loading;
283
- const preloadScripts2 = ((_b = (_a = plugin.config) == null ? void 0 : _a.preloadScripts) == null ? void 0 : _b.map(
285
+ const preloadScripts2 = ((_b = (_a = plugin$1.config) == null ? void 0 : _a.preloadScripts) == null ? void 0 : _b.map(
284
286
  (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
285
287
  )) || [];
286
288
  const autoload = () => {
@@ -305,15 +307,46 @@ const plugin = definePlugin({
305
307
  });
306
308
  transformHooks.beforeParse.tap((_, context) => {
307
309
  enableFeature = () => {
308
- context.features[name] = true;
310
+ context.features[name$1] = true;
309
311
  };
310
312
  });
311
313
  return {
312
- styles: (_c = plugin.config) == null ? void 0 : _c.styles
314
+ styles: (_c = plugin$1.config) == null ? void 0 : _c.styles
313
315
  };
314
316
  }
315
317
  });
316
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
318
+ const name = "checkbox";
319
+ const plugin = definePlugin({
320
+ name,
321
+ transform(transformHooks) {
322
+ transformHooks.parser.tap((md) => {
323
+ md.core.ruler.before(
324
+ "inline",
325
+ "checkbox",
326
+ (state) => {
327
+ for (let i = 2; i < state.tokens.length; i += 1) {
328
+ const token = state.tokens[i];
329
+ if (token.type === "inline" && token.content) {
330
+ const prevType = state.tokens[i - 1].type;
331
+ const prevPrevType = state.tokens[i - 2].type;
332
+ if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
333
+ if (token.content.startsWith("[ ]")) {
334
+ token.content = `${svg_unmarked} ${token.content.slice(3)}`;
335
+ } else if (token.content.startsWith("[x]")) {
336
+ token.content = `${svg_marked} ${token.content.slice(3)}`;
337
+ }
338
+ }
339
+ }
340
+ }
341
+ return false;
342
+ },
343
+ {}
344
+ );
345
+ });
346
+ return {};
347
+ }
348
+ });
349
+ const plugins = [frontmatter, plugin$2, plugin$1, npmUrl, plugin];
317
350
  function cleanNode(node) {
318
351
  while (!node.content && node.children.length === 1) {
319
352
  node = node.children[0];
@@ -453,6 +486,8 @@ export {
453
486
  Transformer,
454
487
  baseJsPaths,
455
488
  plugins as builtInPlugins,
489
+ svg_marked,
490
+ svg_unmarked,
456
491
  template,
457
492
  transformerVersions
458
493
  };
@@ -1,2 +1,4 @@
1
1
  export declare const template: string;
2
2
  export declare const baseJsPaths: string[];
3
+ export declare const svg_marked = "<svg width=\"16\" height=\"16\" fill=\"currentColor\" viewBox=\"0 -3 24 24\"><path d=\"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z\"/></svg>";
4
+ export declare const svg_unmarked = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"currentColor\" viewBox=\"0 -3 24 24\"><path fill-rule=\"evenodd\" d=\"M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z\" clip-rule=\"evenodd\"/></svg>";
package/dist/index.js CHANGED
@@ -9,9 +9,11 @@ const hljs = require("highlight.js");
9
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
10
  const baseJsPaths = [
11
11
  `d3@${"7.8.5"}/dist/d3.min.js`,
12
- `markmap-view@${"0.15.9-alpha.0"}/dist/browser/index.js`
12
+ `markmap-view@${"0.15.9-alpha.5"}/dist/browser/index.js`
13
13
  ];
14
- const name$3 = "katex";
14
+ const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
15
+ const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
16
+ const name$4 = "katex";
15
17
  const preloadScripts$1 = [
16
18
  `katex@${"0.16.8"}/dist/katex.min.js`
17
19
  ].map((path) => markmapCommon.buildJSItem(path));
@@ -77,8 +79,8 @@ function createTransformHooks(transformer) {
77
79
  function definePlugin(plugin2) {
78
80
  return plugin2;
79
81
  }
80
- const plugin$1 = definePlugin({
81
- name: name$3,
82
+ const plugin$2 = definePlugin({
83
+ name: name$4,
82
84
  config: config$1,
83
85
  transform(transformHooks) {
84
86
  var _a, _b;
@@ -95,18 +97,18 @@ const plugin$1 = definePlugin({
95
97
  });
96
98
  transformHooks.beforeParse.tap((_, context) => {
97
99
  enableFeature = () => {
98
- context.features[name$3] = true;
100
+ context.features[name$4] = true;
99
101
  };
100
102
  });
101
103
  return {
102
- styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
103
- scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
104
+ styles: (_a = plugin$2.config) == null ? void 0 : _a.styles,
105
+ scripts: (_b = plugin$2.config) == null ? void 0 : _b.scripts
104
106
  };
105
107
  }
106
108
  });
107
- const name$2 = "frontmatter";
109
+ const name$3 = "frontmatter";
108
110
  const frontmatter = definePlugin({
109
- name: name$2,
111
+ name: name$3,
110
112
  transform(transformHooks) {
111
113
  transformHooks.beforeParse.tap((md, context) => {
112
114
  const { content } = context;
@@ -160,9 +162,9 @@ function normalizeNumber(value) {
160
162
  return;
161
163
  return +value;
162
164
  }
163
- const name$1 = "npmUrl";
165
+ const name$2 = "npmUrl";
164
166
  const npmUrl = definePlugin({
165
- name: name$1,
167
+ name: name$2,
166
168
  transform(transformHooks) {
167
169
  transformHooks.afterParse.tap((_, context) => {
168
170
  const { frontmatter: frontmatter2 } = context;
@@ -186,7 +188,7 @@ const npmUrl = definePlugin({
186
188
  return {};
187
189
  }
188
190
  });
189
- const name = "hljs";
191
+ const name$1 = "hljs";
190
192
  const preloadScripts = [
191
193
  `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
192
194
  ].map((path) => markmapCommon.buildJSItem(path));
@@ -201,8 +203,8 @@ const config = {
201
203
  preloadScripts,
202
204
  styles
203
205
  };
204
- const plugin = definePlugin({
205
- name,
206
+ const plugin$1 = definePlugin({
207
+ name: name$1,
206
208
  config,
207
209
  transform(transformHooks) {
208
210
  var _a;
@@ -217,15 +219,46 @@ const plugin = definePlugin({
217
219
  });
218
220
  transformHooks.beforeParse.tap((_, context) => {
219
221
  enableFeature = () => {
220
- context.features[name] = true;
222
+ context.features[name$1] = true;
221
223
  };
222
224
  });
223
225
  return {
224
- styles: (_a = plugin.config) == null ? void 0 : _a.styles
226
+ styles: (_a = plugin$1.config) == null ? void 0 : _a.styles
225
227
  };
226
228
  }
227
229
  });
228
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
230
+ const name = "checkbox";
231
+ const plugin = definePlugin({
232
+ name,
233
+ transform(transformHooks) {
234
+ transformHooks.parser.tap((md) => {
235
+ md.core.ruler.before(
236
+ "inline",
237
+ "checkbox",
238
+ (state) => {
239
+ for (let i = 2; i < state.tokens.length; i += 1) {
240
+ const token = state.tokens[i];
241
+ if (token.type === "inline" && token.content) {
242
+ const prevType = state.tokens[i - 1].type;
243
+ const prevPrevType = state.tokens[i - 2].type;
244
+ if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
245
+ if (token.content.startsWith("[ ]")) {
246
+ token.content = `${svg_unmarked} ${token.content.slice(3)}`;
247
+ } else if (token.content.startsWith("[x]")) {
248
+ token.content = `${svg_marked} ${token.content.slice(3)}`;
249
+ }
250
+ }
251
+ }
252
+ }
253
+ return false;
254
+ },
255
+ {}
256
+ );
257
+ });
258
+ return {};
259
+ }
260
+ });
261
+ const plugins = [frontmatter, plugin$2, plugin$1, npmUrl, plugin];
229
262
  function patchJSItem(urlBuilder, item) {
230
263
  if (item.type === "script" && item.data.src) {
231
264
  return {
@@ -388,5 +421,7 @@ const transformerVersions = {
388
421
  exports.Transformer = Transformer;
389
422
  exports.baseJsPaths = baseJsPaths;
390
423
  exports.builtInPlugins = plugins;
424
+ exports.svg_marked = svg_marked;
425
+ exports.svg_unmarked = svg_unmarked;
391
426
  exports.template = template;
392
427
  exports.transformerVersions = transformerVersions;
package/dist/index.mjs CHANGED
@@ -7,9 +7,11 @@ import hljs from "highlight.js";
7
7
  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';
8
8
  const baseJsPaths = [
9
9
  `d3@${"7.8.5"}/dist/d3.min.js`,
10
- `markmap-view@${"0.15.9-alpha.0"}/dist/browser/index.js`
10
+ `markmap-view@${"0.15.9-alpha.5"}/dist/browser/index.js`
11
11
  ];
12
- const name$3 = "katex";
12
+ const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
13
+ const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
14
+ const name$4 = "katex";
13
15
  const preloadScripts$1 = [
14
16
  `katex@${"0.16.8"}/dist/katex.min.js`
15
17
  ].map((path) => buildJSItem(path));
@@ -75,8 +77,8 @@ function createTransformHooks(transformer) {
75
77
  function definePlugin(plugin2) {
76
78
  return plugin2;
77
79
  }
78
- const plugin$1 = definePlugin({
79
- name: name$3,
80
+ const plugin$2 = definePlugin({
81
+ name: name$4,
80
82
  config: config$1,
81
83
  transform(transformHooks) {
82
84
  var _a, _b;
@@ -93,18 +95,18 @@ const plugin$1 = definePlugin({
93
95
  });
94
96
  transformHooks.beforeParse.tap((_, context) => {
95
97
  enableFeature = () => {
96
- context.features[name$3] = true;
98
+ context.features[name$4] = true;
97
99
  };
98
100
  });
99
101
  return {
100
- styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
101
- scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
102
+ styles: (_a = plugin$2.config) == null ? void 0 : _a.styles,
103
+ scripts: (_b = plugin$2.config) == null ? void 0 : _b.scripts
102
104
  };
103
105
  }
104
106
  });
105
- const name$2 = "frontmatter";
107
+ const name$3 = "frontmatter";
106
108
  const frontmatter = definePlugin({
107
- name: name$2,
109
+ name: name$3,
108
110
  transform(transformHooks) {
109
111
  transformHooks.beforeParse.tap((md, context) => {
110
112
  const { content } = context;
@@ -158,9 +160,9 @@ function normalizeNumber(value) {
158
160
  return;
159
161
  return +value;
160
162
  }
161
- const name$1 = "npmUrl";
163
+ const name$2 = "npmUrl";
162
164
  const npmUrl = definePlugin({
163
- name: name$1,
165
+ name: name$2,
164
166
  transform(transformHooks) {
165
167
  transformHooks.afterParse.tap((_, context) => {
166
168
  const { frontmatter: frontmatter2 } = context;
@@ -184,7 +186,7 @@ const npmUrl = definePlugin({
184
186
  return {};
185
187
  }
186
188
  });
187
- const name = "hljs";
189
+ const name$1 = "hljs";
188
190
  const preloadScripts = [
189
191
  `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
190
192
  ].map((path) => buildJSItem(path));
@@ -199,8 +201,8 @@ const config = {
199
201
  preloadScripts,
200
202
  styles
201
203
  };
202
- const plugin = definePlugin({
203
- name,
204
+ const plugin$1 = definePlugin({
205
+ name: name$1,
204
206
  config,
205
207
  transform(transformHooks) {
206
208
  var _a;
@@ -215,15 +217,46 @@ const plugin = definePlugin({
215
217
  });
216
218
  transformHooks.beforeParse.tap((_, context) => {
217
219
  enableFeature = () => {
218
- context.features[name] = true;
220
+ context.features[name$1] = true;
219
221
  };
220
222
  });
221
223
  return {
222
- styles: (_a = plugin.config) == null ? void 0 : _a.styles
224
+ styles: (_a = plugin$1.config) == null ? void 0 : _a.styles
223
225
  };
224
226
  }
225
227
  });
226
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
228
+ const name = "checkbox";
229
+ const plugin = definePlugin({
230
+ name,
231
+ transform(transformHooks) {
232
+ transformHooks.parser.tap((md) => {
233
+ md.core.ruler.before(
234
+ "inline",
235
+ "checkbox",
236
+ (state) => {
237
+ for (let i = 2; i < state.tokens.length; i += 1) {
238
+ const token = state.tokens[i];
239
+ if (token.type === "inline" && token.content) {
240
+ const prevType = state.tokens[i - 1].type;
241
+ const prevPrevType = state.tokens[i - 2].type;
242
+ if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
243
+ if (token.content.startsWith("[ ]")) {
244
+ token.content = `${svg_unmarked} ${token.content.slice(3)}`;
245
+ } else if (token.content.startsWith("[x]")) {
246
+ token.content = `${svg_marked} ${token.content.slice(3)}`;
247
+ }
248
+ }
249
+ }
250
+ }
251
+ return false;
252
+ },
253
+ {}
254
+ );
255
+ });
256
+ return {};
257
+ }
258
+ });
259
+ const plugins = [frontmatter, plugin$2, plugin$1, npmUrl, plugin];
227
260
  function patchJSItem(urlBuilder, item) {
228
261
  if (item.type === "script" && item.data.src) {
229
262
  return {
@@ -387,6 +420,8 @@ export {
387
420
  Transformer,
388
421
  baseJsPaths,
389
422
  plugins as builtInPlugins,
423
+ svg_marked,
424
+ svg_unmarked,
390
425
  template,
391
426
  transformerVersions
392
427
  };
@@ -0,0 +1,2 @@
1
+ declare const plugin: import("../types").ITransformPlugin;
2
+ export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-lib",
3
- "version": "0.15.9-alpha.0+9cb40e7",
3
+ "version": "0.15.9-alpha.5+c64866f",
4
4
  "description": "Visualize your Markdown as mindmaps with Markmap",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -47,8 +47,8 @@
47
47
  "devDependencies": {
48
48
  "@highlightjs/cdn-assets": "^11.8.0",
49
49
  "@types/remarkable": "^2.0.3",
50
- "markmap-common": "0.15.9-alpha.0+9cb40e7",
51
- "markmap-view": "0.15.9-alpha.0+9cb40e7",
50
+ "markmap-common": "0.15.9-alpha.5+c64866f",
51
+ "markmap-view": "0.15.9-alpha.5+c64866f",
52
52
  "webfontloader": "^1.6.28"
53
53
  },
54
54
  "dependencies": {
@@ -56,7 +56,7 @@
56
56
  "highlight.js": "^11.8.0",
57
57
  "js-yaml": "^4.1.0",
58
58
  "katex": "^0.16.8",
59
- "markmap-html-parser": "0.15.9-alpha.0+9cb40e7",
59
+ "markmap-html-parser": "0.15.9-alpha.5+c64866f",
60
60
  "prismjs": "^1.29.0",
61
61
  "remarkable": "^2.0.1",
62
62
  "remarkable-katex": "^1.2.1"
@@ -74,5 +74,5 @@
74
74
  ]
75
75
  }
76
76
  },
77
- "gitHead": "9cb40e7e9ec0aa1f25a2de6a74912cd0c21f52ed"
77
+ "gitHead": "c64866fb4873a99923be18ea70715aa49a6dabef"
78
78
  }