markmap-lib 0.15.9-alpha.0 → 0.15.9-alpha.11
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/browser/index.iife.js +582 -435
- package/dist/browser/index.mjs +232 -156
- package/dist/index.js +19 -232
- package/dist/index.mjs +20 -233
- package/dist/index.no-plugins.js +185 -0
- package/dist/index.no-plugins.mjs +185 -0
- package/dist/plugins/checkbox/index.d.ts +2 -0
- package/dist/plugins/frontmatter/index.d.ts +2 -0
- package/dist/plugins/hljs/index.browser.d.ts +2 -0
- package/dist/plugins/hljs/index.d.ts +2 -0
- package/dist/plugins/katex/index.browser.d.ts +2 -0
- package/dist/plugins/katex/index.d.ts +2 -0
- package/dist/plugins/npm-url/index.d.ts +2 -0
- package/dist/plugins/prism/index.browser.d.ts +2 -0
- package/dist/plugins/prism/index.d.ts +2 -0
- package/dist/plugins/source-lines/index.d.ts +2 -0
- package/dist/plugins.js +299 -0
- package/dist/plugins.mjs +299 -0
- package/dist/transform.d.ts +1 -2
- package/package.json +18 -6
- package/dist/plugins/frontmatter.d.ts +0 -2
- package/dist/plugins/hljs.browser.d.ts +0 -2
- package/dist/plugins/hljs.d.ts +0 -2
- package/dist/plugins/katex.browser.d.ts +0 -2
- package/dist/plugins/katex.d.ts +0 -2
- package/dist/plugins/npm-url.d.ts +0 -2
- package/dist/plugins/prism.browser.d.ts +0 -2
- package/dist/plugins/prism.d.ts +0 -2
- /package/dist/plugins/{hljs.config.d.ts → hljs/config.d.ts} +0 -0
- /package/dist/plugins/{katex.config.d.ts → katex/config.d.ts} +0 -0
- /package/dist/plugins/{prism.config.d.ts → prism/config.d.ts} +0 -0
package/dist/plugins.js
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const markmapCommon = require("markmap-common");
|
|
4
|
+
const yaml = require("js-yaml");
|
|
5
|
+
const hljs$1 = require("highlight.js");
|
|
6
|
+
const remarkableKatex = require("remarkable-katex");
|
|
7
|
+
function createTransformHooks(transformer) {
|
|
8
|
+
return {
|
|
9
|
+
transformer,
|
|
10
|
+
parser: new markmapCommon.Hook(),
|
|
11
|
+
beforeParse: new markmapCommon.Hook(),
|
|
12
|
+
afterParse: new markmapCommon.Hook(),
|
|
13
|
+
htmltag: new markmapCommon.Hook(),
|
|
14
|
+
retransform: new markmapCommon.Hook()
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function definePlugin(plugin2) {
|
|
18
|
+
return plugin2;
|
|
19
|
+
}
|
|
20
|
+
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>`;
|
|
21
|
+
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>`;
|
|
22
|
+
const name$5 = "checkbox";
|
|
23
|
+
const plugin$3 = definePlugin({
|
|
24
|
+
name: name$5,
|
|
25
|
+
transform(transformHooks) {
|
|
26
|
+
transformHooks.parser.tap((md) => {
|
|
27
|
+
md.core.ruler.before(
|
|
28
|
+
"inline",
|
|
29
|
+
"checkbox",
|
|
30
|
+
(state) => {
|
|
31
|
+
for (let i = 2; i < state.tokens.length; i += 1) {
|
|
32
|
+
const token = state.tokens[i];
|
|
33
|
+
if (token.type === "inline" && token.content) {
|
|
34
|
+
const prevType = state.tokens[i - 1].type;
|
|
35
|
+
const prevPrevType = state.tokens[i - 2].type;
|
|
36
|
+
if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
|
|
37
|
+
if (token.content.startsWith("[ ]")) {
|
|
38
|
+
token.content = `${svg_unmarked} ${token.content.slice(3)}`;
|
|
39
|
+
} else if (token.content.startsWith("[x]")) {
|
|
40
|
+
token.content = `${svg_marked} ${token.content.slice(3)}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
},
|
|
47
|
+
{}
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const checkbox = plugin$3;
|
|
54
|
+
const name$4 = "frontmatter";
|
|
55
|
+
const frontmatter = definePlugin({
|
|
56
|
+
name: name$4,
|
|
57
|
+
transform(transformHooks) {
|
|
58
|
+
transformHooks.beforeParse.tap((md, context) => {
|
|
59
|
+
const { content } = context;
|
|
60
|
+
if (!/^---\r?\n/.test(content))
|
|
61
|
+
return;
|
|
62
|
+
const match = /\n---\r?\n/.exec(content);
|
|
63
|
+
if (!match)
|
|
64
|
+
return;
|
|
65
|
+
const raw = content.slice(4, match.index);
|
|
66
|
+
let frontmatter2;
|
|
67
|
+
try {
|
|
68
|
+
frontmatter2 = yaml.load(raw);
|
|
69
|
+
if (frontmatter2 == null ? void 0 : frontmatter2.markmap) {
|
|
70
|
+
frontmatter2.markmap = normalizeMarkmapJsonOptions(
|
|
71
|
+
frontmatter2.markmap
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
context.frontmatter = frontmatter2;
|
|
78
|
+
context.content = content.slice(match.index + match[0].length);
|
|
79
|
+
context.contentLineOffset = content.slice(0, match.index).split("\n").length + 1;
|
|
80
|
+
});
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
function normalizeMarkmapJsonOptions(options) {
|
|
85
|
+
if (!options)
|
|
86
|
+
return;
|
|
87
|
+
["color", "extraJs", "extraCss"].forEach((key) => {
|
|
88
|
+
if (options[key] != null)
|
|
89
|
+
options[key] = normalizeStringArray(options[key]);
|
|
90
|
+
});
|
|
91
|
+
["duration", "maxWidth", "initialExpandLevel"].forEach((key) => {
|
|
92
|
+
if (options[key] != null)
|
|
93
|
+
options[key] = normalizeNumber(options[key]);
|
|
94
|
+
});
|
|
95
|
+
return options;
|
|
96
|
+
}
|
|
97
|
+
function normalizeStringArray(value) {
|
|
98
|
+
let result;
|
|
99
|
+
if (typeof value === "string")
|
|
100
|
+
result = [value];
|
|
101
|
+
else if (Array.isArray(value))
|
|
102
|
+
result = value.filter((item) => item && typeof item === "string");
|
|
103
|
+
return (result == null ? void 0 : result.length) ? result : void 0;
|
|
104
|
+
}
|
|
105
|
+
function normalizeNumber(value) {
|
|
106
|
+
if (isNaN(+value))
|
|
107
|
+
return;
|
|
108
|
+
return +value;
|
|
109
|
+
}
|
|
110
|
+
const name$3 = "hljs";
|
|
111
|
+
const preloadScripts$1 = [
|
|
112
|
+
`@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
|
|
113
|
+
].map((path) => markmapCommon.buildJSItem(path));
|
|
114
|
+
const styles$1 = [
|
|
115
|
+
`@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
|
|
116
|
+
// `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
|
|
117
|
+
].map((path) => markmapCommon.buildCSSItem(path));
|
|
118
|
+
const config$1 = {
|
|
119
|
+
versions: {
|
|
120
|
+
hljs: "11.8.0"
|
|
121
|
+
},
|
|
122
|
+
preloadScripts: preloadScripts$1,
|
|
123
|
+
styles: styles$1
|
|
124
|
+
};
|
|
125
|
+
const plugin$2 = definePlugin({
|
|
126
|
+
name: name$3,
|
|
127
|
+
config: config$1,
|
|
128
|
+
transform(transformHooks) {
|
|
129
|
+
var _a;
|
|
130
|
+
let enableFeature = markmapCommon.noop;
|
|
131
|
+
transformHooks.parser.tap((md) => {
|
|
132
|
+
md.set({
|
|
133
|
+
highlight: (str, language) => {
|
|
134
|
+
enableFeature();
|
|
135
|
+
return hljs$1.highlightAuto(str, language ? [language] : void 0).value;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
140
|
+
enableFeature = () => {
|
|
141
|
+
context.features[name$3] = true;
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
styles: (_a = plugin$2.config) == null ? void 0 : _a.styles
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const hljs = plugin$2;
|
|
150
|
+
const name$2 = "katex";
|
|
151
|
+
const preloadScripts = [
|
|
152
|
+
`katex@${"0.16.8"}/dist/katex.min.js`
|
|
153
|
+
].map((path) => markmapCommon.buildJSItem(path));
|
|
154
|
+
const webfontloader = markmapCommon.buildJSItem(
|
|
155
|
+
`webfontloader@${"1.6.28"}/webfontloader.js`
|
|
156
|
+
);
|
|
157
|
+
webfontloader.data.defer = true;
|
|
158
|
+
const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
|
|
159
|
+
(path) => markmapCommon.buildCSSItem(path)
|
|
160
|
+
);
|
|
161
|
+
const config = {
|
|
162
|
+
versions: {
|
|
163
|
+
katex: "0.16.8",
|
|
164
|
+
webfontloader: "1.6.28"
|
|
165
|
+
},
|
|
166
|
+
preloadScripts,
|
|
167
|
+
scripts: [
|
|
168
|
+
{
|
|
169
|
+
type: "iife",
|
|
170
|
+
data: {
|
|
171
|
+
fn: (getMarkmap) => {
|
|
172
|
+
window.WebFontConfig = {
|
|
173
|
+
custom: {
|
|
174
|
+
families: [
|
|
175
|
+
"KaTeX_AMS",
|
|
176
|
+
"KaTeX_Caligraphic:n4,n7",
|
|
177
|
+
"KaTeX_Fraktur:n4,n7",
|
|
178
|
+
"KaTeX_Main:n4,n7,i4,i7",
|
|
179
|
+
"KaTeX_Math:i4,i7",
|
|
180
|
+
"KaTeX_Script",
|
|
181
|
+
"KaTeX_SansSerif:n4,n7,i4",
|
|
182
|
+
"KaTeX_Size1",
|
|
183
|
+
"KaTeX_Size2",
|
|
184
|
+
"KaTeX_Size3",
|
|
185
|
+
"KaTeX_Size4",
|
|
186
|
+
"KaTeX_Typewriter"
|
|
187
|
+
]
|
|
188
|
+
},
|
|
189
|
+
active: () => {
|
|
190
|
+
getMarkmap().refreshHook.call();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
getParams({ getMarkmap }) {
|
|
195
|
+
return [getMarkmap];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
webfontloader
|
|
200
|
+
],
|
|
201
|
+
styles
|
|
202
|
+
};
|
|
203
|
+
const plugin$1 = definePlugin({
|
|
204
|
+
name: name$2,
|
|
205
|
+
config,
|
|
206
|
+
transform(transformHooks) {
|
|
207
|
+
var _a, _b;
|
|
208
|
+
let enableFeature = markmapCommon.noop;
|
|
209
|
+
transformHooks.parser.tap((md) => {
|
|
210
|
+
md.use(remarkableKatex);
|
|
211
|
+
md.renderer.rules.katex = markmapCommon.wrapFunction(
|
|
212
|
+
md.renderer.rules.katex,
|
|
213
|
+
(render, ...args) => {
|
|
214
|
+
enableFeature();
|
|
215
|
+
return render(...args);
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
220
|
+
enableFeature = () => {
|
|
221
|
+
context.features[name$2] = true;
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
return {
|
|
225
|
+
styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
|
|
226
|
+
scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
const katex = plugin$1;
|
|
231
|
+
const name$1 = "npmUrl";
|
|
232
|
+
const npmUrl = definePlugin({
|
|
233
|
+
name: name$1,
|
|
234
|
+
transform(transformHooks) {
|
|
235
|
+
transformHooks.afterParse.tap((_, context) => {
|
|
236
|
+
const { frontmatter: frontmatter2 } = context;
|
|
237
|
+
const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
|
|
238
|
+
if (markmap) {
|
|
239
|
+
["extraJs", "extraCss"].forEach((key) => {
|
|
240
|
+
const value = markmap[key];
|
|
241
|
+
if (value) {
|
|
242
|
+
markmap[key] = value.map((path) => {
|
|
243
|
+
if (path.startsWith("npm:")) {
|
|
244
|
+
return transformHooks.transformer.urlBuilder.getFullUrl(
|
|
245
|
+
path.slice(4)
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
return path;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
return {};
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
const name = "sourceLines";
|
|
258
|
+
const plugin = definePlugin({
|
|
259
|
+
name,
|
|
260
|
+
transform(transformHooks) {
|
|
261
|
+
transformHooks.parser.tap((md) => {
|
|
262
|
+
Object.entries(md.renderer.rules).forEach(([key, value]) => {
|
|
263
|
+
if (typeof value === "function") {
|
|
264
|
+
md.renderer.rules[key] = patchRule(value);
|
|
265
|
+
} else {
|
|
266
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
267
|
+
value[k] = patchRule(v);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
return {};
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
function patchRule(rule, _key) {
|
|
276
|
+
return markmapCommon.wrapFunction(rule, (render, tokens, idx, ...rest) => {
|
|
277
|
+
let html = render(tokens, idx, ...rest);
|
|
278
|
+
const { lines } = tokens[idx];
|
|
279
|
+
if (lines) {
|
|
280
|
+
html = html.replace(
|
|
281
|
+
/^<[\w-]+/,
|
|
282
|
+
(m) => `${m} data-lines="${lines.join(",")}"`
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
return html;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
const sourceLines = plugin;
|
|
289
|
+
const plugins = [
|
|
290
|
+
frontmatter,
|
|
291
|
+
katex,
|
|
292
|
+
hljs,
|
|
293
|
+
npmUrl,
|
|
294
|
+
checkbox,
|
|
295
|
+
sourceLines
|
|
296
|
+
];
|
|
297
|
+
exports.createTransformHooks = createTransformHooks;
|
|
298
|
+
exports.definePlugin = definePlugin;
|
|
299
|
+
exports.plugins = plugins;
|
package/dist/plugins.mjs
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { Hook, buildJSItem, buildCSSItem, noop, wrapFunction } from "markmap-common";
|
|
2
|
+
import yaml from "js-yaml";
|
|
3
|
+
import hljs$1 from "highlight.js";
|
|
4
|
+
import remarkableKatex from "remarkable-katex";
|
|
5
|
+
function createTransformHooks(transformer) {
|
|
6
|
+
return {
|
|
7
|
+
transformer,
|
|
8
|
+
parser: new Hook(),
|
|
9
|
+
beforeParse: new Hook(),
|
|
10
|
+
afterParse: new Hook(),
|
|
11
|
+
htmltag: new Hook(),
|
|
12
|
+
retransform: new Hook()
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function definePlugin(plugin2) {
|
|
16
|
+
return plugin2;
|
|
17
|
+
}
|
|
18
|
+
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>`;
|
|
19
|
+
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>`;
|
|
20
|
+
const name$5 = "checkbox";
|
|
21
|
+
const plugin$3 = definePlugin({
|
|
22
|
+
name: name$5,
|
|
23
|
+
transform(transformHooks) {
|
|
24
|
+
transformHooks.parser.tap((md) => {
|
|
25
|
+
md.core.ruler.before(
|
|
26
|
+
"inline",
|
|
27
|
+
"checkbox",
|
|
28
|
+
(state) => {
|
|
29
|
+
for (let i = 2; i < state.tokens.length; i += 1) {
|
|
30
|
+
const token = state.tokens[i];
|
|
31
|
+
if (token.type === "inline" && token.content) {
|
|
32
|
+
const prevType = state.tokens[i - 1].type;
|
|
33
|
+
const prevPrevType = state.tokens[i - 2].type;
|
|
34
|
+
if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
|
|
35
|
+
if (token.content.startsWith("[ ]")) {
|
|
36
|
+
token.content = `${svg_unmarked} ${token.content.slice(3)}`;
|
|
37
|
+
} else if (token.content.startsWith("[x]")) {
|
|
38
|
+
token.content = `${svg_marked} ${token.content.slice(3)}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
},
|
|
45
|
+
{}
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const checkbox = plugin$3;
|
|
52
|
+
const name$4 = "frontmatter";
|
|
53
|
+
const frontmatter = definePlugin({
|
|
54
|
+
name: name$4,
|
|
55
|
+
transform(transformHooks) {
|
|
56
|
+
transformHooks.beforeParse.tap((md, context) => {
|
|
57
|
+
const { content } = context;
|
|
58
|
+
if (!/^---\r?\n/.test(content))
|
|
59
|
+
return;
|
|
60
|
+
const match = /\n---\r?\n/.exec(content);
|
|
61
|
+
if (!match)
|
|
62
|
+
return;
|
|
63
|
+
const raw = content.slice(4, match.index);
|
|
64
|
+
let frontmatter2;
|
|
65
|
+
try {
|
|
66
|
+
frontmatter2 = yaml.load(raw);
|
|
67
|
+
if (frontmatter2 == null ? void 0 : frontmatter2.markmap) {
|
|
68
|
+
frontmatter2.markmap = normalizeMarkmapJsonOptions(
|
|
69
|
+
frontmatter2.markmap
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
context.frontmatter = frontmatter2;
|
|
76
|
+
context.content = content.slice(match.index + match[0].length);
|
|
77
|
+
context.contentLineOffset = content.slice(0, match.index).split("\n").length + 1;
|
|
78
|
+
});
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
function normalizeMarkmapJsonOptions(options) {
|
|
83
|
+
if (!options)
|
|
84
|
+
return;
|
|
85
|
+
["color", "extraJs", "extraCss"].forEach((key) => {
|
|
86
|
+
if (options[key] != null)
|
|
87
|
+
options[key] = normalizeStringArray(options[key]);
|
|
88
|
+
});
|
|
89
|
+
["duration", "maxWidth", "initialExpandLevel"].forEach((key) => {
|
|
90
|
+
if (options[key] != null)
|
|
91
|
+
options[key] = normalizeNumber(options[key]);
|
|
92
|
+
});
|
|
93
|
+
return options;
|
|
94
|
+
}
|
|
95
|
+
function normalizeStringArray(value) {
|
|
96
|
+
let result;
|
|
97
|
+
if (typeof value === "string")
|
|
98
|
+
result = [value];
|
|
99
|
+
else if (Array.isArray(value))
|
|
100
|
+
result = value.filter((item) => item && typeof item === "string");
|
|
101
|
+
return (result == null ? void 0 : result.length) ? result : void 0;
|
|
102
|
+
}
|
|
103
|
+
function normalizeNumber(value) {
|
|
104
|
+
if (isNaN(+value))
|
|
105
|
+
return;
|
|
106
|
+
return +value;
|
|
107
|
+
}
|
|
108
|
+
const name$3 = "hljs";
|
|
109
|
+
const preloadScripts$1 = [
|
|
110
|
+
`@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
|
|
111
|
+
].map((path) => buildJSItem(path));
|
|
112
|
+
const styles$1 = [
|
|
113
|
+
`@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
|
|
114
|
+
// `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
|
|
115
|
+
].map((path) => buildCSSItem(path));
|
|
116
|
+
const config$1 = {
|
|
117
|
+
versions: {
|
|
118
|
+
hljs: "11.8.0"
|
|
119
|
+
},
|
|
120
|
+
preloadScripts: preloadScripts$1,
|
|
121
|
+
styles: styles$1
|
|
122
|
+
};
|
|
123
|
+
const plugin$2 = definePlugin({
|
|
124
|
+
name: name$3,
|
|
125
|
+
config: config$1,
|
|
126
|
+
transform(transformHooks) {
|
|
127
|
+
var _a;
|
|
128
|
+
let enableFeature = noop;
|
|
129
|
+
transformHooks.parser.tap((md) => {
|
|
130
|
+
md.set({
|
|
131
|
+
highlight: (str, language) => {
|
|
132
|
+
enableFeature();
|
|
133
|
+
return hljs$1.highlightAuto(str, language ? [language] : void 0).value;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
138
|
+
enableFeature = () => {
|
|
139
|
+
context.features[name$3] = true;
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
styles: (_a = plugin$2.config) == null ? void 0 : _a.styles
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const hljs = plugin$2;
|
|
148
|
+
const name$2 = "katex";
|
|
149
|
+
const preloadScripts = [
|
|
150
|
+
`katex@${"0.16.8"}/dist/katex.min.js`
|
|
151
|
+
].map((path) => buildJSItem(path));
|
|
152
|
+
const webfontloader = buildJSItem(
|
|
153
|
+
`webfontloader@${"1.6.28"}/webfontloader.js`
|
|
154
|
+
);
|
|
155
|
+
webfontloader.data.defer = true;
|
|
156
|
+
const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
|
|
157
|
+
(path) => buildCSSItem(path)
|
|
158
|
+
);
|
|
159
|
+
const config = {
|
|
160
|
+
versions: {
|
|
161
|
+
katex: "0.16.8",
|
|
162
|
+
webfontloader: "1.6.28"
|
|
163
|
+
},
|
|
164
|
+
preloadScripts,
|
|
165
|
+
scripts: [
|
|
166
|
+
{
|
|
167
|
+
type: "iife",
|
|
168
|
+
data: {
|
|
169
|
+
fn: (getMarkmap) => {
|
|
170
|
+
window.WebFontConfig = {
|
|
171
|
+
custom: {
|
|
172
|
+
families: [
|
|
173
|
+
"KaTeX_AMS",
|
|
174
|
+
"KaTeX_Caligraphic:n4,n7",
|
|
175
|
+
"KaTeX_Fraktur:n4,n7",
|
|
176
|
+
"KaTeX_Main:n4,n7,i4,i7",
|
|
177
|
+
"KaTeX_Math:i4,i7",
|
|
178
|
+
"KaTeX_Script",
|
|
179
|
+
"KaTeX_SansSerif:n4,n7,i4",
|
|
180
|
+
"KaTeX_Size1",
|
|
181
|
+
"KaTeX_Size2",
|
|
182
|
+
"KaTeX_Size3",
|
|
183
|
+
"KaTeX_Size4",
|
|
184
|
+
"KaTeX_Typewriter"
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
active: () => {
|
|
188
|
+
getMarkmap().refreshHook.call();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
getParams({ getMarkmap }) {
|
|
193
|
+
return [getMarkmap];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
webfontloader
|
|
198
|
+
],
|
|
199
|
+
styles
|
|
200
|
+
};
|
|
201
|
+
const plugin$1 = definePlugin({
|
|
202
|
+
name: name$2,
|
|
203
|
+
config,
|
|
204
|
+
transform(transformHooks) {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
let enableFeature = noop;
|
|
207
|
+
transformHooks.parser.tap((md) => {
|
|
208
|
+
md.use(remarkableKatex);
|
|
209
|
+
md.renderer.rules.katex = wrapFunction(
|
|
210
|
+
md.renderer.rules.katex,
|
|
211
|
+
(render, ...args) => {
|
|
212
|
+
enableFeature();
|
|
213
|
+
return render(...args);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
218
|
+
enableFeature = () => {
|
|
219
|
+
context.features[name$2] = true;
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
return {
|
|
223
|
+
styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
|
|
224
|
+
scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
const katex = plugin$1;
|
|
229
|
+
const name$1 = "npmUrl";
|
|
230
|
+
const npmUrl = definePlugin({
|
|
231
|
+
name: name$1,
|
|
232
|
+
transform(transformHooks) {
|
|
233
|
+
transformHooks.afterParse.tap((_, context) => {
|
|
234
|
+
const { frontmatter: frontmatter2 } = context;
|
|
235
|
+
const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
|
|
236
|
+
if (markmap) {
|
|
237
|
+
["extraJs", "extraCss"].forEach((key) => {
|
|
238
|
+
const value = markmap[key];
|
|
239
|
+
if (value) {
|
|
240
|
+
markmap[key] = value.map((path) => {
|
|
241
|
+
if (path.startsWith("npm:")) {
|
|
242
|
+
return transformHooks.transformer.urlBuilder.getFullUrl(
|
|
243
|
+
path.slice(4)
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
return path;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
return {};
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
const name = "sourceLines";
|
|
256
|
+
const plugin = definePlugin({
|
|
257
|
+
name,
|
|
258
|
+
transform(transformHooks) {
|
|
259
|
+
transformHooks.parser.tap((md) => {
|
|
260
|
+
Object.entries(md.renderer.rules).forEach(([key, value]) => {
|
|
261
|
+
if (typeof value === "function") {
|
|
262
|
+
md.renderer.rules[key] = patchRule(value);
|
|
263
|
+
} else {
|
|
264
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
265
|
+
value[k] = patchRule(v);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
return {};
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
function patchRule(rule, _key) {
|
|
274
|
+
return wrapFunction(rule, (render, tokens, idx, ...rest) => {
|
|
275
|
+
let html = render(tokens, idx, ...rest);
|
|
276
|
+
const { lines } = tokens[idx];
|
|
277
|
+
if (lines) {
|
|
278
|
+
html = html.replace(
|
|
279
|
+
/^<[\w-]+/,
|
|
280
|
+
(m) => `${m} data-lines="${lines.join(",")}"`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
return html;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
const sourceLines = plugin;
|
|
287
|
+
const plugins = [
|
|
288
|
+
frontmatter,
|
|
289
|
+
katex,
|
|
290
|
+
hljs,
|
|
291
|
+
npmUrl,
|
|
292
|
+
checkbox,
|
|
293
|
+
sourceLines
|
|
294
|
+
];
|
|
295
|
+
export {
|
|
296
|
+
createTransformHooks,
|
|
297
|
+
definePlugin,
|
|
298
|
+
plugins
|
|
299
|
+
};
|
package/dist/transform.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { IMarkmapOptions, IPureNode, JSItem, UrlBuilder } from 'markmap-common';
|
|
2
2
|
import { IHtmlParserOptions } from 'markmap-html-parser';
|
|
3
3
|
import { Remarkable } from 'remarkable';
|
|
4
|
-
import { plugins as builtInPlugins } from './plugins';
|
|
5
4
|
import { IAssets, IFeatures, ITransformHooks, ITransformPlugin, ITransformResult, ITransformer, IMarkmapJSONOptions } from './types';
|
|
6
|
-
export
|
|
5
|
+
export declare const builtInPlugins: ITransformPlugin[];
|
|
7
6
|
export declare class Transformer implements ITransformer {
|
|
8
7
|
hooks: ITransformHooks;
|
|
9
8
|
md: Remarkable;
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-lib",
|
|
3
|
-
"version": "0.15.9-alpha.
|
|
3
|
+
"version": "0.15.9-alpha.11+d60da2f",
|
|
4
4
|
"description": "Visualize your Markdown as mindmaps with Markmap",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"clean": "del-cli dist",
|
|
9
9
|
"build:types": "tsc",
|
|
10
|
-
"build:js": "vite build && TARGET=
|
|
10
|
+
"build:js": "vite build && TARGET=nodeLight vite build && TARGET=browserEs vite build && TARGET=browserJs vite build",
|
|
11
|
+
"build": "run-s clean build:*",
|
|
11
12
|
"test": "jest test"
|
|
12
13
|
},
|
|
13
14
|
"publishConfig": {
|
|
14
15
|
"access": "public",
|
|
15
16
|
"registry": "https://registry.npmjs.org/"
|
|
16
17
|
},
|
|
18
|
+
"sideEffects": false,
|
|
17
19
|
"main": "dist/index.js",
|
|
18
20
|
"module": "dist/index.mjs",
|
|
19
21
|
"unpkg": "dist/browser/index.iife.js",
|
|
@@ -25,6 +27,16 @@
|
|
|
25
27
|
"require": "./dist/index.js",
|
|
26
28
|
"default": "./dist/index.mjs"
|
|
27
29
|
},
|
|
30
|
+
"./plugins": {
|
|
31
|
+
"types": "./dist/plugins/index.d.ts",
|
|
32
|
+
"require": "./dist/plugins.js",
|
|
33
|
+
"default": "./dist/plugins.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./no-plugins": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"require": "./dist/index.no-plugins.js",
|
|
38
|
+
"default": "./dist/index.no-plugins.mjs"
|
|
39
|
+
},
|
|
28
40
|
"./package.json": "./package.json"
|
|
29
41
|
},
|
|
30
42
|
"types": "dist/index.d.ts",
|
|
@@ -47,8 +59,8 @@
|
|
|
47
59
|
"devDependencies": {
|
|
48
60
|
"@highlightjs/cdn-assets": "^11.8.0",
|
|
49
61
|
"@types/remarkable": "^2.0.3",
|
|
50
|
-
"markmap-common": "0.15.9-alpha.
|
|
51
|
-
"markmap-view": "0.15.9-alpha.
|
|
62
|
+
"markmap-common": "0.15.9-alpha.11+d60da2f",
|
|
63
|
+
"markmap-view": "0.15.9-alpha.11+d60da2f",
|
|
52
64
|
"webfontloader": "^1.6.28"
|
|
53
65
|
},
|
|
54
66
|
"dependencies": {
|
|
@@ -56,7 +68,7 @@
|
|
|
56
68
|
"highlight.js": "^11.8.0",
|
|
57
69
|
"js-yaml": "^4.1.0",
|
|
58
70
|
"katex": "^0.16.8",
|
|
59
|
-
"markmap-html-parser": "0.15.9-alpha.
|
|
71
|
+
"markmap-html-parser": "0.15.9-alpha.11+d60da2f",
|
|
60
72
|
"prismjs": "^1.29.0",
|
|
61
73
|
"remarkable": "^2.0.1",
|
|
62
74
|
"remarkable-katex": "^1.2.1"
|
|
@@ -74,5 +86,5 @@
|
|
|
74
86
|
]
|
|
75
87
|
}
|
|
76
88
|
},
|
|
77
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "d60da2fb13a85edec875ef002f1be414a0c00abe"
|
|
78
90
|
}
|
package/dist/plugins/hljs.d.ts
DELETED
package/dist/plugins/katex.d.ts
DELETED