@gene-code/rehype 0.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/dist/index.d.ts +2 -0
- package/dist/index.js +35 -0
- package/package.json +49 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import { render } from "@gene-code/core";
|
|
3
|
+
import { fromHtml } from "hast-util-from-html";
|
|
4
|
+
import { visit } from "unist-util-visit";
|
|
5
|
+
function rawText(node) {
|
|
6
|
+
return node.children.map((child) => child.type === "text" ? child.value : "").join("");
|
|
7
|
+
}
|
|
8
|
+
function rehypeGeneCode() {
|
|
9
|
+
return (tree) => {
|
|
10
|
+
visit(tree, "element", (node, index, parent) => {
|
|
11
|
+
if (node.tagName !== "pre" || !parent || index == null)
|
|
12
|
+
return;
|
|
13
|
+
const code = node.children.find((c) => c.type === "element" && c.tagName === "code");
|
|
14
|
+
if (!code)
|
|
15
|
+
return;
|
|
16
|
+
const className = code.properties?.className;
|
|
17
|
+
const langs = Array.isArray(className) ? className : [];
|
|
18
|
+
if (!langs.includes("language-gene-code"))
|
|
19
|
+
return;
|
|
20
|
+
const svg = render(rawText(code));
|
|
21
|
+
if (!svg)
|
|
22
|
+
return;
|
|
23
|
+
const root = fromHtml(svg, { fragment: true, space: "svg" });
|
|
24
|
+
parent.children[index] = {
|
|
25
|
+
type: "element",
|
|
26
|
+
tagName: "figure",
|
|
27
|
+
properties: { className: ["gene-code"] },
|
|
28
|
+
children: root.children
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
rehypeGeneCode as default
|
|
35
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gene-code/rehype",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Rehype plugin that renders gene-code DSL code blocks into SVG diagrams.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/neznayer/gene-code.git",
|
|
9
|
+
"directory": "packages/rehype"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"rehype",
|
|
13
|
+
"rehype-plugin",
|
|
14
|
+
"unified",
|
|
15
|
+
"gene-code",
|
|
16
|
+
"diagram",
|
|
17
|
+
"svg"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "bun build ./index.ts --outdir dist --target node --format esm --external @gene-code/core --external hast-util-from-html --external unist-util-visit --external hast && tsc -p tsconfig.build.json",
|
|
35
|
+
"prepublishOnly": "bun run build"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@gene-code/core": "0.0.1",
|
|
39
|
+
"hast-util-from-html": "^2.0.3",
|
|
40
|
+
"unist-util-visit": "^5.1.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"rehype": ">=12"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/hast": "^3.0.4",
|
|
47
|
+
"typescript": "^5"
|
|
48
|
+
}
|
|
49
|
+
}
|