starlight-cannoli-plugins 1.2.10 → 1.2.11
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
compileLatexToSvg
|
|
2
|
+
compileLatexToSvg,
|
|
3
|
+
hashLatexCode
|
|
3
4
|
} from "./chunk-QZUB4DOG.js";
|
|
4
5
|
|
|
5
6
|
// src/plugins/remark-latex-compile/index.ts
|
|
@@ -18,8 +19,14 @@ function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
|
18
19
|
for (let i = 0; i < children.length; i++) {
|
|
19
20
|
const child = children[i];
|
|
20
21
|
if (child.type === "code" && (child.lang === "tex" || child.lang === "latex") && String(child.meta || "").includes("compile")) {
|
|
22
|
+
const position = child.position;
|
|
23
|
+
const lineNumber = position?.start?.line || "?";
|
|
21
24
|
try {
|
|
22
25
|
const result = compileLatexToSvg(String(child.value), svgOutputDir);
|
|
26
|
+
const status = result.wasCompiled ? "compiled" : "used cached";
|
|
27
|
+
console.log(
|
|
28
|
+
`[remark-latex-compile] ${filePath}:${lineNumber}: ${status} ${result.hash}.svg`
|
|
29
|
+
);
|
|
23
30
|
const customClasses = extractClassesFromMeta(
|
|
24
31
|
String(child.meta || "")
|
|
25
32
|
);
|
|
@@ -41,8 +48,6 @@ function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
|
41
48
|
};
|
|
42
49
|
} catch (err) {
|
|
43
50
|
if (process.env.NODE_ENV !== "production") {
|
|
44
|
-
const position = child.position;
|
|
45
|
-
const lineNumber = position?.start?.line || "?";
|
|
46
51
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
47
52
|
const match = errorMsg.match(/\n\n([\s\S]+)/);
|
|
48
53
|
const details = match ? match[1] : errorMsg;
|
|
@@ -68,11 +73,6 @@ function remarkLatexCompile(options) {
|
|
|
68
73
|
// src/plugins/remark-latex-compile/astro-integration.ts
|
|
69
74
|
import { readdir, readFile, writeFile } from "fs/promises";
|
|
70
75
|
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
76
|
function createAstroLatexIntegration(options) {
|
|
77
77
|
const svgOutputDir = resolve2(options.svgOutputDir);
|
|
78
78
|
const contentDir = options?.contentDir ? resolve2(options.contentDir) : resolve2("src/content/docs");
|
|
@@ -120,7 +120,7 @@ function getLineNumber(content, position) {
|
|
|
120
120
|
}
|
|
121
121
|
async function processMarkdownFile(filePath, svgOutputDir) {
|
|
122
122
|
const content = await readFile(filePath, "utf-8");
|
|
123
|
-
const latexBlockRegex = /```(?:tex|latex)\s+compile\n([\s\S]*?)\n```/g;
|
|
123
|
+
const latexBlockRegex = /```(?:tex|latex)\s+compile\r?\n([\s\S]*?)\r?\n```/g;
|
|
124
124
|
const matches = content.matchAll(latexBlockRegex);
|
|
125
125
|
for (const match of matches) {
|
|
126
126
|
const latexCode = match[1];
|
|
@@ -158,7 +158,7 @@ async function scanMarkdownForHashes(dir, hashes) {
|
|
|
158
158
|
await scanMarkdownForHashes(fullPath, hashes);
|
|
159
159
|
} else if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".mdx"))) {
|
|
160
160
|
const content = await readFile(fullPath, "utf-8");
|
|
161
|
-
const latexBlockRegex = /```(?:tex|latex)\s+compile\n([\s\S]*?)\n```/g;
|
|
161
|
+
const latexBlockRegex = /```(?:tex|latex)\s+compile\r?\n([\s\S]*?)\r?\n```/g;
|
|
162
162
|
const matches = content.matchAll(latexBlockRegex);
|
|
163
163
|
for (const match of matches) {
|
|
164
164
|
const latexCode = match[1];
|
package/dist/index.js
CHANGED
package/package.json
CHANGED