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