starlight-cannoli-plugins 1.2.9 → 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];
@@ -42,7 +42,7 @@ async function scanMarkdownForHashes(dir, hashes) {
42
42
  await scanMarkdownForHashes(fullPath, hashes);
43
43
  } else if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".mdx"))) {
44
44
  const content = await readFile(fullPath, "utf-8");
45
- const latexBlockRegex = /```(?:tex|latex)\s+compile\n([\s\S]*?)\n```/g;
45
+ const latexBlockRegex = /```(?:tex|latex)\s+compile\r?\n([\s\S]*?)\r?\n```/g;
46
46
  const matches = content.matchAll(latexBlockRegex);
47
47
  for (const match of matches) {
48
48
  const latexCode = match[1];
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  remarkLatexCompile,
9
9
  starlightLatexCompile
10
- } from "./chunk-UMYD2SJL.js";
10
+ } from "./chunk-7C6N6IOU.js";
11
11
  import {
12
12
  starlightSyncDocsToPublic
13
13
  } from "./chunk-GE24XGG7.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  remarkLatexCompile,
3
3
  starlightLatexCompile
4
- } from "../chunk-UMYD2SJL.js";
4
+ } from "../chunk-7C6N6IOU.js";
5
5
  import {
6
6
  compileLatexToSvg
7
7
  } from "../chunk-QZUB4DOG.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  starlightLatexCompile,
3
3
  starlight_plugin_default
4
- } from "../chunk-UMYD2SJL.js";
4
+ } from "../chunk-7C6N6IOU.js";
5
5
  import "../chunk-QZUB4DOG.js";
6
6
  import "../chunk-QGM4M3NI.js";
7
7
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "starlight-cannoli-plugins",
3
3
  "type": "module",
4
- "version": "1.2.9",
4
+ "version": "1.2.11",
5
5
  "description": "Starlight plugins for automatic sidebar generation and link validation",
6
6
  "license": "ISC",
7
7
  "main": "./dist/index.js",