starlight-cannoli-plugins 1.2.10 → 1.2.12
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-UMYD2SJL.js → chunk-JZJHH56Q.js} +18 -11
- package/dist/{chunk-QZUB4DOG.js → chunk-W3HDFLM5.js} +2 -0
- package/dist/cli/cannoli-latex-cleanup.js +6 -2
- package/dist/index.js +2 -2
- package/dist/plugins/remark-latex-compile.js +2 -2
- package/dist/plugins/starlight-latex-compile.js +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
LATEX_BLOCK_REGEX,
|
|
3
|
+
compileLatexToSvg,
|
|
4
|
+
hashLatexCode
|
|
5
|
+
} from "./chunk-W3HDFLM5.js";
|
|
4
6
|
|
|
5
7
|
// src/plugins/remark-latex-compile/index.ts
|
|
6
8
|
import { resolve } from "path";
|
|
@@ -18,8 +20,14 @@ function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
|
18
20
|
for (let i = 0; i < children.length; i++) {
|
|
19
21
|
const child = children[i];
|
|
20
22
|
if (child.type === "code" && (child.lang === "tex" || child.lang === "latex") && String(child.meta || "").includes("compile")) {
|
|
23
|
+
const position = child.position;
|
|
24
|
+
const lineNumber = position?.start?.line || "?";
|
|
21
25
|
try {
|
|
22
26
|
const result = compileLatexToSvg(String(child.value), svgOutputDir);
|
|
27
|
+
const status = result.wasCompiled ? "compiled" : "used cached";
|
|
28
|
+
console.log(
|
|
29
|
+
`[remark-latex-compile] ${filePath}:${lineNumber}: ${status} ${result.hash}.svg`
|
|
30
|
+
);
|
|
23
31
|
const customClasses = extractClassesFromMeta(
|
|
24
32
|
String(child.meta || "")
|
|
25
33
|
);
|
|
@@ -41,8 +49,6 @@ function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
|
41
49
|
};
|
|
42
50
|
} catch (err) {
|
|
43
51
|
if (process.env.NODE_ENV !== "production") {
|
|
44
|
-
const position = child.position;
|
|
45
|
-
const lineNumber = position?.start?.line || "?";
|
|
46
52
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
47
53
|
const match = errorMsg.match(/\n\n([\s\S]+)/);
|
|
48
54
|
const details = match ? match[1] : errorMsg;
|
|
@@ -68,11 +74,6 @@ function remarkLatexCompile(options) {
|
|
|
68
74
|
// src/plugins/remark-latex-compile/astro-integration.ts
|
|
69
75
|
import { readdir, readFile, writeFile } from "fs/promises";
|
|
70
76
|
import { resolve as resolve2, join, extname } from "path";
|
|
71
|
-
import { createHash } from "crypto";
|
|
72
|
-
function hashLatexCode(code) {
|
|
73
|
-
const normalized = code.split("\n").map((line) => line.trim()).join("\n").trim();
|
|
74
|
-
return createHash("md5").update(normalized).digest("hex").slice(0, 16);
|
|
75
|
-
}
|
|
76
77
|
function createAstroLatexIntegration(options) {
|
|
77
78
|
const svgOutputDir = resolve2(options.svgOutputDir);
|
|
78
79
|
const contentDir = options?.contentDir ? resolve2(options.contentDir) : resolve2("src/content/docs");
|
|
@@ -120,7 +121,10 @@ function getLineNumber(content, position) {
|
|
|
120
121
|
}
|
|
121
122
|
async function processMarkdownFile(filePath, svgOutputDir) {
|
|
122
123
|
const content = await readFile(filePath, "utf-8");
|
|
123
|
-
const latexBlockRegex =
|
|
124
|
+
const latexBlockRegex = new RegExp(
|
|
125
|
+
LATEX_BLOCK_REGEX.source,
|
|
126
|
+
LATEX_BLOCK_REGEX.flags
|
|
127
|
+
);
|
|
124
128
|
const matches = content.matchAll(latexBlockRegex);
|
|
125
129
|
for (const match of matches) {
|
|
126
130
|
const latexCode = match[1];
|
|
@@ -158,7 +162,10 @@ async function scanMarkdownForHashes(dir, hashes) {
|
|
|
158
162
|
await scanMarkdownForHashes(fullPath, hashes);
|
|
159
163
|
} else if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".mdx"))) {
|
|
160
164
|
const content = await readFile(fullPath, "utf-8");
|
|
161
|
-
const latexBlockRegex =
|
|
165
|
+
const latexBlockRegex = new RegExp(
|
|
166
|
+
LATEX_BLOCK_REGEX.source,
|
|
167
|
+
LATEX_BLOCK_REGEX.flags
|
|
168
|
+
);
|
|
162
169
|
const matches = content.matchAll(latexBlockRegex);
|
|
163
170
|
for (const match of matches) {
|
|
164
171
|
const latexCode = match[1];
|
|
@@ -162,6 +162,7 @@ ${formattedSource}
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
// src/plugins/remark-latex-compile/compile.ts
|
|
165
|
+
var LATEX_BLOCK_REGEX = /```(?:tex|latex)\s+compile\r?\n([\s\S]*?)\r?\n```/g;
|
|
165
166
|
function hashLatexCode(code) {
|
|
166
167
|
const normalized = code.split("\n").map((line) => line.trim()).filter((line) => !line.startsWith("%")).filter(Boolean).join("\n").trim();
|
|
167
168
|
return createHash("md5").update(normalized).digest("hex").slice(0, 16);
|
|
@@ -250,6 +251,7 @@ Error: ${errorOutput}`
|
|
|
250
251
|
}
|
|
251
252
|
|
|
252
253
|
export {
|
|
254
|
+
LATEX_BLOCK_REGEX,
|
|
253
255
|
hashLatexCode,
|
|
254
256
|
compileLatexToSvg
|
|
255
257
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
LATEX_BLOCK_REGEX,
|
|
3
4
|
hashLatexCode
|
|
4
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-W3HDFLM5.js";
|
|
5
6
|
import "../chunk-QGM4M3NI.js";
|
|
6
7
|
|
|
7
8
|
// scripts/cli/cannoli-latex-cleanup.ts
|
|
@@ -42,7 +43,10 @@ async function scanMarkdownForHashes(dir, hashes) {
|
|
|
42
43
|
await scanMarkdownForHashes(fullPath, hashes);
|
|
43
44
|
} else if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".mdx"))) {
|
|
44
45
|
const content = await readFile(fullPath, "utf-8");
|
|
45
|
-
const latexBlockRegex =
|
|
46
|
+
const latexBlockRegex = new RegExp(
|
|
47
|
+
LATEX_BLOCK_REGEX.source,
|
|
48
|
+
LATEX_BLOCK_REGEX.flags
|
|
49
|
+
);
|
|
46
50
|
const matches = content.matchAll(latexBlockRegex);
|
|
47
51
|
for (const match of matches) {
|
|
48
52
|
const latexCode = match[1];
|
package/dist/index.js
CHANGED
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
remarkLatexCompile,
|
|
9
9
|
starlightLatexCompile
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-JZJHH56Q.js";
|
|
11
11
|
import {
|
|
12
12
|
starlightSyncDocsToPublic
|
|
13
13
|
} from "./chunk-GE24XGG7.js";
|
|
14
14
|
import "./chunk-3ATSZG6H.js";
|
|
15
|
-
import "./chunk-
|
|
15
|
+
import "./chunk-W3HDFLM5.js";
|
|
16
16
|
import "./chunk-QGM4M3NI.js";
|
|
17
17
|
|
|
18
18
|
// src/plugins/astro-normalize-paths.ts
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
remarkLatexCompile,
|
|
3
3
|
starlightLatexCompile
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-JZJHH56Q.js";
|
|
5
5
|
import {
|
|
6
6
|
compileLatexToSvg
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-W3HDFLM5.js";
|
|
8
8
|
import "../chunk-QGM4M3NI.js";
|
|
9
9
|
export {
|
|
10
10
|
compileLatexToSvg,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
starlightLatexCompile,
|
|
3
3
|
starlight_plugin_default
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-JZJHH56Q.js";
|
|
5
|
+
import "../chunk-W3HDFLM5.js";
|
|
6
6
|
import "../chunk-QGM4M3NI.js";
|
|
7
7
|
export {
|
|
8
8
|
starlight_plugin_default as default,
|
package/package.json
CHANGED