@anlijiu/remark-markmap 1.0.1
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/LICENSE +21 -0
- package/dist/handlers.js +20 -0
- package/dist/index.js +1 -0
- package/dist/remark-markmap.js +80 -0
- package/dist/utils.js +25 -0
- package/package.json +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 anlijiu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/handlers.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
function inlineCode(state, node) {
|
|
4
|
+
const text = { type: "text", value: node.value.replace(/\r?\n|\r/g, " ") };
|
|
5
|
+
state.patch(node, text);
|
|
6
|
+
const result = {
|
|
7
|
+
type: "element",
|
|
8
|
+
tagName: "code",
|
|
9
|
+
properties: {
|
|
10
|
+
display: "inline"
|
|
11
|
+
},
|
|
12
|
+
children: [text]
|
|
13
|
+
};
|
|
14
|
+
state.patch(node, result);
|
|
15
|
+
return state.applyData(node, result);
|
|
16
|
+
}
|
|
17
|
+
__name(inlineCode, "inlineCode");
|
|
18
|
+
export {
|
|
19
|
+
inlineCode
|
|
20
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./remark-markmap.js";
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { fromHtmlIsomorphic } from "hast-util-from-html-isomorphic";
|
|
4
|
+
import {
|
|
5
|
+
createMarkmapRenderer
|
|
6
|
+
} from "@anlijiu/markmap-isomorphic";
|
|
7
|
+
import remarkGfm from "remark-gfm";
|
|
8
|
+
import remarkFrontmatter from "remark-frontmatter";
|
|
9
|
+
import remarkParse from "remark-parse";
|
|
10
|
+
import remarkMath from "remark-math";
|
|
11
|
+
import remarkRehype from "remark-rehype";
|
|
12
|
+
import matter from "gray-matter";
|
|
13
|
+
import rehypeMathjax from "rehype-mathjax";
|
|
14
|
+
import { unified } from "unified";
|
|
15
|
+
import { visit } from "unist-util-visit";
|
|
16
|
+
import { buildTree } from "@anlijiu/markmap";
|
|
17
|
+
import { inlineCode } from "./handlers.js";
|
|
18
|
+
import { objectValueToString } from "./utils.js";
|
|
19
|
+
const shikiConfig = {
|
|
20
|
+
langs: [],
|
|
21
|
+
theme: "github-dark",
|
|
22
|
+
themes: {},
|
|
23
|
+
wrap: false,
|
|
24
|
+
transformers: []
|
|
25
|
+
};
|
|
26
|
+
const parser = unified().use(remarkParse).use(remarkGfm).use(remarkFrontmatter, { type: "yaml", marker: "-" }).use(remarkMath).use(remarkRehype, {
|
|
27
|
+
allowDangerousHtml: true,
|
|
28
|
+
handlers: {
|
|
29
|
+
inlineCode
|
|
30
|
+
}
|
|
31
|
+
}).use(rehypeMathjax, {
|
|
32
|
+
svg: {
|
|
33
|
+
scale: 1.4
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
async function visitor(node, idx, parent, render) {
|
|
37
|
+
const totalSize = parent.children.length;
|
|
38
|
+
const nodeIndex = parent.children.indexOf(node);
|
|
39
|
+
const frontmatter = matter(node.value);
|
|
40
|
+
const { content, data, isEmpty, excerpt } = frontmatter;
|
|
41
|
+
const vfile = { value: content };
|
|
42
|
+
const tree = parser.parse(vfile);
|
|
43
|
+
const opts = objectValueToString(data);
|
|
44
|
+
let result = await parser.run(tree);
|
|
45
|
+
console.log("xxxx remark-markmap result: ", JSON.stringify(result, void 0, 2));
|
|
46
|
+
console.log("xxxx remark-markmap frontmatter : ", JSON.stringify(frontmatter, void 0, 2), ", opts:", JSON.stringify(opts, void 0, 2));
|
|
47
|
+
let mindmapTree = buildTree(result.children, opts);
|
|
48
|
+
let svgResults = await render(mindmapTree, opts);
|
|
49
|
+
let svgResult = svgResults[0];
|
|
50
|
+
if (svgResult.status === "fulfilled") {
|
|
51
|
+
let { svg } = svgResult.value;
|
|
52
|
+
console.log("remark-markmap visit svg: ", svg);
|
|
53
|
+
const hChildren = fromHtmlIsomorphic(svg, { fragment: true, space: "svg" }).children;
|
|
54
|
+
parent.children[nodeIndex] = {
|
|
55
|
+
type: "paragraph",
|
|
56
|
+
children: [{ type: "html", value: svg }],
|
|
57
|
+
data: { hChildren }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return node;
|
|
61
|
+
}
|
|
62
|
+
__name(visitor, "visitor");
|
|
63
|
+
const remarkMarkmap = /* @__PURE__ */ __name((options = {}) => {
|
|
64
|
+
const render = createMarkmapRenderer(options);
|
|
65
|
+
return /* @__PURE__ */ __name(async function transformer(ast, file) {
|
|
66
|
+
console.log("ast: ", JSON.stringify(ast, void 0, 2));
|
|
67
|
+
const matches = [];
|
|
68
|
+
visit(ast, { type: "code", lang: "markmap" }, (...args) => {
|
|
69
|
+
matches.push([...args, render]);
|
|
70
|
+
});
|
|
71
|
+
const promises = matches.map((match) => visitor(...match));
|
|
72
|
+
await Promise.all(promises);
|
|
73
|
+
return ast;
|
|
74
|
+
}, "transformer");
|
|
75
|
+
}, "remarkMarkmap");
|
|
76
|
+
var remark_markmap_default = remarkMarkmap;
|
|
77
|
+
export {
|
|
78
|
+
remark_markmap_default as default,
|
|
79
|
+
remarkMarkmap
|
|
80
|
+
};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const regexp = /((?<k1>(?!=)\S+)=((?<v1>(["'`])(.*?)\5)|(?<v2>\S+)))|(?<k2>\S+)/g;
|
|
4
|
+
const mapToObject = /* @__PURE__ */ __name((map) => Object.fromEntries(map.entries()), "mapToObject");
|
|
5
|
+
function parseMeta(str) {
|
|
6
|
+
const io = (str ?? "").matchAll(regexp);
|
|
7
|
+
return mapToObject(new Map(
|
|
8
|
+
[...io].map((item) => item?.groups).map(({ k1, k2, v1, v2 }) => [k1 ?? k2, v1 ?? v2])
|
|
9
|
+
));
|
|
10
|
+
}
|
|
11
|
+
__name(parseMeta, "parseMeta");
|
|
12
|
+
function objectValueToString(o) {
|
|
13
|
+
Object.keys(o).forEach((k) => {
|
|
14
|
+
if (typeof o[k] === "object") {
|
|
15
|
+
return toString(o[k]);
|
|
16
|
+
}
|
|
17
|
+
o[k] = "" + o[k];
|
|
18
|
+
});
|
|
19
|
+
return o;
|
|
20
|
+
}
|
|
21
|
+
__name(objectValueToString, "objectValueToString");
|
|
22
|
+
export {
|
|
23
|
+
objectValueToString,
|
|
24
|
+
parseMeta
|
|
25
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@anlijiu/remark-markmap",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A code library for render markmap to svg",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"author": "anlijiu@gmail.com",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"wireit": {
|
|
11
|
+
"start": {
|
|
12
|
+
"command": "node ./dist",
|
|
13
|
+
"dependencies": [
|
|
14
|
+
"script:build",
|
|
15
|
+
"build"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"dev": {
|
|
19
|
+
"command": "node scripts/build.mjs -d",
|
|
20
|
+
"dependencies": [
|
|
21
|
+
"script:build",
|
|
22
|
+
"build"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"build": {
|
|
26
|
+
"command": "node scripts/build.mjs",
|
|
27
|
+
"dependencies": [
|
|
28
|
+
"script:build"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"build:watch": {
|
|
32
|
+
"command": "node scripts/build.mjs -w",
|
|
33
|
+
"dependencies": [
|
|
34
|
+
"script:build"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"script:build": {
|
|
38
|
+
"command": "esbuild scripts/*.mts --outdir=scripts --target=node18 --supported:top-level-await=true --out-extension:.js=.mjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/cytoscape": "^3.21.9",
|
|
43
|
+
"@types/d3-selection": "^3.0.11",
|
|
44
|
+
"@types/jest": "^29.5.14",
|
|
45
|
+
"@types/lodash": "^4.17.5",
|
|
46
|
+
"@types/lodash.uppercase": "^4.3.9",
|
|
47
|
+
"@types/node": "^20.14.5",
|
|
48
|
+
"@types/nodemon": "^1.19.6",
|
|
49
|
+
"esbuild": "^0.25.5",
|
|
50
|
+
"esbuild-node-externals": "^1.18.0",
|
|
51
|
+
"jest": "^29.7.0",
|
|
52
|
+
"nodemon": "^3.1.3",
|
|
53
|
+
"rimraf": "^5.0.7",
|
|
54
|
+
"ts-jest": "^29.1.5",
|
|
55
|
+
"typescript": "^5.8.3",
|
|
56
|
+
"wireit": "^0.14.12"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@astrojs/markdown-remark": "^6.3.2",
|
|
60
|
+
"cytoscape": "^3.32.0",
|
|
61
|
+
"cytoscape-cose-bilkent": "^4.1.0",
|
|
62
|
+
"d3-selection": "^3.0.0",
|
|
63
|
+
"dompurify": "^3.2.6",
|
|
64
|
+
"gray-matter": "^4.0.3",
|
|
65
|
+
"hast-util-from-html-isomorphic": "^2.0.0",
|
|
66
|
+
"hast-util-to-html": "^9.0.5",
|
|
67
|
+
"hast-util-to-text": "^4.0.2",
|
|
68
|
+
"playwright-core": "^1.52.0",
|
|
69
|
+
"rehype-katex": "^7.0.1",
|
|
70
|
+
"rehype-mathjax": "^7.1.0",
|
|
71
|
+
"remark-frontmatter": "^5.0.0",
|
|
72
|
+
"remark-gfm": "^4.0.1",
|
|
73
|
+
"remark-math": "^6.0.0",
|
|
74
|
+
"remark-parse": "^11.0.0",
|
|
75
|
+
"remark-rehype": "^11.1.2",
|
|
76
|
+
"unified": "^11.0.5",
|
|
77
|
+
"unist-util-visit": "^5.0.0",
|
|
78
|
+
"vfile": "^6.0.3",
|
|
79
|
+
"@anlijiu/markmap-isomorphic": "1.0.1",
|
|
80
|
+
"@anlijiu/markmap": "1.0.1"
|
|
81
|
+
},
|
|
82
|
+
"repository": {
|
|
83
|
+
"type": "git",
|
|
84
|
+
"url": "https://github.com/anlijiu/remark-markmap.git"
|
|
85
|
+
},
|
|
86
|
+
"scripts": {
|
|
87
|
+
"start": "wireit",
|
|
88
|
+
"dev": "wireit",
|
|
89
|
+
"build": "wireit",
|
|
90
|
+
"build:watch": "wireit",
|
|
91
|
+
"script:build": "wireit",
|
|
92
|
+
"test": "jest",
|
|
93
|
+
"test:watch": "jest --watch",
|
|
94
|
+
"clean": "rimraf dist coverage .wireit dist scripts/build.mjs node_modules"
|
|
95
|
+
}
|
|
96
|
+
}
|