starlight-cannoli-plugins 1.0.16 → 1.1.0
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-IRJEKSXQ.js +417 -0
- package/dist/index-DapkTQmZ.d.ts +42 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -1
- package/dist/plugins/remark-latex-compile.d.ts +2 -0
- package/dist/plugins/remark-latex-compile.js +10 -0
- package/dist/plugins/starlight-latex-compile.d.ts +2 -0
- package/dist/plugins/starlight-latex-compile.js +8 -0
- package/package.json +9 -1
- package/dist/static/.static-files-go-here +0 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
// src/plugins/remark-latex-compile/index.ts
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
|
|
4
|
+
// src/plugins/remark-latex-compile/compile.ts
|
|
5
|
+
import { createHash } from "crypto";
|
|
6
|
+
import { execSync } from "child_process";
|
|
7
|
+
import {
|
|
8
|
+
existsSync,
|
|
9
|
+
mkdirSync,
|
|
10
|
+
copyFileSync,
|
|
11
|
+
writeFileSync,
|
|
12
|
+
rmSync
|
|
13
|
+
} from "fs";
|
|
14
|
+
import { join } from "path";
|
|
15
|
+
import { tmpdir } from "os";
|
|
16
|
+
|
|
17
|
+
// src/plugins/remark-latex-compile/error-parser.ts
|
|
18
|
+
function parseLatexError(latexOutput) {
|
|
19
|
+
const lines = latexOutput.split("\n");
|
|
20
|
+
const errorLines = [];
|
|
21
|
+
let mainError = "";
|
|
22
|
+
let errorLineNum;
|
|
23
|
+
for (let i = 0; i < lines.length; i++) {
|
|
24
|
+
const line = lines[i];
|
|
25
|
+
if (line.includes("Undefined control sequence")) {
|
|
26
|
+
mainError = "Undefined control sequence";
|
|
27
|
+
errorLines.push(line);
|
|
28
|
+
for (let j = Math.max(0, i - 3); j <= Math.min(i + 3, lines.length - 1); j++) {
|
|
29
|
+
if (lines[j].startsWith("l.")) {
|
|
30
|
+
const match = lines[j].match(/^l\.(\d+)\s*(.*)/);
|
|
31
|
+
if (match) {
|
|
32
|
+
errorLineNum = parseInt(match[1], 10);
|
|
33
|
+
const sourceLine = match[2].trim();
|
|
34
|
+
if (sourceLine) {
|
|
35
|
+
mainError = `Undefined control sequence: ${sourceLine}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
errorLines.push(lines[j]);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!mainError) {
|
|
46
|
+
for (let i = 0; i < lines.length; i++) {
|
|
47
|
+
const line = lines[i];
|
|
48
|
+
if (line.startsWith("!")) {
|
|
49
|
+
mainError = line.substring(1).trim();
|
|
50
|
+
errorLines.push(line);
|
|
51
|
+
for (let j = i + 1; j < Math.min(i + 5, lines.length); j++) {
|
|
52
|
+
const contextLine = lines[j];
|
|
53
|
+
if (contextLine.trim()) {
|
|
54
|
+
errorLines.push(contextLine);
|
|
55
|
+
}
|
|
56
|
+
if (contextLine.startsWith("l.")) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (let j = i; j < Math.min(i + 10, lines.length); j++) {
|
|
61
|
+
const lineMatch = lines[j].match(/^l\.(\d+)/);
|
|
62
|
+
if (lineMatch) {
|
|
63
|
+
errorLineNum = parseInt(lineMatch[1], 10);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!mainError) {
|
|
72
|
+
for (let i = 0; i < lines.length; i++) {
|
|
73
|
+
const line = lines[i];
|
|
74
|
+
if (line.toLowerCase().includes("emergency stop") || line.toLowerCase().includes("fatal error")) {
|
|
75
|
+
for (let j = Math.max(0, i - 5); j < i; j++) {
|
|
76
|
+
if (lines[j].startsWith("!")) {
|
|
77
|
+
mainError = lines[j].substring(1).trim();
|
|
78
|
+
errorLines.push(lines[j]);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!mainError) {
|
|
83
|
+
mainError = line.trim();
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!mainError && latexOutput.length > 0) {
|
|
90
|
+
for (const line of lines) {
|
|
91
|
+
if (line.includes("error") || line.includes("Error") || line.includes("Misplaced") || line.includes("Missing")) {
|
|
92
|
+
mainError = line.trim();
|
|
93
|
+
errorLines.push(mainError);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const message = mainError || "Unknown LaTeX compilation error";
|
|
99
|
+
return {
|
|
100
|
+
message,
|
|
101
|
+
line: errorLineNum,
|
|
102
|
+
context: errorLines.slice(0, 6)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function formatLatexError(error) {
|
|
106
|
+
let output = `LaTeX Error: ${error.message}`;
|
|
107
|
+
if (error.line) {
|
|
108
|
+
output += ` (line ${error.line})`;
|
|
109
|
+
}
|
|
110
|
+
if (error.context.length > 0) {
|
|
111
|
+
output += "\n\nContext:";
|
|
112
|
+
for (const contextLine of error.context) {
|
|
113
|
+
output += `
|
|
114
|
+
${contextLine}`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return output;
|
|
118
|
+
}
|
|
119
|
+
function createCompilationErrorMessage(latexSource, rawError) {
|
|
120
|
+
const parsed = parseLatexError(rawError);
|
|
121
|
+
const formatted = formatLatexError(parsed);
|
|
122
|
+
const RED = "\x1B[31m";
|
|
123
|
+
const RESET = "\x1B[0m";
|
|
124
|
+
return `${RED}[remark-latex-compile] LaTeX compilation failed${RESET}
|
|
125
|
+
|
|
126
|
+
${formatted}
|
|
127
|
+
|
|
128
|
+
LaTeX source:
|
|
129
|
+
${latexSource}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/plugins/remark-latex-compile/compile.ts
|
|
133
|
+
function hashLatexCode(code) {
|
|
134
|
+
const normalized = code.split("\n").map((line) => line.trim()).join("\n").trim();
|
|
135
|
+
return createHash("md5").update(normalized).digest("hex").slice(0, 16);
|
|
136
|
+
}
|
|
137
|
+
function buildLatexSource(latexCode) {
|
|
138
|
+
const packageRegex = /\\usepackage\{[^}]+\}|\\usetikzlibrary\{[^}]+\}/g;
|
|
139
|
+
const packages = latexCode.match(packageRegex) || [];
|
|
140
|
+
const codeWithoutPackages = latexCode.replace(packageRegex, "").trim();
|
|
141
|
+
return [
|
|
142
|
+
"\\documentclass[border=0.5in]{standalone}",
|
|
143
|
+
...packages,
|
|
144
|
+
"\\usepackage{xcolor}",
|
|
145
|
+
"\\pagecolor{white}",
|
|
146
|
+
"\\begin{document}",
|
|
147
|
+
"\\Large",
|
|
148
|
+
"\\fboxsep=2pt\\relax",
|
|
149
|
+
"\\fboxrule=0.5pt\\relax",
|
|
150
|
+
"\\fbox{",
|
|
151
|
+
codeWithoutPackages,
|
|
152
|
+
"}",
|
|
153
|
+
"\\end{document}"
|
|
154
|
+
].join("\n");
|
|
155
|
+
}
|
|
156
|
+
function compileLatexToSvg(latexCode, svgOutputDir) {
|
|
157
|
+
const hash = hashLatexCode(latexCode);
|
|
158
|
+
const svgPath = join(svgOutputDir, `${hash}.svg`);
|
|
159
|
+
if (existsSync(svgPath)) {
|
|
160
|
+
return { hash, svgPath, wasCompiled: false };
|
|
161
|
+
}
|
|
162
|
+
mkdirSync(svgOutputDir, { recursive: true });
|
|
163
|
+
const workDir = join(tmpdir(), `tikz-compile-${hash}`);
|
|
164
|
+
mkdirSync(workDir, { recursive: true });
|
|
165
|
+
const texFile = join(workDir, `${hash}.tex`);
|
|
166
|
+
const dviFile = join(workDir, `${hash}.dvi`);
|
|
167
|
+
const svgTempFile = join(workDir, `${hash}.svg`);
|
|
168
|
+
const latexSource = buildLatexSource(latexCode);
|
|
169
|
+
try {
|
|
170
|
+
writeFileSync(texFile, latexSource, "utf-8");
|
|
171
|
+
try {
|
|
172
|
+
execSync(
|
|
173
|
+
`latex -interaction=nonstopmode -output-directory "${workDir}" "${texFile}"`,
|
|
174
|
+
{ stdio: "pipe", cwd: workDir, encoding: "utf-8" }
|
|
175
|
+
);
|
|
176
|
+
} catch (latexErr) {
|
|
177
|
+
const errorOutput = latexErr.stdout || latexErr.stderr || latexErr.message || "";
|
|
178
|
+
const userMessage = createCompilationErrorMessage(
|
|
179
|
+
latexSource,
|
|
180
|
+
errorOutput
|
|
181
|
+
);
|
|
182
|
+
throw new Error(userMessage);
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
execSync(`dvisvgm --bbox=min "${dviFile}" -o "${svgTempFile}"`, {
|
|
186
|
+
stdio: "pipe",
|
|
187
|
+
cwd: workDir,
|
|
188
|
+
encoding: "utf-8"
|
|
189
|
+
});
|
|
190
|
+
} catch (dvisvgmErr) {
|
|
191
|
+
throw new Error(
|
|
192
|
+
`[remark-latex-compile] DVI to SVG conversion failed (hash: ${hash}).
|
|
193
|
+
Error: ${dvisvgmErr.message}
|
|
194
|
+
Stderr: ${dvisvgmErr.stderr ?? ""}Stdout: ${dvisvgmErr.stdout ?? ""}`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
copyFileSync(svgTempFile, svgPath);
|
|
198
|
+
} catch (err) {
|
|
199
|
+
throw err;
|
|
200
|
+
} finally {
|
|
201
|
+
try {
|
|
202
|
+
rmSync(workDir, { recursive: true, force: true });
|
|
203
|
+
} catch {
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return { hash, svgPath, wasCompiled: true };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/plugins/remark-latex-compile/index.ts
|
|
210
|
+
function traverseTree(node, svgOutputDir, depth = 0) {
|
|
211
|
+
if (!node) return;
|
|
212
|
+
if (Array.isArray(node.children)) {
|
|
213
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
214
|
+
const child = node.children[i];
|
|
215
|
+
if (child.type === "code" && (child.lang === "tex" || child.lang === "latex") && child.meta?.includes("compile")) {
|
|
216
|
+
try {
|
|
217
|
+
const result = compileLatexToSvg(child.value, svgOutputDir);
|
|
218
|
+
node.children[i] = {
|
|
219
|
+
type: "paragraph",
|
|
220
|
+
children: [
|
|
221
|
+
{
|
|
222
|
+
type: "image",
|
|
223
|
+
url: `/static/tex-svgs/${result.hash}.svg`,
|
|
224
|
+
alt: "LaTeX diagram"
|
|
225
|
+
}
|
|
226
|
+
]
|
|
227
|
+
};
|
|
228
|
+
} catch (err) {
|
|
229
|
+
console.error(`[remarkLatexCompile] Failed to compile LaTeX code block:`, err);
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
traverseTree(child, svgOutputDir, depth + 1);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function remarkLatexCompile(options) {
|
|
238
|
+
const svgOutputDir = options?.svgOutputDir ? resolve(options.svgOutputDir) : resolve("public/static/tex-svgs");
|
|
239
|
+
return (tree) => {
|
|
240
|
+
traverseTree(tree, svgOutputDir, 0);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/plugins/remark-latex-compile/astro-integration.ts
|
|
245
|
+
import { readdir, readFile, writeFile } from "fs/promises";
|
|
246
|
+
import { resolve as resolve2, join as join2, extname } from "path";
|
|
247
|
+
import { createHash as createHash2 } from "crypto";
|
|
248
|
+
function hashLatexCode2(code) {
|
|
249
|
+
const normalized = code.split("\n").map((line) => line.trim()).join("\n").trim();
|
|
250
|
+
return createHash2("md5").update(normalized).digest("hex").slice(0, 16);
|
|
251
|
+
}
|
|
252
|
+
function createAstroLatexIntegration(options) {
|
|
253
|
+
const svgOutputDir = options?.svgOutputDir ? resolve2(options.svgOutputDir) : resolve2("public/static/tex-svgs");
|
|
254
|
+
const contentDir = options?.contentDir ? resolve2(options.contentDir) : resolve2("src/content/docs");
|
|
255
|
+
return {
|
|
256
|
+
name: "astro-latex-compile",
|
|
257
|
+
hooks: {
|
|
258
|
+
"astro:build:start": async () => {
|
|
259
|
+
console.log(
|
|
260
|
+
"[astro-latex-compile] Build start, scanning for tex/latex compile blocks"
|
|
261
|
+
);
|
|
262
|
+
try {
|
|
263
|
+
await scanAndCompileLatex(contentDir, svgOutputDir);
|
|
264
|
+
} catch (err) {
|
|
265
|
+
console.error(
|
|
266
|
+
"[astro-latex-compile] Error during LaTeX compilation:",
|
|
267
|
+
err
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
"astro:build:done": async ({ dir }) => {
|
|
272
|
+
console.log(
|
|
273
|
+
"[astro-latex-compile] Build done, updating HTML references"
|
|
274
|
+
);
|
|
275
|
+
try {
|
|
276
|
+
await updateHtmlReferences(dir.pathname, contentDir, svgOutputDir);
|
|
277
|
+
} catch (err) {
|
|
278
|
+
console.error(
|
|
279
|
+
"[astro-latex-compile] Error updating HTML references:",
|
|
280
|
+
err
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
async function scanAndCompileLatex(dir, svgOutputDir) {
|
|
288
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
289
|
+
for (const entry of entries) {
|
|
290
|
+
const fullPath = join2(dir, entry.name);
|
|
291
|
+
if (entry.isDirectory()) {
|
|
292
|
+
await scanAndCompileLatex(fullPath, svgOutputDir);
|
|
293
|
+
} else if (entry.isFile()) {
|
|
294
|
+
const ext = extname(entry.name);
|
|
295
|
+
if (ext === ".md" || ext === ".mdx") {
|
|
296
|
+
await processMarkdownFile(fullPath, svgOutputDir);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function getLineNumber(content, position) {
|
|
302
|
+
return content.substring(0, position).split("\n").length;
|
|
303
|
+
}
|
|
304
|
+
async function processMarkdownFile(filePath, svgOutputDir) {
|
|
305
|
+
const content = await readFile(filePath, "utf-8");
|
|
306
|
+
const latexBlockRegex = /```(?:tex|latex)\s+compile\n([\s\S]*?)\n```/g;
|
|
307
|
+
const matches = content.matchAll(latexBlockRegex);
|
|
308
|
+
for (const match of matches) {
|
|
309
|
+
const latexCode = match[1];
|
|
310
|
+
const lineNumber = getLineNumber(content, match.index || 0);
|
|
311
|
+
try {
|
|
312
|
+
const result = compileLatexToSvg(latexCode, svgOutputDir);
|
|
313
|
+
const status = result.wasCompiled ? "compiled" : "used cached";
|
|
314
|
+
console.log(
|
|
315
|
+
`[astro-latex-compile] ${filePath}:${lineNumber}: ${status} ${result.hash}.svg`
|
|
316
|
+
);
|
|
317
|
+
} catch (err) {
|
|
318
|
+
console.error(
|
|
319
|
+
`[astro-latex-compile] Failed to compile LaTeX in ${filePath}:${lineNumber}:`,
|
|
320
|
+
err
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
async function updateHtmlReferences(buildDir, contentDir, svgOutputDir) {
|
|
326
|
+
const latexHashes = [];
|
|
327
|
+
const entries = await readdir(contentDir, { withFileTypes: true });
|
|
328
|
+
for (const entry of entries) {
|
|
329
|
+
const fullPath = join2(contentDir, entry.name);
|
|
330
|
+
if (entry.isDirectory()) {
|
|
331
|
+
await scanMarkdownForHashes(fullPath, latexHashes);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
await updateHtmlDirWithHashes(buildDir, latexHashes);
|
|
335
|
+
}
|
|
336
|
+
async function scanMarkdownForHashes(dir, hashes) {
|
|
337
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
338
|
+
for (const entry of entries) {
|
|
339
|
+
const fullPath = join2(dir, entry.name);
|
|
340
|
+
if (entry.isDirectory()) {
|
|
341
|
+
await scanMarkdownForHashes(fullPath, hashes);
|
|
342
|
+
} else if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".mdx"))) {
|
|
343
|
+
const content = await readFile(fullPath, "utf-8");
|
|
344
|
+
const latexBlockRegex = /```(?:tex|latex)\s+compile\n([\s\S]*?)\n```/g;
|
|
345
|
+
const matches = content.matchAll(latexBlockRegex);
|
|
346
|
+
for (const match of matches) {
|
|
347
|
+
const latexCode = match[1];
|
|
348
|
+
const hash = hashLatexCode2(latexCode);
|
|
349
|
+
hashes.push(hash);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
async function updateHtmlDirWithHashes(dir, hashes) {
|
|
355
|
+
let hashIndex = 0;
|
|
356
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
357
|
+
for (const entry of entries) {
|
|
358
|
+
const fullPath = join2(dir, entry.name);
|
|
359
|
+
if (entry.isDirectory()) {
|
|
360
|
+
await updateHtmlDirWithHashes(fullPath, hashes);
|
|
361
|
+
} else if (entry.isFile() && entry.name.endsWith(".html")) {
|
|
362
|
+
let content = await readFile(fullPath, "utf-8");
|
|
363
|
+
let modified = false;
|
|
364
|
+
content = content.replace(
|
|
365
|
+
/src="\/static\/tex-svgs\/[a-f0-9]+\.svg"/g,
|
|
366
|
+
() => {
|
|
367
|
+
if (hashIndex < hashes.length) {
|
|
368
|
+
modified = true;
|
|
369
|
+
return `src="/static/tex-svgs/${hashes[hashIndex++]}.svg"`;
|
|
370
|
+
}
|
|
371
|
+
return arguments[0];
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
if (modified) {
|
|
375
|
+
await writeFile(fullPath, content, "utf-8");
|
|
376
|
+
console.log(`[astro-latex-compile] Updated ${fullPath}`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/plugins/remark-latex-compile/starlight-plugin.ts
|
|
383
|
+
function starlightLatexCompile(options) {
|
|
384
|
+
return {
|
|
385
|
+
name: "starlight-latex-compile",
|
|
386
|
+
hooks: {
|
|
387
|
+
"config:setup": (hook) => {
|
|
388
|
+
hook.addIntegration({
|
|
389
|
+
name: "latex-compile-remark-integration",
|
|
390
|
+
hooks: {
|
|
391
|
+
"astro:config:setup": ({ updateConfig, config }) => {
|
|
392
|
+
const existingPlugins = (Array.isArray(config.markdown?.remarkPlugins) ? config.markdown.remarkPlugins : []).filter((p) => p !== void 0 && p !== null);
|
|
393
|
+
updateConfig({
|
|
394
|
+
markdown: {
|
|
395
|
+
remarkPlugins: [...existingPlugins, [remarkLatexCompile, options ?? {}]]
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
hook.addIntegration(
|
|
402
|
+
createAstroLatexIntegration({
|
|
403
|
+
svgOutputDir: options?.svgOutputDir
|
|
404
|
+
})
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
var starlight_plugin_default = starlightLatexCompile;
|
|
411
|
+
|
|
412
|
+
export {
|
|
413
|
+
compileLatexToSvg,
|
|
414
|
+
starlightLatexCompile,
|
|
415
|
+
starlight_plugin_default,
|
|
416
|
+
remarkLatexCompile
|
|
417
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HookParameters } from '@astrojs/starlight/types';
|
|
2
|
+
|
|
3
|
+
interface CompilationResult {
|
|
4
|
+
hash: string;
|
|
5
|
+
svgPath: string;
|
|
6
|
+
wasCompiled: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Compile LaTeX code to SVG.
|
|
10
|
+
*
|
|
11
|
+
* @param latexCode - The LaTeX code to compile (e.g., TikZ, pgfplots, etc.)
|
|
12
|
+
* @param svgOutputDir - The directory where SVG files should be written
|
|
13
|
+
* @returns Result object with hash, svgPath, and whether compilation occurred
|
|
14
|
+
* @throws Error if compilation fails
|
|
15
|
+
*/
|
|
16
|
+
declare function compileLatexToSvg(latexCode: string, svgOutputDir: string): CompilationResult;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Starlight plugin wrapper for remark-latex-compile.
|
|
20
|
+
*
|
|
21
|
+
* This plugin hooks into Starlight's config:setup to inject the remark-latex-compile
|
|
22
|
+
* plugin and the build-time Astro integration for scanning markdown files.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
type StarlightLatexCompileOptions = RemarkLatexCompileOptions;
|
|
26
|
+
declare function starlightLatexCompile(options?: StarlightLatexCompileOptions): {
|
|
27
|
+
name: string;
|
|
28
|
+
hooks: {
|
|
29
|
+
"config:setup": (hook: HookParameters<"config:setup">) => void;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
interface RemarkLatexCompileOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Directory where SVG files should be written.
|
|
36
|
+
* @default "public/static/tex-svgs"
|
|
37
|
+
*/
|
|
38
|
+
svgOutputDir?: string;
|
|
39
|
+
}
|
|
40
|
+
declare function remarkLatexCompile(options?: RemarkLatexCompileOptions): (tree: any) => void;
|
|
41
|
+
|
|
42
|
+
export { type RemarkLatexCompileOptions as R, type StarlightLatexCompileOptions as S, compileLatexToSvg as c, remarkLatexCompile as r, starlightLatexCompile as s };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { starlightIndexOnlySidebar } from './plugins/starlight-index-only-sidebar.js';
|
|
2
2
|
export { default as rehypeValidateLinks } from './plugins/rehype-validate-links.js';
|
|
3
3
|
import { AstroIntegration } from 'astro';
|
|
4
|
+
export { r as remarkLatexCompile, s as starlightLatexCompile } from './index-DapkTQmZ.js';
|
|
4
5
|
import '@astrojs/starlight/types';
|
|
5
6
|
import 'hast';
|
|
6
7
|
import 'vfile';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,10 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
rehypeValidateLinks
|
|
6
6
|
} from "./chunk-HRUZQZ5L.js";
|
|
7
|
+
import {
|
|
8
|
+
remarkLatexCompile,
|
|
9
|
+
starlightLatexCompile
|
|
10
|
+
} from "./chunk-IRJEKSXQ.js";
|
|
7
11
|
|
|
8
12
|
// src/plugins/astro-normalize-paths.ts
|
|
9
13
|
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
@@ -74,5 +78,7 @@ function normalizeAssetPath(path, htmlFile, siteRootPath) {
|
|
|
74
78
|
export {
|
|
75
79
|
astroNormalizePaths,
|
|
76
80
|
rehypeValidateLinks,
|
|
77
|
-
|
|
81
|
+
remarkLatexCompile,
|
|
82
|
+
starlightIndexOnlySidebar,
|
|
83
|
+
starlightLatexCompile
|
|
78
84
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-cannoli-plugins",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"description": "Starlight plugins for automatic sidebar generation and link validation",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -23,6 +23,14 @@
|
|
|
23
23
|
"import": "./dist/plugins/astro-normalize-paths.js",
|
|
24
24
|
"types": "./dist/plugins/astro-normalize-paths.d.ts"
|
|
25
25
|
},
|
|
26
|
+
"./remark-latex-compile": {
|
|
27
|
+
"import": "./dist/plugins/remark-latex-compile.js",
|
|
28
|
+
"types": "./dist/plugins/remark-latex-compile.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./starlight-latex-compile": {
|
|
31
|
+
"import": "./dist/plugins/starlight-latex-compile.js",
|
|
32
|
+
"types": "./dist/plugins/starlight-latex-compile.d.ts"
|
|
33
|
+
},
|
|
26
34
|
"./styles": "./dist/styles/",
|
|
27
35
|
"./styles/*": "./dist/styles/*"
|
|
28
36
|
},
|
|
File without changes
|