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

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.js CHANGED
@@ -3,69 +3,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const markmapCommon = require("markmap-common");
4
4
  const markmapHtmlParser = require("markmap-html-parser");
5
5
  const remarkable = require("remarkable");
6
- const remarkableKatex = require("remarkable-katex");
7
6
  const yaml = require("js-yaml");
8
7
  const hljs = require("highlight.js");
8
+ const remarkableKatex = require("remarkable-katex");
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.5"}/dist/browser/index.js`
12
+ `markmap-view@${"0.15.9-alpha.6"}/dist/browser/index.js`
13
13
  ];
14
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
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";
17
- const preloadScripts$1 = [
18
- `katex@${"0.16.8"}/dist/katex.min.js`
19
- ].map((path) => markmapCommon.buildJSItem(path));
20
- const webfontloader = markmapCommon.buildJSItem(
21
- `webfontloader@${"1.6.28"}/webfontloader.js`
22
- );
23
- webfontloader.data.defer = true;
24
- const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
25
- (path) => markmapCommon.buildCSSItem(path)
26
- );
27
- const config$1 = {
28
- versions: {
29
- katex: "0.16.8",
30
- webfontloader: "1.6.28"
31
- },
32
- preloadScripts: preloadScripts$1,
33
- scripts: [
34
- {
35
- type: "iife",
36
- data: {
37
- fn: (getMarkmap) => {
38
- window.WebFontConfig = {
39
- custom: {
40
- families: [
41
- "KaTeX_AMS",
42
- "KaTeX_Caligraphic:n4,n7",
43
- "KaTeX_Fraktur:n4,n7",
44
- "KaTeX_Main:n4,n7,i4,i7",
45
- "KaTeX_Math:i4,i7",
46
- "KaTeX_Script",
47
- "KaTeX_SansSerif:n4,n7,i4",
48
- "KaTeX_Size1",
49
- "KaTeX_Size2",
50
- "KaTeX_Size3",
51
- "KaTeX_Size4",
52
- "KaTeX_Typewriter"
53
- ]
54
- },
55
- active: () => {
56
- getMarkmap().refreshHook.call();
57
- }
58
- };
59
- },
60
- getParams({ getMarkmap }) {
61
- return [getMarkmap];
62
- }
63
- }
64
- },
65
- webfontloader
66
- ],
67
- styles: styles$1
68
- };
69
16
  function createTransformHooks(transformer) {
70
17
  return {
71
18
  transformer,
@@ -79,36 +26,40 @@ function createTransformHooks(transformer) {
79
26
  function definePlugin(plugin2) {
80
27
  return plugin2;
81
28
  }
82
- const plugin$2 = definePlugin({
83
- name: name$4,
84
- config: config$1,
29
+ const name$5 = "checkbox";
30
+ const plugin$3 = definePlugin({
31
+ name: name$5,
85
32
  transform(transformHooks) {
86
- var _a, _b;
87
- let enableFeature = markmapCommon.noop;
88
33
  transformHooks.parser.tap((md) => {
89
- md.use(remarkableKatex);
90
- md.renderer.rules.katex = markmapCommon.wrapFunction(
91
- md.renderer.rules.katex,
92
- (render, ...args) => {
93
- enableFeature();
94
- return render(...args);
95
- }
34
+ md.core.ruler.before(
35
+ "inline",
36
+ "checkbox",
37
+ (state) => {
38
+ for (let i = 2; i < state.tokens.length; i += 1) {
39
+ const token = state.tokens[i];
40
+ if (token.type === "inline" && token.content) {
41
+ const prevType = state.tokens[i - 1].type;
42
+ const prevPrevType = state.tokens[i - 2].type;
43
+ if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
44
+ if (token.content.startsWith("[ ]")) {
45
+ token.content = `${svg_unmarked} ${token.content.slice(3)}`;
46
+ } else if (token.content.startsWith("[x]")) {
47
+ token.content = `${svg_marked} ${token.content.slice(3)}`;
48
+ }
49
+ }
50
+ }
51
+ }
52
+ return false;
53
+ },
54
+ {}
96
55
  );
97
56
  });
98
- transformHooks.beforeParse.tap((_, context) => {
99
- enableFeature = () => {
100
- context.features[name$4] = true;
101
- };
102
- });
103
- return {
104
- styles: (_a = plugin$2.config) == null ? void 0 : _a.styles,
105
- scripts: (_b = plugin$2.config) == null ? void 0 : _b.scripts
106
- };
57
+ return {};
107
58
  }
108
59
  });
109
- const name$3 = "frontmatter";
60
+ const name$4 = "frontmatter";
110
61
  const frontmatter = definePlugin({
111
- name: name$3,
62
+ name: name$4,
112
63
  transform(transformHooks) {
113
64
  transformHooks.beforeParse.tap((md, context) => {
114
65
  const { content } = context;
@@ -162,50 +113,24 @@ function normalizeNumber(value) {
162
113
  return;
163
114
  return +value;
164
115
  }
165
- const name$2 = "npmUrl";
166
- const npmUrl = definePlugin({
167
- name: name$2,
168
- transform(transformHooks) {
169
- transformHooks.afterParse.tap((_, context) => {
170
- const { frontmatter: frontmatter2 } = context;
171
- const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
172
- if (markmap) {
173
- ["extraJs", "extraCss"].forEach((key) => {
174
- const value = markmap[key];
175
- if (value) {
176
- markmap[key] = value.map((path) => {
177
- if (path.startsWith("npm:")) {
178
- return transformHooks.transformer.urlBuilder.getFullUrl(
179
- path.slice(4)
180
- );
181
- }
182
- return path;
183
- });
184
- }
185
- });
186
- }
187
- });
188
- return {};
189
- }
190
- });
191
- const name$1 = "hljs";
192
- const preloadScripts = [
116
+ const name$3 = "hljs";
117
+ const preloadScripts$1 = [
193
118
  `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
194
119
  ].map((path) => markmapCommon.buildJSItem(path));
195
- const styles = [
120
+ const styles$1 = [
196
121
  `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
197
122
  // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
198
123
  ].map((path) => markmapCommon.buildCSSItem(path));
199
- const config = {
124
+ const config$1 = {
200
125
  versions: {
201
126
  hljs: "11.8.0"
202
127
  },
203
- preloadScripts,
204
- styles
128
+ preloadScripts: preloadScripts$1,
129
+ styles: styles$1
205
130
  };
206
- const plugin$1 = definePlugin({
207
- name: name$1,
208
- config,
131
+ const plugin$2 = definePlugin({
132
+ name: name$3,
133
+ config: config$1,
209
134
  transform(transformHooks) {
210
135
  var _a;
211
136
  let enableFeature = markmapCommon.noop;
@@ -219,46 +144,159 @@ const plugin$1 = definePlugin({
219
144
  });
220
145
  transformHooks.beforeParse.tap((_, context) => {
221
146
  enableFeature = () => {
222
- context.features[name$1] = true;
147
+ context.features[name$3] = true;
223
148
  };
224
149
  });
225
150
  return {
226
- styles: (_a = plugin$1.config) == null ? void 0 : _a.styles
151
+ styles: (_a = plugin$2.config) == null ? void 0 : _a.styles
227
152
  };
228
153
  }
229
154
  });
230
- const name = "checkbox";
231
- const plugin = definePlugin({
232
- name,
155
+ const name$2 = "katex";
156
+ const preloadScripts = [
157
+ `katex@${"0.16.8"}/dist/katex.min.js`
158
+ ].map((path) => markmapCommon.buildJSItem(path));
159
+ const webfontloader = markmapCommon.buildJSItem(
160
+ `webfontloader@${"1.6.28"}/webfontloader.js`
161
+ );
162
+ webfontloader.data.defer = true;
163
+ const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
164
+ (path) => markmapCommon.buildCSSItem(path)
165
+ );
166
+ const config = {
167
+ versions: {
168
+ katex: "0.16.8",
169
+ webfontloader: "1.6.28"
170
+ },
171
+ preloadScripts,
172
+ scripts: [
173
+ {
174
+ type: "iife",
175
+ data: {
176
+ fn: (getMarkmap) => {
177
+ window.WebFontConfig = {
178
+ custom: {
179
+ families: [
180
+ "KaTeX_AMS",
181
+ "KaTeX_Caligraphic:n4,n7",
182
+ "KaTeX_Fraktur:n4,n7",
183
+ "KaTeX_Main:n4,n7,i4,i7",
184
+ "KaTeX_Math:i4,i7",
185
+ "KaTeX_Script",
186
+ "KaTeX_SansSerif:n4,n7,i4",
187
+ "KaTeX_Size1",
188
+ "KaTeX_Size2",
189
+ "KaTeX_Size3",
190
+ "KaTeX_Size4",
191
+ "KaTeX_Typewriter"
192
+ ]
193
+ },
194
+ active: () => {
195
+ getMarkmap().refreshHook.call();
196
+ }
197
+ };
198
+ },
199
+ getParams({ getMarkmap }) {
200
+ return [getMarkmap];
201
+ }
202
+ }
203
+ },
204
+ webfontloader
205
+ ],
206
+ styles
207
+ };
208
+ const plugin$1 = definePlugin({
209
+ name: name$2,
210
+ config,
233
211
  transform(transformHooks) {
212
+ var _a, _b;
213
+ let enableFeature = markmapCommon.noop;
234
214
  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
- }
215
+ md.use(remarkableKatex);
216
+ md.renderer.rules.katex = markmapCommon.wrapFunction(
217
+ md.renderer.rules.katex,
218
+ (render, ...args) => {
219
+ enableFeature();
220
+ return render(...args);
221
+ }
222
+ );
223
+ });
224
+ transformHooks.beforeParse.tap((_, context) => {
225
+ enableFeature = () => {
226
+ context.features[name$2] = true;
227
+ };
228
+ });
229
+ return {
230
+ styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
231
+ scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
232
+ };
233
+ }
234
+ });
235
+ const name$1 = "npmUrl";
236
+ const npmUrl = definePlugin({
237
+ name: name$1,
238
+ transform(transformHooks) {
239
+ transformHooks.afterParse.tap((_, context) => {
240
+ const { frontmatter: frontmatter2 } = context;
241
+ const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
242
+ if (markmap) {
243
+ ["extraJs", "extraCss"].forEach((key) => {
244
+ const value = markmap[key];
245
+ if (value) {
246
+ markmap[key] = value.map((path) => {
247
+ if (path.startsWith("npm:")) {
248
+ return transformHooks.transformer.urlBuilder.getFullUrl(
249
+ path.slice(4)
250
+ );
250
251
  }
251
- }
252
+ return path;
253
+ });
252
254
  }
253
- return false;
254
- },
255
- {}
256
- );
255
+ });
256
+ }
257
257
  });
258
258
  return {};
259
259
  }
260
260
  });
261
- const plugins = [frontmatter, plugin$2, plugin$1, npmUrl, plugin];
261
+ const name = "sourceLines";
262
+ const plugin = definePlugin({
263
+ name,
264
+ transform(transformHooks) {
265
+ transformHooks.parser.tap((md) => {
266
+ Object.entries(md.renderer.rules).forEach(([key, value]) => {
267
+ if (typeof value === "function") {
268
+ md.renderer.rules[key] = patchRule(value);
269
+ } else {
270
+ Object.entries(value).forEach(([k, v]) => {
271
+ value[k] = patchRule(v);
272
+ });
273
+ }
274
+ });
275
+ });
276
+ return {};
277
+ }
278
+ });
279
+ function patchRule(rule) {
280
+ return markmapCommon.wrapFunction(rule, (render, tokens, idx, ...rest) => {
281
+ let html = render(tokens, idx, ...rest);
282
+ const { lines } = tokens[idx];
283
+ if (lines) {
284
+ html = html.replace(
285
+ /^<[\w-]+/,
286
+ (m) => `${m} data-lines="${lines.join(",")}"`
287
+ );
288
+ }
289
+ return html;
290
+ });
291
+ }
292
+ const plugins = [
293
+ frontmatter,
294
+ plugin$1,
295
+ plugin$2,
296
+ npmUrl,
297
+ plugin$3,
298
+ plugin
299
+ ];
262
300
  function patchJSItem(urlBuilder, item) {
263
301
  if (item.type === "script" && item.data.src) {
264
302
  return {