@commentray/render 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/LICENSE +373 -0
- package/README.md +28 -0
- package/dist/code-browser-client.bundle.js +5 -0
- package/dist/code-browser-client.d.ts +2 -0
- package/dist/code-browser-client.d.ts.map +1 -0
- package/dist/code-browser-client.js +252 -0
- package/dist/code-browser-client.js.map +1 -0
- package/dist/code-browser-search.d.ts +17 -0
- package/dist/code-browser-search.d.ts.map +1 -0
- package/dist/code-browser-search.js +60 -0
- package/dist/code-browser-search.js.map +1 -0
- package/dist/code-browser.d.ts +18 -0
- package/dist/code-browser.d.ts.map +1 -0
- package/dist/code-browser.js +241 -0
- package/dist/code-browser.js.map +1 -0
- package/dist/html-utils.d.ts +3 -0
- package/dist/html-utils.d.ts.map +1 -0
- package/dist/html-utils.js +10 -0
- package/dist/html-utils.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown-pipeline.d.ts +3 -0
- package/dist/markdown-pipeline.d.ts.map +1 -0
- package/dist/markdown-pipeline.js +47 -0
- package/dist/markdown-pipeline.js.map +1 -0
- package/dist/side-by-side.d.ts +13 -0
- package/dist/side-by-side.d.ts.map +1 -0
- package/dist/side-by-side.js +50 -0
- package/dist/side-by-side.js.map +1 -0
- package/package.json +43 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { renderCodeBrowserHtml } from "./code-browser.js";
|
|
2
|
+
export type { CodeBrowserPageOptions } from "./code-browser.js";
|
|
3
|
+
export { renderFencedCode, renderMarkdownToHtml } from "./markdown-pipeline.js";
|
|
4
|
+
export { renderSideBySideHtml } from "./side-by-side.js";
|
|
5
|
+
export type { SideBySideOptions } from "./side-by-side.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-pipeline.d.ts","sourceRoot":"","sources":["../src/markdown-pipeline.ts"],"names":[],"mappings":"AAsCA,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAW5E;AAED,wBAAsB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE7E"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import rehypeHighlight from "rehype-highlight";
|
|
2
|
+
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
|
|
3
|
+
import rehypeStringify from "rehype-stringify";
|
|
4
|
+
import remarkGfm from "remark-gfm";
|
|
5
|
+
import remarkParse from "remark-parse";
|
|
6
|
+
import remarkRehype from "remark-rehype";
|
|
7
|
+
import { unified } from "unified";
|
|
8
|
+
import { visit } from "unist-util-visit";
|
|
9
|
+
import { escapeHtml } from "./html-utils.js";
|
|
10
|
+
function remarkMermaidPlaceholders() {
|
|
11
|
+
return (tree) => {
|
|
12
|
+
visit(tree, "code", (node, index, parent) => {
|
|
13
|
+
if (node.lang !== "mermaid" || parent === undefined || index === undefined)
|
|
14
|
+
return;
|
|
15
|
+
const value = node.value;
|
|
16
|
+
const html = {
|
|
17
|
+
type: "html",
|
|
18
|
+
value: `<div class="commentray-mermaid"><pre class="mermaid"><code>${escapeHtml(value)}</code></pre></div>`,
|
|
19
|
+
};
|
|
20
|
+
parent.children[index] = html;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const sanitizeSchema = structuredClone(defaultSchema);
|
|
25
|
+
sanitizeSchema.attributes = {
|
|
26
|
+
...sanitizeSchema.attributes,
|
|
27
|
+
code: [...(sanitizeSchema.attributes?.code ?? []), "className"],
|
|
28
|
+
pre: [...(sanitizeSchema.attributes?.pre ?? []), "className"],
|
|
29
|
+
span: [...(sanitizeSchema.attributes?.span ?? []), "className"],
|
|
30
|
+
div: ["className"],
|
|
31
|
+
};
|
|
32
|
+
export async function renderMarkdownToHtml(markdown) {
|
|
33
|
+
const file = await unified()
|
|
34
|
+
.use(remarkParse)
|
|
35
|
+
.use(remarkGfm)
|
|
36
|
+
.use(remarkMermaidPlaceholders)
|
|
37
|
+
.use(remarkRehype, { allowDangerousHtml: true })
|
|
38
|
+
.use(rehypeSanitize, sanitizeSchema)
|
|
39
|
+
.use(rehypeHighlight)
|
|
40
|
+
.use(rehypeStringify)
|
|
41
|
+
.process(markdown);
|
|
42
|
+
return String(file);
|
|
43
|
+
}
|
|
44
|
+
export async function renderFencedCode(markdownFence) {
|
|
45
|
+
return renderMarkdownToHtml(markdownFence);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=markdown-pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-pipeline.js","sourceRoot":"","sources":["../src/markdown-pipeline.ts"],"names":[],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,EAAE,CAAC,EAAE,WAAW,CAAC;IAC7D,IAAI,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,EAAE,WAAW,CAAC;IAC/D,GAAG,EAAE,CAAC,WAAW,CAAC;CACnB,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,QAAgB;IACzD,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE;SACzB,GAAG,CAAC,WAAW,CAAC;SAChB,GAAG,CAAC,SAAS,CAAC;SACd,GAAG,CAAC,yBAAyB,CAAC;SAC9B,GAAG,CAAC,YAAY,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC;SAC/C,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC;SACnC,GAAG,CAAC,eAAe,CAAC;SACpB,GAAG,CAAC,eAAe,CAAC;SACpB,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,aAAqB;IAC1D,OAAO,oBAAoB,CAAC,aAAa,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SideBySideOptions = {
|
|
2
|
+
title?: string;
|
|
3
|
+
/** Source code text (not yet fenced). */
|
|
4
|
+
code: string;
|
|
5
|
+
/** Highlight.js / common language id, e.g. ts, go, json */
|
|
6
|
+
language: string;
|
|
7
|
+
/** Commentray markdown body. */
|
|
8
|
+
commentrayMarkdown: string;
|
|
9
|
+
/** When true, include Mermaid runtime from CDN in the footer. */
|
|
10
|
+
includeMermaidRuntime?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function renderSideBySideHtml(opts: SideBySideOptions): Promise<string>;
|
|
13
|
+
//# sourceMappingURL=side-by-side.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"side-by-side.d.ts","sourceRoot":"","sources":["../src/side-by-side.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iEAAiE;IACjE,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiDnF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { escapeHtml } from "./html-utils.js";
|
|
2
|
+
import { renderFencedCode, renderMarkdownToHtml } from "./markdown-pipeline.js";
|
|
3
|
+
export async function renderSideBySideHtml(opts) {
|
|
4
|
+
const fence = "```" + opts.language + "\n" + opts.code + "\n```\n";
|
|
5
|
+
const [codeHtml, commentrayHtml] = await Promise.all([
|
|
6
|
+
renderFencedCode(fence),
|
|
7
|
+
renderMarkdownToHtml(opts.commentrayMarkdown),
|
|
8
|
+
]);
|
|
9
|
+
const mermaidScript = opts.includeMermaidRuntime
|
|
10
|
+
? `<script type="module">
|
|
11
|
+
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs";
|
|
12
|
+
mermaid.initialize({ startOnLoad: true, securityLevel: "strict" });
|
|
13
|
+
mermaid.run({ querySelector: ".mermaid" });
|
|
14
|
+
</script>`
|
|
15
|
+
: "";
|
|
16
|
+
const title = opts.title ?? "Commentray";
|
|
17
|
+
return `<!doctype html>
|
|
18
|
+
<html lang="en">
|
|
19
|
+
<head>
|
|
20
|
+
<meta charset="utf-8" />
|
|
21
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
22
|
+
<title>${escapeHtml(title)}</title>
|
|
23
|
+
<style>
|
|
24
|
+
:root { color-scheme: light dark; }
|
|
25
|
+
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
|
|
26
|
+
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 100vh; }
|
|
27
|
+
.pane { overflow: auto; padding: 16px; border-right: 1px solid color-mix(in oklab, CanvasText 20%, Canvas); }
|
|
28
|
+
.pane:last-child { border-right: none; }
|
|
29
|
+
.pane h2 { margin-top: 0; font-size: 14px; letter-spacing: 0.02em; text-transform: uppercase; opacity: 0.8; }
|
|
30
|
+
pre { margin: 0; }
|
|
31
|
+
.commentray { font-size: 15px; line-height: 1.45; }
|
|
32
|
+
.commentray img { max-width: 100%; height: auto; }
|
|
33
|
+
</style>
|
|
34
|
+
</head>
|
|
35
|
+
<body>
|
|
36
|
+
<div class="layout">
|
|
37
|
+
<section class="pane" aria-label="Source">
|
|
38
|
+
<h2>Code</h2>
|
|
39
|
+
${codeHtml}
|
|
40
|
+
</section>
|
|
41
|
+
<section class="pane commentray" aria-label="Commentray">
|
|
42
|
+
<h2>Commentray</h2>
|
|
43
|
+
${commentrayHtml}
|
|
44
|
+
</section>
|
|
45
|
+
</div>
|
|
46
|
+
${mermaidScript}
|
|
47
|
+
</body>
|
|
48
|
+
</html>`;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=side-by-side.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"side-by-side.js","sourceRoot":"","sources":["../src/side-by-side.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAchF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,IAAuB;IAChE,MAAM,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACnE,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,gBAAgB,CAAC,KAAK,CAAC;QACvB,oBAAoB,CAAC,IAAI,CAAC,kBAAkB,CAAC;KAC9C,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB;QAC9C,CAAC,CAAC;;;;UAII;QACN,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,YAAY,CAAC;IAEzC,OAAO;;;;;aAKI,UAAU,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;UAiBpB,QAAQ;;;;UAIR,cAAc;;;MAGlB,aAAa;;QAEX,CAAC;AACT,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commentray/render",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Markdown + syntax highlighting rendering for Commentray",
|
|
8
|
+
"license": "MPL-2.0",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.build.json && node esbuild-code-browser-client.mjs",
|
|
25
|
+
"clean": "rm -rf dist"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@m31coding/fuzzy-search": "^2.0.0",
|
|
29
|
+
"rehype-highlight": "^7.0.2",
|
|
30
|
+
"rehype-sanitize": "^6.0.0",
|
|
31
|
+
"rehype-stringify": "^10.0.1",
|
|
32
|
+
"remark-gfm": "^4.0.1",
|
|
33
|
+
"remark-parse": "^11.0.0",
|
|
34
|
+
"remark-rehype": "^11.1.2",
|
|
35
|
+
"unified": "^11.0.5",
|
|
36
|
+
"unist-util-visit": "^5.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/mdast": "^4.0.4",
|
|
40
|
+
"@types/node": "^22.14.1",
|
|
41
|
+
"esbuild": "^0.25.12"
|
|
42
|
+
}
|
|
43
|
+
}
|