markmap-lib 0.15.9-alpha.0 → 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,67 +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.0"}/dist/browser/index.js`
12
+ `markmap-view@${"0.15.9-alpha.6"}/dist/browser/index.js`
13
13
  ];
14
- const name$3 = "katex";
15
- const preloadScripts$1 = [
16
- `katex@${"0.16.8"}/dist/katex.min.js`
17
- ].map((path) => markmapCommon.buildJSItem(path));
18
- const webfontloader = markmapCommon.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) => markmapCommon.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
- };
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>`;
67
16
  function createTransformHooks(transformer) {
68
17
  return {
69
18
  transformer,
@@ -77,36 +26,40 @@ function createTransformHooks(transformer) {
77
26
  function definePlugin(plugin2) {
78
27
  return plugin2;
79
28
  }
80
- const plugin$1 = definePlugin({
81
- name: name$3,
82
- config: config$1,
29
+ const name$5 = "checkbox";
30
+ const plugin$3 = definePlugin({
31
+ name: name$5,
83
32
  transform(transformHooks) {
84
- var _a, _b;
85
- let enableFeature = markmapCommon.noop;
86
33
  transformHooks.parser.tap((md) => {
87
- md.use(remarkableKatex);
88
- md.renderer.rules.katex = markmapCommon.wrapFunction(
89
- md.renderer.rules.katex,
90
- (render, ...args) => {
91
- enableFeature();
92
- return render(...args);
93
- }
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
+ {}
94
55
  );
95
56
  });
96
- transformHooks.beforeParse.tap((_, context) => {
97
- enableFeature = () => {
98
- context.features[name$3] = true;
99
- };
100
- });
101
- return {
102
- styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
103
- scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
104
- };
57
+ return {};
105
58
  }
106
59
  });
107
- const name$2 = "frontmatter";
60
+ const name$4 = "frontmatter";
108
61
  const frontmatter = definePlugin({
109
- name: name$2,
62
+ name: name$4,
110
63
  transform(transformHooks) {
111
64
  transformHooks.beforeParse.tap((md, context) => {
112
65
  const { content } = context;
@@ -160,6 +113,125 @@ function normalizeNumber(value) {
160
113
  return;
161
114
  return +value;
162
115
  }
116
+ const name$3 = "hljs";
117
+ const preloadScripts$1 = [
118
+ `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
119
+ ].map((path) => markmapCommon.buildJSItem(path));
120
+ const styles$1 = [
121
+ `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
122
+ // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
123
+ ].map((path) => markmapCommon.buildCSSItem(path));
124
+ const config$1 = {
125
+ versions: {
126
+ hljs: "11.8.0"
127
+ },
128
+ preloadScripts: preloadScripts$1,
129
+ styles: styles$1
130
+ };
131
+ const plugin$2 = definePlugin({
132
+ name: name$3,
133
+ config: config$1,
134
+ transform(transformHooks) {
135
+ var _a;
136
+ let enableFeature = markmapCommon.noop;
137
+ transformHooks.parser.tap((md) => {
138
+ md.set({
139
+ highlight: (str, language) => {
140
+ enableFeature();
141
+ return hljs.highlightAuto(str, language ? [language] : void 0).value;
142
+ }
143
+ });
144
+ });
145
+ transformHooks.beforeParse.tap((_, context) => {
146
+ enableFeature = () => {
147
+ context.features[name$3] = true;
148
+ };
149
+ });
150
+ return {
151
+ styles: (_a = plugin$2.config) == null ? void 0 : _a.styles
152
+ };
153
+ }
154
+ });
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,
211
+ transform(transformHooks) {
212
+ var _a, _b;
213
+ let enableFeature = markmapCommon.noop;
214
+ transformHooks.parser.tap((md) => {
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
+ });
163
235
  const name$1 = "npmUrl";
164
236
  const npmUrl = definePlugin({
165
237
  name: name$1,
@@ -186,46 +258,45 @@ const npmUrl = definePlugin({
186
258
  return {};
187
259
  }
188
260
  });
189
- const name = "hljs";
190
- const preloadScripts = [
191
- `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
192
- ].map((path) => markmapCommon.buildJSItem(path));
193
- const styles = [
194
- `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
195
- // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
196
- ].map((path) => markmapCommon.buildCSSItem(path));
197
- const config = {
198
- versions: {
199
- hljs: "11.8.0"
200
- },
201
- preloadScripts,
202
- styles
203
- };
261
+ const name = "sourceLines";
204
262
  const plugin = definePlugin({
205
263
  name,
206
- config,
207
264
  transform(transformHooks) {
208
- var _a;
209
- let enableFeature = markmapCommon.noop;
210
265
  transformHooks.parser.tap((md) => {
211
- md.set({
212
- highlight: (str, language) => {
213
- enableFeature();
214
- return hljs.highlightAuto(str, language ? [language] : void 0).value;
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
+ });
215
273
  }
216
274
  });
217
275
  });
218
- transformHooks.beforeParse.tap((_, context) => {
219
- enableFeature = () => {
220
- context.features[name] = true;
221
- };
222
- });
223
- return {
224
- styles: (_a = plugin.config) == null ? void 0 : _a.styles
225
- };
276
+ return {};
226
277
  }
227
278
  });
228
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
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
+ ];
229
300
  function patchJSItem(urlBuilder, item) {
230
301
  if (item.type === "script" && item.data.src) {
231
302
  return {
@@ -388,5 +459,7 @@ const transformerVersions = {
388
459
  exports.Transformer = Transformer;
389
460
  exports.baseJsPaths = baseJsPaths;
390
461
  exports.builtInPlugins = plugins;
462
+ exports.svg_marked = svg_marked;
463
+ exports.svg_unmarked = svg_unmarked;
391
464
  exports.template = template;
392
465
  exports.transformerVersions = transformerVersions;
package/dist/index.mjs CHANGED
@@ -1,67 +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.0"}/dist/browser/index.js`
10
+ `markmap-view@${"0.15.9-alpha.6"}/dist/browser/index.js`
11
11
  ];
12
- const name$3 = "katex";
13
- const preloadScripts$1 = [
14
- `katex@${"0.16.8"}/dist/katex.min.js`
15
- ].map((path) => buildJSItem(path));
16
- const webfontloader = buildJSItem(
17
- `webfontloader@${"1.6.28"}/webfontloader.js`
18
- );
19
- webfontloader.data.defer = true;
20
- const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
21
- (path) => buildCSSItem(path)
22
- );
23
- const config$1 = {
24
- versions: {
25
- katex: "0.16.8",
26
- webfontloader: "1.6.28"
27
- },
28
- preloadScripts: preloadScripts$1,
29
- scripts: [
30
- {
31
- type: "iife",
32
- data: {
33
- fn: (getMarkmap) => {
34
- window.WebFontConfig = {
35
- custom: {
36
- families: [
37
- "KaTeX_AMS",
38
- "KaTeX_Caligraphic:n4,n7",
39
- "KaTeX_Fraktur:n4,n7",
40
- "KaTeX_Main:n4,n7,i4,i7",
41
- "KaTeX_Math:i4,i7",
42
- "KaTeX_Script",
43
- "KaTeX_SansSerif:n4,n7,i4",
44
- "KaTeX_Size1",
45
- "KaTeX_Size2",
46
- "KaTeX_Size3",
47
- "KaTeX_Size4",
48
- "KaTeX_Typewriter"
49
- ]
50
- },
51
- active: () => {
52
- getMarkmap().refreshHook.call();
53
- }
54
- };
55
- },
56
- getParams({ getMarkmap }) {
57
- return [getMarkmap];
58
- }
59
- }
60
- },
61
- webfontloader
62
- ],
63
- styles: styles$1
64
- };
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>`;
65
14
  function createTransformHooks(transformer) {
66
15
  return {
67
16
  transformer,
@@ -75,36 +24,40 @@ function createTransformHooks(transformer) {
75
24
  function definePlugin(plugin2) {
76
25
  return plugin2;
77
26
  }
78
- const plugin$1 = definePlugin({
79
- name: name$3,
80
- config: config$1,
27
+ const name$5 = "checkbox";
28
+ const plugin$3 = definePlugin({
29
+ name: name$5,
81
30
  transform(transformHooks) {
82
- var _a, _b;
83
- let enableFeature = noop;
84
31
  transformHooks.parser.tap((md) => {
85
- md.use(remarkableKatex);
86
- md.renderer.rules.katex = wrapFunction(
87
- md.renderer.rules.katex,
88
- (render, ...args) => {
89
- enableFeature();
90
- return render(...args);
91
- }
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
+ {}
92
53
  );
93
54
  });
94
- transformHooks.beforeParse.tap((_, context) => {
95
- enableFeature = () => {
96
- context.features[name$3] = true;
97
- };
98
- });
99
- return {
100
- styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
101
- scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
102
- };
55
+ return {};
103
56
  }
104
57
  });
105
- const name$2 = "frontmatter";
58
+ const name$4 = "frontmatter";
106
59
  const frontmatter = definePlugin({
107
- name: name$2,
60
+ name: name$4,
108
61
  transform(transformHooks) {
109
62
  transformHooks.beforeParse.tap((md, context) => {
110
63
  const { content } = context;
@@ -158,6 +111,125 @@ function normalizeNumber(value) {
158
111
  return;
159
112
  return +value;
160
113
  }
114
+ const name$3 = "hljs";
115
+ const preloadScripts$1 = [
116
+ `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
117
+ ].map((path) => buildJSItem(path));
118
+ const styles$1 = [
119
+ `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
120
+ // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
121
+ ].map((path) => buildCSSItem(path));
122
+ const config$1 = {
123
+ versions: {
124
+ hljs: "11.8.0"
125
+ },
126
+ preloadScripts: preloadScripts$1,
127
+ styles: styles$1
128
+ };
129
+ const plugin$2 = definePlugin({
130
+ name: name$3,
131
+ config: config$1,
132
+ transform(transformHooks) {
133
+ var _a;
134
+ let enableFeature = noop;
135
+ transformHooks.parser.tap((md) => {
136
+ md.set({
137
+ highlight: (str, language) => {
138
+ enableFeature();
139
+ return hljs.highlightAuto(str, language ? [language] : void 0).value;
140
+ }
141
+ });
142
+ });
143
+ transformHooks.beforeParse.tap((_, context) => {
144
+ enableFeature = () => {
145
+ context.features[name$3] = true;
146
+ };
147
+ });
148
+ return {
149
+ styles: (_a = plugin$2.config) == null ? void 0 : _a.styles
150
+ };
151
+ }
152
+ });
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,
209
+ transform(transformHooks) {
210
+ var _a, _b;
211
+ let enableFeature = noop;
212
+ transformHooks.parser.tap((md) => {
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
+ });
161
233
  const name$1 = "npmUrl";
162
234
  const npmUrl = definePlugin({
163
235
  name: name$1,
@@ -184,46 +256,45 @@ const npmUrl = definePlugin({
184
256
  return {};
185
257
  }
186
258
  });
187
- const name = "hljs";
188
- const preloadScripts = [
189
- `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
190
- ].map((path) => buildJSItem(path));
191
- const styles = [
192
- `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
193
- // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
194
- ].map((path) => buildCSSItem(path));
195
- const config = {
196
- versions: {
197
- hljs: "11.8.0"
198
- },
199
- preloadScripts,
200
- styles
201
- };
259
+ const name = "sourceLines";
202
260
  const plugin = definePlugin({
203
261
  name,
204
- config,
205
262
  transform(transformHooks) {
206
- var _a;
207
- let enableFeature = noop;
208
263
  transformHooks.parser.tap((md) => {
209
- md.set({
210
- highlight: (str, language) => {
211
- enableFeature();
212
- return hljs.highlightAuto(str, language ? [language] : void 0).value;
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
+ });
213
271
  }
214
272
  });
215
273
  });
216
- transformHooks.beforeParse.tap((_, context) => {
217
- enableFeature = () => {
218
- context.features[name] = true;
219
- };
220
- });
221
- return {
222
- styles: (_a = plugin.config) == null ? void 0 : _a.styles
223
- };
274
+ return {};
224
275
  }
225
276
  });
226
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
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
+ ];
227
298
  function patchJSItem(urlBuilder, item) {
228
299
  if (item.type === "script" && item.data.src) {
229
300
  return {
@@ -387,6 +458,8 @@ export {
387
458
  Transformer,
388
459
  baseJsPaths,
389
460
  plugins as builtInPlugins,
461
+ svg_marked,
462
+ svg_unmarked,
390
463
  template,
391
464
  transformerVersions
392
465
  };
@@ -0,0 +1,2 @@
1
+ declare const plugin: import("../types").ITransformPlugin;
2
+ export default plugin;
@@ -0,0 +1,2 @@
1
+ declare const plugin: import("../types").ITransformPlugin;
2
+ export default plugin;