starlight-cannoli-plugins 2.1.8 → 2.1.9
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/{chunk-3ATSZG6H.js → chunk-IY4A67ZP.js} +7 -175
- package/dist/chunk-N2I2GJW3.js +238 -0
- package/dist/{chunk-KJ6KZOCD.js → chunk-WZNJ5VFU.js} +1 -1
- package/dist/{chunk-TTQY54Q6.js → chunk-XVMRLEQM.js} +113 -24
- package/dist/cpp-VZKLUKT7.js +1 -1
- package/dist/{erb-5EKNOWNJ.js → erb-WAGUANI2.js} +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -7
- package/dist/{just-DKAU2FPN.js → just-PYDV7ZQ7.js} +3 -3
- package/dist/plugins/astro-latex-compile.d.ts +3 -6
- package/dist/plugins/astro-latex-compile.js +3 -7
- package/dist/plugins/astro-sync-docs-to-public/page-script.js +9 -4
- package/dist/plugins/astro-sync-docs-to-public.js +2 -2
- package/dist/plugins/starlight-index-only-sidebar.js +2 -2
- package/dist/{rst-OXRHDCQE.js → rst-V6D7WWXH.js} +3 -3
- package/dist/{ruby-SUFBDHOR.js → ruby-QQFN2P53.js} +3 -3
- package/dist/styles/page-src-context-menu.scss +29 -0
- package/dist/{twig-BNCU37LV.js → twig-CHAFMQ5H.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-HDL4DZNT.js +0 -65
- package/dist/chunk-IX5UFISR.js +0 -149
- package/dist/cli/cannoli-latex-cleanup.d.ts +0 -1
- package/dist/cli/cannoli-latex-cleanup.js +0 -128
- package/dist/{blade-N26A55JB.js → blade-MNWQFAXA.js} +3 -3
- package/dist/{chunk-26NQJBXH.js → chunk-7DJE5LRN.js} +3 -3
- package/dist/{crystal-OIARPJAM.js → crystal-MYUTTSDY.js} +3 -3
- package/dist/{julia-T3UAQLFW.js → julia-VFJDJOWL.js} +3 -3
- package/dist/{ts-tags-DME2ZSNV.js → ts-tags-O77G7HGT.js} +1 -1
|
@@ -3,23 +3,23 @@ import {
|
|
|
3
3
|
} from "./chunk-Z2VUFOSG.js";
|
|
4
4
|
import {
|
|
5
5
|
ruby_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7DJE5LRN.js";
|
|
7
7
|
import "./chunk-ZSX4GOHC.js";
|
|
8
|
-
import "./chunk-NE25QJUZ.js";
|
|
9
8
|
import "./chunk-OII47WE4.js";
|
|
10
9
|
import "./chunk-76C5RMV7.js";
|
|
11
10
|
import "./chunk-S3SFQXYS.js";
|
|
11
|
+
import "./chunk-NE25QJUZ.js";
|
|
12
12
|
import "./chunk-ICUS267J.js";
|
|
13
13
|
import "./chunk-MT4FGOLU.js";
|
|
14
14
|
import "./chunk-YJV35WLF.js";
|
|
15
15
|
import {
|
|
16
16
|
shellscript_default
|
|
17
17
|
} from "./chunk-5TDK5Y5S.js";
|
|
18
|
-
import "./chunk-IWM27JZF.js";
|
|
19
18
|
import "./chunk-XOMTOLBK.js";
|
|
20
19
|
import {
|
|
21
20
|
python_default
|
|
22
21
|
} from "./chunk-QH2T6GYZ.js";
|
|
22
|
+
import "./chunk-IWM27JZF.js";
|
|
23
23
|
import {
|
|
24
24
|
typescript_default
|
|
25
25
|
} from "./chunk-VB3O6QM4.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Root
|
|
1
|
+
import { Root } from 'mdast';
|
|
2
2
|
import { VFile } from 'vfile';
|
|
3
|
-
import { Root } from 'hast';
|
|
4
3
|
|
|
5
4
|
interface CompilationResult {
|
|
6
5
|
hash: string;
|
|
@@ -17,8 +16,6 @@ interface CompilationResult {
|
|
|
17
16
|
*/
|
|
18
17
|
declare function compileLatexToSvg(latexCode: string, svgOutputDir: string): Promise<CompilationResult>;
|
|
19
18
|
|
|
20
|
-
declare function rehypeLatexCompile(): (tree: Root, _file: VFile) => void;
|
|
21
|
-
|
|
22
19
|
interface RemarkLatexCompileOptions {
|
|
23
20
|
/**
|
|
24
21
|
* Directory where SVG files should be written.
|
|
@@ -36,6 +33,6 @@ interface RemarkLatexCompileOptions {
|
|
|
36
33
|
*/
|
|
37
34
|
_fileHashMap?: Map<string, Set<string>>;
|
|
38
35
|
}
|
|
39
|
-
declare function remarkLatexCompile(options: RemarkLatexCompileOptions): (tree: Root
|
|
36
|
+
declare function remarkLatexCompile(options: RemarkLatexCompileOptions): (tree: Root, file: VFile) => Promise<void>;
|
|
40
37
|
|
|
41
|
-
export { type RemarkLatexCompileOptions, compileLatexToSvg, remarkLatexCompile as default
|
|
38
|
+
export { type RemarkLatexCompileOptions, compileLatexToSvg, remarkLatexCompile as default };
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
compileLatexToSvg,
|
|
3
3
|
remarkLatexCompile
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import {
|
|
6
|
-
compileLatexToSvg
|
|
7
|
-
} from "../chunk-TTQY54Q6.js";
|
|
4
|
+
} from "../chunk-XVMRLEQM.js";
|
|
8
5
|
import "../chunk-QGM4M3NI.js";
|
|
9
6
|
export {
|
|
10
7
|
compileLatexToSvg,
|
|
11
|
-
remarkLatexCompile as default
|
|
12
|
-
rehypeLatexCompile
|
|
8
|
+
remarkLatexCompile as default
|
|
13
9
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/plugins/astro-sync-docs-to-public/page-script.ts
|
|
2
|
-
function
|
|
2
|
+
function showBanner(message, variant) {
|
|
3
3
|
const banner = document.createElement("div");
|
|
4
|
-
banner.className =
|
|
4
|
+
banner.className = `page-src-banner page-src-banner--${variant}`;
|
|
5
5
|
banner.textContent = message;
|
|
6
6
|
document.body.appendChild(banner);
|
|
7
7
|
requestAnimationFrame(() => {
|
|
@@ -34,19 +34,24 @@ function createActionBar() {
|
|
|
34
34
|
const menuBtn = document.createElement("button");
|
|
35
35
|
menuBtn.className = "page-src-action-bar__btn";
|
|
36
36
|
menuBtn.textContent = "\u22EE";
|
|
37
|
+
function setLoading(loading) {
|
|
38
|
+
menuBtn.classList.toggle("page-src-action-bar__btn--loading", loading);
|
|
39
|
+
}
|
|
37
40
|
const menu = document.createElement("div");
|
|
38
41
|
menu.className = "page-src-action-bar__menu";
|
|
39
42
|
const menuItems = [
|
|
40
43
|
{
|
|
41
44
|
label: "Copy Page",
|
|
42
45
|
action: () => {
|
|
43
|
-
|
|
46
|
+
setLoading(true);
|
|
47
|
+
getRawMdUrl().then((url) => fetch(url)).then((resp) => resp.text()).then((text) => navigator.clipboard.writeText(text)).then(() => showBanner("Page source copied to clipboard!", "success")).catch(() => showBanner("Failed to copy page source.", "error")).finally(() => setLoading(false));
|
|
44
48
|
}
|
|
45
49
|
},
|
|
46
50
|
{
|
|
47
51
|
label: "View raw",
|
|
48
52
|
action: () => {
|
|
49
|
-
|
|
53
|
+
setLoading(true);
|
|
54
|
+
getRawMdUrl().then((url) => window.open(url, "_blank")).catch(() => showBanner("Failed to open raw source.", "error")).finally(() => setLoading(false));
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ruby_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7DJE5LRN.js";
|
|
4
4
|
import "./chunk-ZSX4GOHC.js";
|
|
5
|
-
import "./chunk-NE25QJUZ.js";
|
|
6
5
|
import "./chunk-OII47WE4.js";
|
|
7
6
|
import {
|
|
8
7
|
yaml_default
|
|
9
8
|
} from "./chunk-76C5RMV7.js";
|
|
10
9
|
import "./chunk-S3SFQXYS.js";
|
|
10
|
+
import "./chunk-NE25QJUZ.js";
|
|
11
11
|
import {
|
|
12
12
|
cpp_default
|
|
13
13
|
} from "./chunk-ICUS267J.js";
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
cmake_default
|
|
21
21
|
} from "./chunk-CYKSS2Y7.js";
|
|
22
|
-
import "./chunk-IWM27JZF.js";
|
|
23
22
|
import "./chunk-XOMTOLBK.js";
|
|
24
23
|
import {
|
|
25
24
|
python_default
|
|
@@ -27,6 +26,7 @@ import {
|
|
|
27
26
|
import {
|
|
28
27
|
html_derivative_default
|
|
29
28
|
} from "./chunk-HO32H4C2.js";
|
|
29
|
+
import "./chunk-IWM27JZF.js";
|
|
30
30
|
import "./chunk-VB3O6QM4.js";
|
|
31
31
|
import "./chunk-QFOAKHDY.js";
|
|
32
32
|
import "./chunk-AZIN3OHL.js";
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ruby_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7DJE5LRN.js";
|
|
4
4
|
import "./chunk-ZSX4GOHC.js";
|
|
5
|
-
import "./chunk-NE25QJUZ.js";
|
|
6
5
|
import "./chunk-OII47WE4.js";
|
|
7
6
|
import "./chunk-76C5RMV7.js";
|
|
8
7
|
import "./chunk-S3SFQXYS.js";
|
|
8
|
+
import "./chunk-NE25QJUZ.js";
|
|
9
9
|
import "./chunk-ICUS267J.js";
|
|
10
10
|
import "./chunk-MT4FGOLU.js";
|
|
11
11
|
import "./chunk-YJV35WLF.js";
|
|
12
12
|
import "./chunk-5TDK5Y5S.js";
|
|
13
|
-
import "./chunk-IWM27JZF.js";
|
|
14
13
|
import "./chunk-XOMTOLBK.js";
|
|
14
|
+
import "./chunk-IWM27JZF.js";
|
|
15
15
|
import "./chunk-VB3O6QM4.js";
|
|
16
16
|
import "./chunk-QFOAKHDY.js";
|
|
17
17
|
import "./chunk-AZIN3OHL.js";
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
color: #fff;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
&--error {
|
|
20
|
+
background: #cf222e;
|
|
21
|
+
color: #fff;
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
&--visible {
|
|
20
25
|
transform: translateY(0);
|
|
21
26
|
}
|
|
@@ -25,12 +30,19 @@
|
|
|
25
30
|
position: relative;
|
|
26
31
|
}
|
|
27
32
|
|
|
33
|
+
@keyframes page-src-spin {
|
|
34
|
+
to {
|
|
35
|
+
transform: rotate(360deg);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
28
39
|
.page-src-action-bar {
|
|
29
40
|
position: absolute;
|
|
30
41
|
top: -30px;
|
|
31
42
|
right: -5px;
|
|
32
43
|
|
|
33
44
|
&__btn {
|
|
45
|
+
position: relative;
|
|
34
46
|
width: 2rem;
|
|
35
47
|
height: 2rem;
|
|
36
48
|
padding: 0;
|
|
@@ -48,6 +60,23 @@
|
|
|
48
60
|
&:hover {
|
|
49
61
|
background: var(--sl-color-bg-nav);
|
|
50
62
|
}
|
|
63
|
+
|
|
64
|
+
&--loading {
|
|
65
|
+
cursor: default;
|
|
66
|
+
pointer-events: none;
|
|
67
|
+
color: transparent;
|
|
68
|
+
|
|
69
|
+
&::after {
|
|
70
|
+
content: "";
|
|
71
|
+
position: absolute;
|
|
72
|
+
width: 12px;
|
|
73
|
+
height: 12px;
|
|
74
|
+
border: 2px solid var(--sl-color-text);
|
|
75
|
+
border-top-color: transparent;
|
|
76
|
+
border-radius: 50%;
|
|
77
|
+
animation: page-src-spin 0.6s linear infinite;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
51
80
|
}
|
|
52
81
|
|
|
53
82
|
&__menu {
|
|
@@ -3,21 +3,21 @@ import {
|
|
|
3
3
|
} from "./chunk-LU63TSZZ.js";
|
|
4
4
|
import {
|
|
5
5
|
ruby_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7DJE5LRN.js";
|
|
7
7
|
import "./chunk-ZSX4GOHC.js";
|
|
8
|
-
import "./chunk-NE25QJUZ.js";
|
|
9
8
|
import "./chunk-OII47WE4.js";
|
|
10
9
|
import "./chunk-76C5RMV7.js";
|
|
11
10
|
import "./chunk-S3SFQXYS.js";
|
|
11
|
+
import "./chunk-NE25QJUZ.js";
|
|
12
12
|
import "./chunk-ICUS267J.js";
|
|
13
13
|
import "./chunk-MT4FGOLU.js";
|
|
14
14
|
import "./chunk-YJV35WLF.js";
|
|
15
15
|
import "./chunk-5TDK5Y5S.js";
|
|
16
|
-
import "./chunk-IWM27JZF.js";
|
|
17
16
|
import "./chunk-XOMTOLBK.js";
|
|
18
17
|
import {
|
|
19
18
|
python_default
|
|
20
19
|
} from "./chunk-QH2T6GYZ.js";
|
|
20
|
+
import "./chunk-IWM27JZF.js";
|
|
21
21
|
import "./chunk-VB3O6QM4.js";
|
|
22
22
|
import "./chunk-QFOAKHDY.js";
|
|
23
23
|
import "./chunk-AZIN3OHL.js";
|
package/package.json
CHANGED
package/dist/chunk-HDL4DZNT.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getIndexMdSidebarItems
|
|
3
|
-
} from "./chunk-3ATSZG6H.js";
|
|
4
|
-
|
|
5
|
-
// src/plugins/starlight-index-only-sidebar.ts
|
|
6
|
-
import { join } from "path";
|
|
7
|
-
var SITE_DOCS_ROOT = "./src/content/docs";
|
|
8
|
-
function normalizeSlug(slug) {
|
|
9
|
-
return slug.endsWith("/index") ? slug.slice(0, -6) : slug;
|
|
10
|
-
}
|
|
11
|
-
function normalizeItems(items) {
|
|
12
|
-
return items.map((item) => {
|
|
13
|
-
if ("items" in item) {
|
|
14
|
-
return {
|
|
15
|
-
label: item.label,
|
|
16
|
-
items: normalizeItems(item.items)
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
if ("slug" in item) {
|
|
20
|
-
return {
|
|
21
|
-
label: item.label,
|
|
22
|
-
slug: normalizeSlug(item.slug)
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return item;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function starlightIndexOnlySidebar(pluginOptions) {
|
|
29
|
-
return {
|
|
30
|
-
name: "index-only-sidebar",
|
|
31
|
-
hooks: {
|
|
32
|
-
"config:setup": (hookOptions) => {
|
|
33
|
-
const { updateConfig } = hookOptions;
|
|
34
|
-
const { directories, maxDepthNesting, dirnameDeterminesLabels } = pluginOptions;
|
|
35
|
-
const functionOptions = {
|
|
36
|
-
maxDepthNesting,
|
|
37
|
-
dirnameDeterminesLabels
|
|
38
|
-
};
|
|
39
|
-
const sidebarItems = directories.map((directory) => {
|
|
40
|
-
const dirPath = join(SITE_DOCS_ROOT, directory);
|
|
41
|
-
const rawItems = getIndexMdSidebarItems(dirPath, functionOptions);
|
|
42
|
-
const rootGroup = rawItems[0];
|
|
43
|
-
if (!rootGroup || !("items" in rootGroup)) {
|
|
44
|
-
return void 0;
|
|
45
|
-
}
|
|
46
|
-
const items = rootGroup.items || [];
|
|
47
|
-
const normalizedItems = normalizeItems(items);
|
|
48
|
-
return {
|
|
49
|
-
label: rootGroup.label,
|
|
50
|
-
items: normalizedItems
|
|
51
|
-
};
|
|
52
|
-
}).filter(
|
|
53
|
-
(group) => group !== void 0 && group.items.length > 0
|
|
54
|
-
);
|
|
55
|
-
updateConfig({
|
|
56
|
-
sidebar: sidebarItems
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export {
|
|
64
|
-
starlightIndexOnlySidebar
|
|
65
|
-
};
|
package/dist/chunk-IX5UFISR.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
compileLatexToSvg,
|
|
3
|
-
hashLatexCode
|
|
4
|
-
} from "./chunk-TTQY54Q6.js";
|
|
5
|
-
|
|
6
|
-
// src/plugins/astro-latex-compile/index.ts
|
|
7
|
-
import { rm } from "fs/promises";
|
|
8
|
-
import { join, resolve } from "path";
|
|
9
|
-
import { visit as visit2, SKIP } from "unist-util-visit";
|
|
10
|
-
|
|
11
|
-
// src/plugins/astro-latex-compile/rehype-converter.ts
|
|
12
|
-
import { visit } from "unist-util-visit";
|
|
13
|
-
function rehypeLatexCompile() {
|
|
14
|
-
return (tree, _file) => {
|
|
15
|
-
visit(tree, "element", (node, index, parent) => {
|
|
16
|
-
if (node.tagName !== "pre") return;
|
|
17
|
-
const codeChild = node.children?.[0];
|
|
18
|
-
if (!codeChild || codeChild.tagName !== "code") return;
|
|
19
|
-
const classes = Array.isArray(codeChild.properties?.className) ? codeChild.properties.className : [];
|
|
20
|
-
if (!classes.includes("language-tex") && !classes.includes("language-latex")) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const codeContent = codeChild.children?.map(
|
|
24
|
-
(child) => typeof child === "string" ? child : child.value || ""
|
|
25
|
-
).join("").trim();
|
|
26
|
-
if (!codeContent) return;
|
|
27
|
-
const dataAttribute = codeChild.properties?.["data-meta"];
|
|
28
|
-
const isCompileBlock = dataAttribute && dataAttribute.includes("compile") || codeContent.includes("compile");
|
|
29
|
-
if (!isCompileBlock) return;
|
|
30
|
-
try {
|
|
31
|
-
const hash = hashLatexCode(codeContent);
|
|
32
|
-
const svgPath = `/static/tex-svgs/${hash}.svg`;
|
|
33
|
-
const imgElement = {
|
|
34
|
-
type: "element",
|
|
35
|
-
tagName: "img",
|
|
36
|
-
properties: {
|
|
37
|
-
src: svgPath,
|
|
38
|
-
alt: "LaTeX diagram",
|
|
39
|
-
className: ["tex-compiled"]
|
|
40
|
-
},
|
|
41
|
-
children: []
|
|
42
|
-
};
|
|
43
|
-
const paragraphElement = {
|
|
44
|
-
type: "element",
|
|
45
|
-
tagName: "p",
|
|
46
|
-
properties: {},
|
|
47
|
-
children: [imgElement]
|
|
48
|
-
};
|
|
49
|
-
if (parent && typeof index === "number") {
|
|
50
|
-
parent.children[index] = paragraphElement;
|
|
51
|
-
}
|
|
52
|
-
} catch (err) {
|
|
53
|
-
console.error(
|
|
54
|
-
`[rehype-latex-compile] Error processing code block:`,
|
|
55
|
-
err
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// src/plugins/astro-latex-compile/index.ts
|
|
63
|
-
function extractClassesFromMeta(meta) {
|
|
64
|
-
const classMatch = meta.match(/class="([^"]+)"/);
|
|
65
|
-
if (classMatch?.[1]) {
|
|
66
|
-
return classMatch[1].split(/\s+/).filter(Boolean);
|
|
67
|
-
}
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
function remarkLatexCompile(options) {
|
|
71
|
-
const svgOutputDir = resolve(options.svgOutputDir);
|
|
72
|
-
return async function transformer(tree, file) {
|
|
73
|
-
const nodes = [];
|
|
74
|
-
visit2(tree, "code", (node, index, parent) => {
|
|
75
|
-
if ((node.lang === "tex" || node.lang === "latex") && node.meta?.includes("compile") && parent && index !== void 0) {
|
|
76
|
-
nodes.push({ node, index, parent });
|
|
77
|
-
}
|
|
78
|
-
return SKIP;
|
|
79
|
-
});
|
|
80
|
-
if (nodes.length === 0) return;
|
|
81
|
-
const filePath = file.path || "unknown";
|
|
82
|
-
const results = await Promise.all(
|
|
83
|
-
nodes.map(async ({ node, index, parent }) => {
|
|
84
|
-
const lineNumber = node.position?.start.line ?? "?";
|
|
85
|
-
try {
|
|
86
|
-
const result = await compileLatexToSvg(node.value, svgOutputDir);
|
|
87
|
-
if (result.wasCompiled) {
|
|
88
|
-
console.log(
|
|
89
|
-
`[remark-latex-compile] ${filePath}:${lineNumber}: compiled ${result.hash}.svg`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
options._referencedHashes?.add(result.hash);
|
|
93
|
-
return { index, parent, result, error: null, hash: result.hash };
|
|
94
|
-
} catch (err) {
|
|
95
|
-
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
96
|
-
const match = errorMsg.match(/\n\n([\s\S]+)/);
|
|
97
|
-
const details = match ? match[1] : errorMsg;
|
|
98
|
-
console.error(
|
|
99
|
-
`[remark-latex-compile] ${filePath}:${lineNumber}
|
|
100
|
-
${details}`
|
|
101
|
-
);
|
|
102
|
-
return { index, parent, result: null, error: err, hash: null };
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
);
|
|
106
|
-
if (options._fileHashMap) {
|
|
107
|
-
const newHashes = new Set(
|
|
108
|
-
results.map((r) => r.hash).filter(Boolean)
|
|
109
|
-
);
|
|
110
|
-
const oldHashes = options._fileHashMap.get(filePath) ?? /* @__PURE__ */ new Set();
|
|
111
|
-
const staleHashes = [...oldHashes].filter((h) => !newHashes.has(h));
|
|
112
|
-
for (const staleHash of staleHashes) {
|
|
113
|
-
console.warn(
|
|
114
|
-
`[remark-latex-compile] Removing orphaned svg: ${staleHash}.svg`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
await Promise.all(
|
|
118
|
-
staleHashes.map(
|
|
119
|
-
(h) => rm(join(svgOutputDir, `${h}.svg`), { force: true })
|
|
120
|
-
)
|
|
121
|
-
);
|
|
122
|
-
options._fileHashMap.set(filePath, newHashes);
|
|
123
|
-
}
|
|
124
|
-
for (let i = results.length - 1; i >= 0; i--) {
|
|
125
|
-
const { index, parent, result } = results[i];
|
|
126
|
-
const { node } = nodes[i];
|
|
127
|
-
if (!result) continue;
|
|
128
|
-
const customClasses = extractClassesFromMeta(node.meta ?? "");
|
|
129
|
-
const imageNode = {
|
|
130
|
-
type: "image",
|
|
131
|
-
url: `/static/tex-svgs/${result.hash}.svg`,
|
|
132
|
-
alt: "LaTeX diagram",
|
|
133
|
-
data: {
|
|
134
|
-
hProperties: { className: ["tex-compiled", ...customClasses] }
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
const paragraph = {
|
|
138
|
-
type: "paragraph",
|
|
139
|
-
children: [imageNode]
|
|
140
|
-
};
|
|
141
|
-
parent.children.splice(index, 1, paragraph);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export {
|
|
147
|
-
rehypeLatexCompile,
|
|
148
|
-
remarkLatexCompile
|
|
149
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
LATEX_BLOCK_REGEX,
|
|
4
|
-
hashLatexCode
|
|
5
|
-
} from "../chunk-TTQY54Q6.js";
|
|
6
|
-
import "../chunk-QGM4M3NI.js";
|
|
7
|
-
|
|
8
|
-
// scripts/cli/cannoli-latex-cleanup.ts
|
|
9
|
-
import { readdir, readFile, unlink } from "fs/promises";
|
|
10
|
-
import { resolve, join } from "path";
|
|
11
|
-
var args = process.argv.slice(2);
|
|
12
|
-
var svgDir = null;
|
|
13
|
-
var docsDir = "src/content/docs";
|
|
14
|
-
var checkMode = false;
|
|
15
|
-
var deleteMode = false;
|
|
16
|
-
for (let i = 0; i < args.length; i++) {
|
|
17
|
-
if (args[i] === "--svg-dir" && i + 1 < args.length) {
|
|
18
|
-
svgDir = args[++i];
|
|
19
|
-
} else if (args[i] === "--docs-dir" && i + 1 < args.length) {
|
|
20
|
-
docsDir = args[++i];
|
|
21
|
-
} else if (args[i] === "--check") {
|
|
22
|
-
checkMode = true;
|
|
23
|
-
} else if (args[i] === "--delete") {
|
|
24
|
-
deleteMode = true;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (!svgDir) {
|
|
28
|
-
console.error("Error: --svg-dir is required");
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
if (!checkMode && !deleteMode) {
|
|
32
|
-
console.error("Error: either --check or --delete must be specified");
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
var svgDirPath = resolve(svgDir);
|
|
36
|
-
var docsDirPath = resolve(docsDir);
|
|
37
|
-
async function scanMarkdownForHashes(dir, hashes) {
|
|
38
|
-
try {
|
|
39
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
40
|
-
for (const entry of entries) {
|
|
41
|
-
const fullPath = join(dir, entry.name);
|
|
42
|
-
if (entry.isDirectory()) {
|
|
43
|
-
await scanMarkdownForHashes(fullPath, hashes);
|
|
44
|
-
} else if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".mdx"))) {
|
|
45
|
-
const content = await readFile(fullPath, "utf-8");
|
|
46
|
-
const latexBlockRegex = new RegExp(
|
|
47
|
-
LATEX_BLOCK_REGEX.source,
|
|
48
|
-
LATEX_BLOCK_REGEX.flags
|
|
49
|
-
);
|
|
50
|
-
const matches = content.matchAll(latexBlockRegex);
|
|
51
|
-
for (const match of matches) {
|
|
52
|
-
const latexCode = match[1];
|
|
53
|
-
const hash = hashLatexCode(latexCode);
|
|
54
|
-
hashes.add(hash);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} catch (err) {
|
|
59
|
-
console.error(`Error scanning directory ${dir}:`, err);
|
|
60
|
-
throw err;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async function findOrphanedSvgs(svgPath, usedHashes) {
|
|
64
|
-
const orphaned = [];
|
|
65
|
-
try {
|
|
66
|
-
const entries = await readdir(svgPath, { withFileTypes: true });
|
|
67
|
-
for (const entry of entries) {
|
|
68
|
-
if (entry.isFile() && entry.name.endsWith(".svg")) {
|
|
69
|
-
const hash = entry.name.replace(".svg", "");
|
|
70
|
-
if (!usedHashes.has(hash)) {
|
|
71
|
-
orphaned.push(join(svgPath, entry.name));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} catch (err) {
|
|
76
|
-
if (err.code === "ENOENT") {
|
|
77
|
-
console.warn(`SVG directory does not exist: ${svgPath}`);
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
throw err;
|
|
81
|
-
}
|
|
82
|
-
return orphaned;
|
|
83
|
-
}
|
|
84
|
-
async function main() {
|
|
85
|
-
try {
|
|
86
|
-
console.log(`Scanning markdown files in ${docsDirPath}...`);
|
|
87
|
-
const usedHashes = /* @__PURE__ */ new Set();
|
|
88
|
-
await scanMarkdownForHashes(docsDirPath, usedHashes);
|
|
89
|
-
console.log(`Found ${usedHashes.size} unique tex compile blocks
|
|
90
|
-
`);
|
|
91
|
-
console.log(`Scanning SVG directory ${svgDirPath}...`);
|
|
92
|
-
const orphanedSvgs = await findOrphanedSvgs(svgDirPath, usedHashes);
|
|
93
|
-
if (orphanedSvgs.length === 0) {
|
|
94
|
-
console.log("No orphaned SVGs found \u2713");
|
|
95
|
-
process.exit(0);
|
|
96
|
-
}
|
|
97
|
-
console.log(`
|
|
98
|
-
Found ${orphanedSvgs.length} orphaned SVG(s):`);
|
|
99
|
-
orphanedSvgs.forEach((svg) => {
|
|
100
|
-
const filename = svg.split("/").pop();
|
|
101
|
-
console.log(` - ${filename}`);
|
|
102
|
-
});
|
|
103
|
-
if (checkMode) {
|
|
104
|
-
console.log("\n(Use --delete to remove these files)");
|
|
105
|
-
process.exit(0);
|
|
106
|
-
}
|
|
107
|
-
if (deleteMode) {
|
|
108
|
-
console.log("\nDeleting orphaned SVGs...");
|
|
109
|
-
let deleted = 0;
|
|
110
|
-
for (const svg of orphanedSvgs) {
|
|
111
|
-
try {
|
|
112
|
-
await unlink(svg);
|
|
113
|
-
deleted++;
|
|
114
|
-
console.log(` \u2713 Deleted ${svg.split("/").pop()}`);
|
|
115
|
-
} catch (err) {
|
|
116
|
-
console.error(` \u2717 Failed to delete ${svg}:`, err);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
console.log(`
|
|
120
|
-
Deleted ${deleted}/${orphanedSvgs.length} files`);
|
|
121
|
-
process.exit(0);
|
|
122
|
-
}
|
|
123
|
-
} catch (err) {
|
|
124
|
-
console.error("Error:", err);
|
|
125
|
-
process.exit(1);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
main();
|
|
@@ -16,12 +16,12 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
shellscript_default
|
|
18
18
|
} from "./chunk-5TDK5Y5S.js";
|
|
19
|
-
import {
|
|
20
|
-
sql_default
|
|
21
|
-
} from "./chunk-IWM27JZF.js";
|
|
22
19
|
import {
|
|
23
20
|
c_default
|
|
24
21
|
} from "./chunk-XOMTOLBK.js";
|
|
22
|
+
import {
|
|
23
|
+
sql_default
|
|
24
|
+
} from "./chunk-IWM27JZF.js";
|
|
25
25
|
import {
|
|
26
26
|
xml_default
|
|
27
27
|
} from "./chunk-AZIN3OHL.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
shellscript_default
|
|
3
3
|
} from "./chunk-5TDK5Y5S.js";
|
|
4
|
-
import {
|
|
5
|
-
sql_default
|
|
6
|
-
} from "./chunk-IWM27JZF.js";
|
|
7
4
|
import {
|
|
8
5
|
c_default
|
|
9
6
|
} from "./chunk-XOMTOLBK.js";
|
|
7
|
+
import {
|
|
8
|
+
sql_default
|
|
9
|
+
} from "./chunk-IWM27JZF.js";
|
|
10
10
|
import {
|
|
11
11
|
html_default
|
|
12
12
|
} from "./chunk-L4TNW36O.js";
|
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
} from "./chunk-ICUS267J.js";
|
|
7
7
|
import "./chunk-MT4FGOLU.js";
|
|
8
8
|
import "./chunk-YJV35WLF.js";
|
|
9
|
-
import {
|
|
10
|
-
sql_default
|
|
11
|
-
} from "./chunk-IWM27JZF.js";
|
|
12
9
|
import "./chunk-XOMTOLBK.js";
|
|
13
10
|
import {
|
|
14
11
|
python_default
|
|
15
12
|
} from "./chunk-QH2T6GYZ.js";
|
|
13
|
+
import {
|
|
14
|
+
sql_default
|
|
15
|
+
} from "./chunk-IWM27JZF.js";
|
|
16
16
|
import {
|
|
17
17
|
javascript_default
|
|
18
18
|
} from "./chunk-2QHMH6QB.js";
|