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
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const markmapCommon = require("markmap-common");
|
|
4
|
+
const markmapHtmlParser = require("markmap-html-parser");
|
|
5
|
+
const remarkable = require("remarkable");
|
|
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
|
+
const baseJsPaths = [
|
|
8
|
+
`d3@${"7.8.5"}/dist/d3.min.js`,
|
|
9
|
+
`markmap-view@${"0.15.8"}/dist/browser/index.js`
|
|
10
|
+
];
|
|
11
|
+
function createTransformHooks(transformer) {
|
|
12
|
+
return {
|
|
13
|
+
transformer,
|
|
14
|
+
parser: new markmapCommon.Hook(),
|
|
15
|
+
beforeParse: new markmapCommon.Hook(),
|
|
16
|
+
afterParse: new markmapCommon.Hook(),
|
|
17
|
+
htmltag: new markmapCommon.Hook(),
|
|
18
|
+
retransform: new markmapCommon.Hook()
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function patchJSItem(urlBuilder, item) {
|
|
22
|
+
if (item.type === "script" && item.data.src) {
|
|
23
|
+
return {
|
|
24
|
+
...item,
|
|
25
|
+
data: {
|
|
26
|
+
...item.data,
|
|
27
|
+
src: urlBuilder.getFullUrl(item.data.src)
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return item;
|
|
32
|
+
}
|
|
33
|
+
function patchCSSItem(urlBuilder, item) {
|
|
34
|
+
if (item.type === "stylesheet" && item.data.href) {
|
|
35
|
+
return {
|
|
36
|
+
...item,
|
|
37
|
+
data: {
|
|
38
|
+
...item.data,
|
|
39
|
+
href: urlBuilder.getFullUrl(item.data.href)
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return item;
|
|
44
|
+
}
|
|
45
|
+
const builtInPlugins = [];
|
|
46
|
+
function cleanNode(node) {
|
|
47
|
+
while (!node.content && node.children.length === 1) {
|
|
48
|
+
node = node.children[0];
|
|
49
|
+
}
|
|
50
|
+
while (node.children.length === 1 && !node.children[0].content) {
|
|
51
|
+
node = {
|
|
52
|
+
...node,
|
|
53
|
+
children: node.children[0].children
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
...node,
|
|
58
|
+
children: node.children.map(cleanNode)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
class Transformer {
|
|
62
|
+
constructor(plugins = builtInPlugins) {
|
|
63
|
+
this.assetsMap = {};
|
|
64
|
+
this.urlBuilder = new markmapCommon.UrlBuilder();
|
|
65
|
+
this.hooks = createTransformHooks(this);
|
|
66
|
+
this.plugins = plugins.map(
|
|
67
|
+
(plugin) => typeof plugin === "function" ? plugin() : plugin
|
|
68
|
+
);
|
|
69
|
+
const assetsMap = {};
|
|
70
|
+
for (const { name, transform } of this.plugins) {
|
|
71
|
+
assetsMap[name] = transform(this.hooks);
|
|
72
|
+
}
|
|
73
|
+
this.assetsMap = assetsMap;
|
|
74
|
+
const md = new remarkable.Remarkable("full", {
|
|
75
|
+
html: true,
|
|
76
|
+
breaks: true,
|
|
77
|
+
maxNesting: Infinity
|
|
78
|
+
});
|
|
79
|
+
md.renderer.rules.htmltag = markmapCommon.wrapFunction(
|
|
80
|
+
md.renderer.rules.htmltag,
|
|
81
|
+
(render, ...args) => {
|
|
82
|
+
const result = render(...args);
|
|
83
|
+
this.hooks.htmltag.call({ args, result });
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
this.md = md;
|
|
88
|
+
this.hooks.parser.call(md);
|
|
89
|
+
}
|
|
90
|
+
transform(content, opts) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const context = {
|
|
93
|
+
content,
|
|
94
|
+
features: {},
|
|
95
|
+
contentLineOffset: 0
|
|
96
|
+
};
|
|
97
|
+
this.hooks.beforeParse.call(this.md, context);
|
|
98
|
+
const html = this.md.render(context.content, {});
|
|
99
|
+
this.hooks.afterParse.call(this.md, context);
|
|
100
|
+
const root = cleanNode(
|
|
101
|
+
markmapHtmlParser.buildTree(html, {
|
|
102
|
+
...(_b = (_a = context.frontmatter) == null ? void 0 : _a.markmap) == null ? void 0 : _b.htmlParser,
|
|
103
|
+
...opts
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
return { ...context, root };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get all assets from enabled plugins or filter them by plugin names as keys.
|
|
110
|
+
*/
|
|
111
|
+
getAssets(keys) {
|
|
112
|
+
const styles = [];
|
|
113
|
+
const scripts = [];
|
|
114
|
+
keys ?? (keys = this.plugins.map((plugin) => plugin.name));
|
|
115
|
+
for (const assets of keys.map((key) => this.assetsMap[key])) {
|
|
116
|
+
if (assets) {
|
|
117
|
+
if (assets.styles)
|
|
118
|
+
styles.push(...assets.styles);
|
|
119
|
+
if (assets.scripts)
|
|
120
|
+
scripts.push(...assets.scripts);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
styles: styles.map((item) => patchCSSItem(this.urlBuilder, item)),
|
|
125
|
+
scripts: scripts.map((item) => patchJSItem(this.urlBuilder, item))
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get used assets by features object returned by `transform`.
|
|
130
|
+
*/
|
|
131
|
+
getUsedAssets(features) {
|
|
132
|
+
const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
|
|
133
|
+
return this.getAssets(keys);
|
|
134
|
+
}
|
|
135
|
+
fillTemplate(root, assets, extra) {
|
|
136
|
+
extra = {
|
|
137
|
+
...extra
|
|
138
|
+
};
|
|
139
|
+
extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => markmapCommon.buildJSItem(path)));
|
|
140
|
+
const { scripts, styles } = assets;
|
|
141
|
+
const cssList = [...styles ? markmapCommon.persistCSS(styles) : []];
|
|
142
|
+
const context = {
|
|
143
|
+
getMarkmap: () => window.markmap,
|
|
144
|
+
getOptions: extra.getOptions,
|
|
145
|
+
jsonOptions: extra.jsonOptions,
|
|
146
|
+
root
|
|
147
|
+
};
|
|
148
|
+
const jsList = [
|
|
149
|
+
...markmapCommon.persistJS(
|
|
150
|
+
[
|
|
151
|
+
...extra.baseJs,
|
|
152
|
+
...scripts || [],
|
|
153
|
+
{
|
|
154
|
+
type: "iife",
|
|
155
|
+
data: {
|
|
156
|
+
fn: (getMarkmap, getOptions, root2, jsonOptions) => {
|
|
157
|
+
const markmap = getMarkmap();
|
|
158
|
+
window.mm = markmap.Markmap.create(
|
|
159
|
+
"svg#mindmap",
|
|
160
|
+
(getOptions || markmap.deriveOptions)(jsonOptions),
|
|
161
|
+
root2
|
|
162
|
+
);
|
|
163
|
+
},
|
|
164
|
+
getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
|
|
165
|
+
return [getMarkmap, getOptions, root2, jsonOptions];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
context
|
|
171
|
+
)
|
|
172
|
+
];
|
|
173
|
+
const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
|
|
174
|
+
return html;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const transformerVersions = {
|
|
178
|
+
"markmap-lib": "process.env.VERSION",
|
|
179
|
+
d3: "7.8.5"
|
|
180
|
+
};
|
|
181
|
+
exports.Transformer = Transformer;
|
|
182
|
+
exports.baseJsPaths = baseJsPaths;
|
|
183
|
+
exports.builtInPlugins = builtInPlugins;
|
|
184
|
+
exports.template = template;
|
|
185
|
+
exports.transformerVersions = transformerVersions;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { Hook, UrlBuilder, wrapFunction, buildJSItem, persistCSS, persistJS } from "markmap-common";
|
|
2
|
+
import { buildTree } from "markmap-html-parser";
|
|
3
|
+
import { Remarkable } from "remarkable";
|
|
4
|
+
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';
|
|
5
|
+
const baseJsPaths = [
|
|
6
|
+
`d3@${"7.8.5"}/dist/d3.min.js`,
|
|
7
|
+
`markmap-view@${"0.15.8"}/dist/browser/index.js`
|
|
8
|
+
];
|
|
9
|
+
function createTransformHooks(transformer) {
|
|
10
|
+
return {
|
|
11
|
+
transformer,
|
|
12
|
+
parser: new Hook(),
|
|
13
|
+
beforeParse: new Hook(),
|
|
14
|
+
afterParse: new Hook(),
|
|
15
|
+
htmltag: new Hook(),
|
|
16
|
+
retransform: new Hook()
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function patchJSItem(urlBuilder, item) {
|
|
20
|
+
if (item.type === "script" && item.data.src) {
|
|
21
|
+
return {
|
|
22
|
+
...item,
|
|
23
|
+
data: {
|
|
24
|
+
...item.data,
|
|
25
|
+
src: urlBuilder.getFullUrl(item.data.src)
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return item;
|
|
30
|
+
}
|
|
31
|
+
function patchCSSItem(urlBuilder, item) {
|
|
32
|
+
if (item.type === "stylesheet" && item.data.href) {
|
|
33
|
+
return {
|
|
34
|
+
...item,
|
|
35
|
+
data: {
|
|
36
|
+
...item.data,
|
|
37
|
+
href: urlBuilder.getFullUrl(item.data.href)
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return item;
|
|
42
|
+
}
|
|
43
|
+
const builtInPlugins = [];
|
|
44
|
+
function cleanNode(node) {
|
|
45
|
+
while (!node.content && node.children.length === 1) {
|
|
46
|
+
node = node.children[0];
|
|
47
|
+
}
|
|
48
|
+
while (node.children.length === 1 && !node.children[0].content) {
|
|
49
|
+
node = {
|
|
50
|
+
...node,
|
|
51
|
+
children: node.children[0].children
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
...node,
|
|
56
|
+
children: node.children.map(cleanNode)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
class Transformer {
|
|
60
|
+
constructor(plugins = builtInPlugins) {
|
|
61
|
+
this.assetsMap = {};
|
|
62
|
+
this.urlBuilder = new UrlBuilder();
|
|
63
|
+
this.hooks = createTransformHooks(this);
|
|
64
|
+
this.plugins = plugins.map(
|
|
65
|
+
(plugin) => typeof plugin === "function" ? plugin() : plugin
|
|
66
|
+
);
|
|
67
|
+
const assetsMap = {};
|
|
68
|
+
for (const { name, transform } of this.plugins) {
|
|
69
|
+
assetsMap[name] = transform(this.hooks);
|
|
70
|
+
}
|
|
71
|
+
this.assetsMap = assetsMap;
|
|
72
|
+
const md = new Remarkable("full", {
|
|
73
|
+
html: true,
|
|
74
|
+
breaks: true,
|
|
75
|
+
maxNesting: Infinity
|
|
76
|
+
});
|
|
77
|
+
md.renderer.rules.htmltag = wrapFunction(
|
|
78
|
+
md.renderer.rules.htmltag,
|
|
79
|
+
(render, ...args) => {
|
|
80
|
+
const result = render(...args);
|
|
81
|
+
this.hooks.htmltag.call({ args, result });
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
this.md = md;
|
|
86
|
+
this.hooks.parser.call(md);
|
|
87
|
+
}
|
|
88
|
+
transform(content, opts) {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
const context = {
|
|
91
|
+
content,
|
|
92
|
+
features: {},
|
|
93
|
+
contentLineOffset: 0
|
|
94
|
+
};
|
|
95
|
+
this.hooks.beforeParse.call(this.md, context);
|
|
96
|
+
const html = this.md.render(context.content, {});
|
|
97
|
+
this.hooks.afterParse.call(this.md, context);
|
|
98
|
+
const root = cleanNode(
|
|
99
|
+
buildTree(html, {
|
|
100
|
+
...(_b = (_a = context.frontmatter) == null ? void 0 : _a.markmap) == null ? void 0 : _b.htmlParser,
|
|
101
|
+
...opts
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
return { ...context, root };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get all assets from enabled plugins or filter them by plugin names as keys.
|
|
108
|
+
*/
|
|
109
|
+
getAssets(keys) {
|
|
110
|
+
const styles = [];
|
|
111
|
+
const scripts = [];
|
|
112
|
+
keys ?? (keys = this.plugins.map((plugin) => plugin.name));
|
|
113
|
+
for (const assets of keys.map((key) => this.assetsMap[key])) {
|
|
114
|
+
if (assets) {
|
|
115
|
+
if (assets.styles)
|
|
116
|
+
styles.push(...assets.styles);
|
|
117
|
+
if (assets.scripts)
|
|
118
|
+
scripts.push(...assets.scripts);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
styles: styles.map((item) => patchCSSItem(this.urlBuilder, item)),
|
|
123
|
+
scripts: scripts.map((item) => patchJSItem(this.urlBuilder, item))
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get used assets by features object returned by `transform`.
|
|
128
|
+
*/
|
|
129
|
+
getUsedAssets(features) {
|
|
130
|
+
const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
|
|
131
|
+
return this.getAssets(keys);
|
|
132
|
+
}
|
|
133
|
+
fillTemplate(root, assets, extra) {
|
|
134
|
+
extra = {
|
|
135
|
+
...extra
|
|
136
|
+
};
|
|
137
|
+
extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => buildJSItem(path)));
|
|
138
|
+
const { scripts, styles } = assets;
|
|
139
|
+
const cssList = [...styles ? persistCSS(styles) : []];
|
|
140
|
+
const context = {
|
|
141
|
+
getMarkmap: () => window.markmap,
|
|
142
|
+
getOptions: extra.getOptions,
|
|
143
|
+
jsonOptions: extra.jsonOptions,
|
|
144
|
+
root
|
|
145
|
+
};
|
|
146
|
+
const jsList = [
|
|
147
|
+
...persistJS(
|
|
148
|
+
[
|
|
149
|
+
...extra.baseJs,
|
|
150
|
+
...scripts || [],
|
|
151
|
+
{
|
|
152
|
+
type: "iife",
|
|
153
|
+
data: {
|
|
154
|
+
fn: (getMarkmap, getOptions, root2, jsonOptions) => {
|
|
155
|
+
const markmap = getMarkmap();
|
|
156
|
+
window.mm = markmap.Markmap.create(
|
|
157
|
+
"svg#mindmap",
|
|
158
|
+
(getOptions || markmap.deriveOptions)(jsonOptions),
|
|
159
|
+
root2
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
|
|
163
|
+
return [getMarkmap, getOptions, root2, jsonOptions];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
context
|
|
169
|
+
)
|
|
170
|
+
];
|
|
171
|
+
const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
|
|
172
|
+
return html;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const transformerVersions = {
|
|
176
|
+
"markmap-lib": "process.env.VERSION",
|
|
177
|
+
d3: "7.8.5"
|
|
178
|
+
};
|
|
179
|
+
export {
|
|
180
|
+
Transformer,
|
|
181
|
+
baseJsPaths,
|
|
182
|
+
builtInPlugins,
|
|
183
|
+
template,
|
|
184
|
+
transformerVersions
|
|
185
|
+
};
|