starlight-cannoli-plugins 2.14.0 → 2.14.2
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/README.md +0 -22
- package/dist/{chunk-ETBDUEFH.js → chunk-RAKGKJJO.js} +12 -12
- package/dist/index.d.ts +3 -4
- package/dist/index.js +34 -6
- package/dist/plugins/astro-latex-compile.d.ts +5 -5
- package/dist/plugins/astro-latex-compile.js +3 -3
- package/dist/styles/_starlight.scss +0 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -231,28 +231,6 @@ The following attributes can be added to the opening fence:
|
|
|
231
231
|
```
|
|
232
232
|
````
|
|
233
233
|
|
|
234
|
-
### Remark LaTeX Compile (low-level)
|
|
235
|
-
|
|
236
|
-
The underlying remark plugin used by `astroLatexCompile`. Use this directly if you need to wire the transformer into a custom pipeline — most users should use `astroLatexCompile` instead.
|
|
237
|
-
|
|
238
|
-
**Usage:**
|
|
239
|
-
|
|
240
|
-
```ts
|
|
241
|
-
// astro.config.mjs
|
|
242
|
-
import { defineConfig } from "astro/config";
|
|
243
|
-
import { remarkLatexCompile } from "starlight-cannoli-plugins/astro-latex-compile";
|
|
244
|
-
|
|
245
|
-
export default defineConfig({
|
|
246
|
-
markdown: {
|
|
247
|
-
remarkPlugins: [
|
|
248
|
-
[remarkLatexCompile, { svgOutputDir: "public/static/tex-svgs" }],
|
|
249
|
-
],
|
|
250
|
-
},
|
|
251
|
-
});
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
Note: when used directly (without `astroLatexCompile`), the Starlight content layer cache is not cleared automatically, so SVGs may not recompile on repeat builds in Starlight projects.
|
|
255
|
-
|
|
256
234
|
### Rehype Validate Links
|
|
257
235
|
|
|
258
236
|
A rehype plugin that validates all internal links in your Markdown/MDX files at build time. Links without matching files will cause the build to fail.
|
|
@@ -112,7 +112,7 @@ function formatLatexError(parsed) {
|
|
|
112
112
|
const warningCount = parsed.errors.filter(
|
|
113
113
|
(e) => e.severity === "warning"
|
|
114
114
|
).length;
|
|
115
|
-
let output = `${RED}[
|
|
115
|
+
let output = `${RED}[astro-latex-compile] LaTeX compilation failed${RESET}
|
|
116
116
|
`;
|
|
117
117
|
output += `${RED}${errorCount} error${errorCount !== 1 ? "s" : ""}${RESET}`;
|
|
118
118
|
if (warningCount > 0) {
|
|
@@ -412,7 +412,7 @@ function buildLatexSource(latexCode) {
|
|
|
412
412
|
return latexCode.trim();
|
|
413
413
|
}
|
|
414
414
|
throw new Error(
|
|
415
|
-
`[
|
|
415
|
+
`[astro-latex-compile] Code block is not a complete LaTeX document. Blocks must contain both \\documentclass and \\begin{document}.`
|
|
416
416
|
);
|
|
417
417
|
}
|
|
418
418
|
async function compileLatexToSvg(latexCode, svgOutputDir, texInputDirs = [], inputsSalt = "") {
|
|
@@ -442,7 +442,7 @@ async function compileLatexToSvg(latexCode, svgOutputDir, texInputDirs = [], inp
|
|
|
442
442
|
} catch (err) {
|
|
443
443
|
const code = err.code;
|
|
444
444
|
throw new Error(
|
|
445
|
-
`[
|
|
445
|
+
`[astro-latex-compile] pdflatex not found on PATH (${code}).`,
|
|
446
446
|
{ cause: err }
|
|
447
447
|
);
|
|
448
448
|
}
|
|
@@ -466,14 +466,14 @@ async function compileLatexToSvg(latexCode, svgOutputDir, texInputDirs = [], inp
|
|
|
466
466
|
} catch (err) {
|
|
467
467
|
const code = err.code;
|
|
468
468
|
throw new Error(
|
|
469
|
-
`[
|
|
469
|
+
`[astro-latex-compile] dvisvgm not found on PATH (${code}).`,
|
|
470
470
|
{ cause: err }
|
|
471
471
|
);
|
|
472
472
|
}
|
|
473
473
|
if (svgResult.status !== 0) {
|
|
474
474
|
const errorOutput = svgResult.stderr || svgResult.stdout || "";
|
|
475
475
|
throw new Error(
|
|
476
|
-
`[
|
|
476
|
+
`[astro-latex-compile] PDF to SVG conversion failed (hash: ${hash}).
|
|
477
477
|
Error: ${errorOutput}`
|
|
478
478
|
);
|
|
479
479
|
}
|
|
@@ -497,7 +497,7 @@ function getFrontmatterOffset(absoluteFilePath) {
|
|
|
497
497
|
return 0;
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
|
-
function
|
|
500
|
+
function latexCompileTransformer(options) {
|
|
501
501
|
const svgOutputDir = resolve2(options.svgOutputDir);
|
|
502
502
|
return async function transformer(tree, file) {
|
|
503
503
|
const nodes = [];
|
|
@@ -526,14 +526,14 @@ function remarkLatexCompile(options) {
|
|
|
526
526
|
);
|
|
527
527
|
if (result.wasCompiled) {
|
|
528
528
|
console.log(
|
|
529
|
-
`[
|
|
529
|
+
`[astro-latex-compile] ${relFilePath}:${lineNumberStr}: compiled ${result.hash}.svg`
|
|
530
530
|
);
|
|
531
531
|
}
|
|
532
532
|
options._referencedHashes?.add(result.hash);
|
|
533
533
|
if (jpgPath) {
|
|
534
534
|
await writeJpgFromSvg(result.svgPath, jpgPath);
|
|
535
535
|
console.log(
|
|
536
|
-
`[
|
|
536
|
+
`[astro-latex-compile] ${relFilePath}:${lineNumberStr}: wrote ${jpgPath}`
|
|
537
537
|
);
|
|
538
538
|
}
|
|
539
539
|
return {
|
|
@@ -549,7 +549,7 @@ function remarkLatexCompile(options) {
|
|
|
549
549
|
const match = errorMsg.match(/\n\n([\s\S]+)/);
|
|
550
550
|
const details = match ? match[1] : errorMsg;
|
|
551
551
|
console.error(
|
|
552
|
-
`[
|
|
552
|
+
`[astro-latex-compile] ${relFilePath}:${lineNumberStr}
|
|
553
553
|
${details}`
|
|
554
554
|
);
|
|
555
555
|
if (jpgPath) {
|
|
@@ -578,7 +578,7 @@ ${details}`
|
|
|
578
578
|
const staleHashes = [...oldHashes].filter((h) => !newHashes.has(h));
|
|
579
579
|
for (const staleHash of staleHashes) {
|
|
580
580
|
console.warn(
|
|
581
|
-
`[
|
|
581
|
+
`[astro-latex-compile] Removing orphaned svg: ${staleHash}.svg`
|
|
582
582
|
);
|
|
583
583
|
}
|
|
584
584
|
await Promise.all(
|
|
@@ -596,7 +596,7 @@ ${details}`
|
|
|
596
596
|
const staleJpgPaths = [...oldJpgPaths].filter((p) => !newJpgPaths.has(p));
|
|
597
597
|
for (const stalePath of staleJpgPaths) {
|
|
598
598
|
console.warn(
|
|
599
|
-
`[
|
|
599
|
+
`[astro-latex-compile] Removing orphaned jpg: ${stalePath}`
|
|
600
600
|
);
|
|
601
601
|
}
|
|
602
602
|
await Promise.all(staleJpgPaths.map((p) => rm(p, { force: true })));
|
|
@@ -642,5 +642,5 @@ ${details}`
|
|
|
642
642
|
|
|
643
643
|
export {
|
|
644
644
|
compileLatexToSvg,
|
|
645
|
-
|
|
645
|
+
latexCompileTransformer
|
|
646
646
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,14 +4,13 @@ export { DomPatchesOptions, starlightDomPatches } from './plugins/starlight-dom-
|
|
|
4
4
|
export { SyncDocsToPublicOptions, syncDocsToPublic } from './plugins/astro-sync-docs-to-public.js';
|
|
5
5
|
export { rehypeValidateLinks } from './plugins/rehype-validate-links.js';
|
|
6
6
|
export { astroNormalizePaths } from './plugins/astro-normalize-paths.js';
|
|
7
|
-
import { RemarkLatexCompileOptions } from './plugins/astro-latex-compile.js';
|
|
8
|
-
export { remarkLatexCompile } from './plugins/astro-latex-compile.js';
|
|
9
7
|
export { expressiveCodeEmphasis } from './plugins/expressive-code-emphasis.js';
|
|
10
8
|
import { AstroIntegration } from 'astro';
|
|
9
|
+
import { LatexCompilePluginOptions } from './plugins/astro-latex-compile.js';
|
|
11
10
|
import 'hast';
|
|
12
11
|
import 'vfile';
|
|
13
|
-
import 'mdast';
|
|
14
12
|
import 'expressive-code';
|
|
13
|
+
import 'mdast';
|
|
15
14
|
|
|
16
15
|
type TBadgeVariant = "note" | "danger" | "success" | "caution" | "tip" | "default";
|
|
17
16
|
type TIndexMarker = {
|
|
@@ -67,7 +66,7 @@ declare function starlightIndexSourcedSidebar(options: TOptions): {
|
|
|
67
66
|
};
|
|
68
67
|
};
|
|
69
68
|
|
|
70
|
-
interface LatexCompileOptions extends
|
|
69
|
+
interface LatexCompileOptions extends LatexCompilePluginOptions {
|
|
71
70
|
/**
|
|
72
71
|
* When `true`, SVG files in `svgOutputDir` that are no longer referenced by
|
|
73
72
|
* any `tex compile` block are deleted automatically. In dev mode, stale SVGs
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
rehypeValidateLinks
|
|
9
9
|
} from "./chunk-3UMY7T6G.js";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
11
|
+
latexCompileTransformer
|
|
12
|
+
} from "./chunk-RAKGKJJO.js";
|
|
13
13
|
import {
|
|
14
14
|
astroNormalizePaths
|
|
15
15
|
} from "./chunk-TLOFSB33.js";
|
|
@@ -232,6 +232,26 @@ function starlightIndexSourcedSidebar(options) {
|
|
|
232
232
|
import fs2 from "fs";
|
|
233
233
|
import { readdir, rm } from "fs/promises";
|
|
234
234
|
import { join as join3, resolve as resolve2 } from "path";
|
|
235
|
+
var js = String.raw;
|
|
236
|
+
var DARK_MODE_ROTATE = "178deg";
|
|
237
|
+
var INJECTED_CSS = `
|
|
238
|
+
:root {
|
|
239
|
+
--cannoli-error-low: hsl(0, 70%, 94%);
|
|
240
|
+
--cannoli-error: hsl(0, 72%, 42%);
|
|
241
|
+
--cannoli-error-high: hsl(0, 72%, 28%);
|
|
242
|
+
}
|
|
243
|
+
[data-theme="dark"] {
|
|
244
|
+
--cannoli-error-low: hsl(0, 55%, 16%);
|
|
245
|
+
--cannoli-error: hsl(0, 75%, 60%);
|
|
246
|
+
--cannoli-error-high: hsl(0, 80%, 82%);
|
|
247
|
+
}
|
|
248
|
+
.tex-compiled {
|
|
249
|
+
background-color: transparent;
|
|
250
|
+
}
|
|
251
|
+
html[data-theme="dark"] .tex-compiled {
|
|
252
|
+
filter: invert(1) hue-rotate(${DARK_MODE_ROTATE});
|
|
253
|
+
}
|
|
254
|
+
`;
|
|
235
255
|
var DATA_STORE_FILE = "data-store.json";
|
|
236
256
|
function getDataStoreFile(config) {
|
|
237
257
|
return new URL(DATA_STORE_FILE, config.cacheDir);
|
|
@@ -249,13 +269,22 @@ function astroLatexCompile(options) {
|
|
|
249
269
|
return {
|
|
250
270
|
name: "astro-latex-compile",
|
|
251
271
|
hooks: {
|
|
252
|
-
"astro:config:setup": async ({
|
|
272
|
+
"astro:config:setup": async ({
|
|
273
|
+
command,
|
|
274
|
+
config,
|
|
275
|
+
updateConfig,
|
|
276
|
+
injectScript
|
|
277
|
+
}) => {
|
|
253
278
|
if (command !== "build" && command !== "dev") return;
|
|
279
|
+
injectScript(
|
|
280
|
+
"page",
|
|
281
|
+
js`{ const s = document.createElement("style"); s.textContent = ${JSON.stringify(INJECTED_CSS)}; document.head.appendChild(s); }`
|
|
282
|
+
);
|
|
254
283
|
if (command === "build") {
|
|
255
284
|
await clearContentLayerCache(config);
|
|
256
285
|
}
|
|
257
286
|
const existingPlugins = Array.isArray(config.markdown?.remarkPlugins) ? config.markdown.remarkPlugins.filter(Boolean) : [];
|
|
258
|
-
const
|
|
287
|
+
const pluginOptions = {
|
|
259
288
|
...options,
|
|
260
289
|
_fileHashMap: options.removeOrphanedSvgs ? fileHashMap : void 0,
|
|
261
290
|
_referencedHashes: command === "build" && options.removeOrphanedSvgs ? referencedHashes : void 0,
|
|
@@ -265,7 +294,7 @@ function astroLatexCompile(options) {
|
|
|
265
294
|
markdown: {
|
|
266
295
|
remarkPlugins: [
|
|
267
296
|
...existingPlugins,
|
|
268
|
-
[
|
|
297
|
+
[latexCompileTransformer, pluginOptions]
|
|
269
298
|
]
|
|
270
299
|
}
|
|
271
300
|
});
|
|
@@ -299,7 +328,6 @@ export {
|
|
|
299
328
|
astroNormalizePaths,
|
|
300
329
|
expressiveCodeEmphasis,
|
|
301
330
|
rehypeValidateLinks,
|
|
302
|
-
remarkLatexCompile,
|
|
303
331
|
starlightDomPatches,
|
|
304
332
|
starlightIndexOnlySidebar,
|
|
305
333
|
starlightIndexSourcedSidebar,
|
|
@@ -16,7 +16,7 @@ interface CompilationResult {
|
|
|
16
16
|
*/
|
|
17
17
|
declare function compileLatexToSvg(latexCode: string, svgOutputDir: string, texInputDirs?: string[], inputsSalt?: string): Promise<CompilationResult>;
|
|
18
18
|
|
|
19
|
-
interface
|
|
19
|
+
interface LatexCompilePluginOptions {
|
|
20
20
|
/**
|
|
21
21
|
* Directory where SVG files should be written.
|
|
22
22
|
* Must be inside `public/` so Astro serves them as static assets.
|
|
@@ -51,15 +51,15 @@ interface RemarkLatexCompileOptions {
|
|
|
51
51
|
_referencedHashes?: Set<string>;
|
|
52
52
|
/**
|
|
53
53
|
* @internal Maps each file path to the set of hashes it produced on the
|
|
54
|
-
* previous
|
|
54
|
+
* previous run. Used to delete stale SVGs when a block changes.
|
|
55
55
|
*/
|
|
56
56
|
_fileHashMap?: Map<string, Set<string>>;
|
|
57
57
|
/**
|
|
58
58
|
* @internal Maps each file path to the set of JPG paths it produced on the
|
|
59
|
-
* previous
|
|
59
|
+
* previous run. Used to delete stale JPGs when a block changes.
|
|
60
60
|
*/
|
|
61
61
|
_fileJpgPathMap?: Map<string, Set<string>>;
|
|
62
62
|
}
|
|
63
|
-
declare function
|
|
63
|
+
declare function latexCompileTransformer(options: LatexCompilePluginOptions): (tree: Root, file: VFile) => Promise<void>;
|
|
64
64
|
|
|
65
|
-
export { type
|
|
65
|
+
export { type LatexCompilePluginOptions, compileLatexToSvg, latexCompileTransformer };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
compileLatexToSvg,
|
|
3
|
-
|
|
4
|
-
} from "../chunk-
|
|
3
|
+
latexCompileTransformer
|
|
4
|
+
} from "../chunk-RAKGKJJO.js";
|
|
5
5
|
import "../chunk-C2VXRQOK.js";
|
|
6
6
|
import "../chunk-4VNS5WPM.js";
|
|
7
7
|
export {
|
|
8
8
|
compileLatexToSvg,
|
|
9
|
-
|
|
9
|
+
latexCompileTransformer
|
|
10
10
|
};
|
|
@@ -2,21 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
$DARK_MODE_ROTATE: 178deg;
|
|
4
4
|
|
|
5
|
-
/********** Custom Error Colors **********/
|
|
6
|
-
// Starlight's --sl-color-red-* sit at hsl(349°) which reads as pink/magenta.
|
|
7
|
-
// These replacements use true red (0°) for a more conventional error appearance.
|
|
8
|
-
:root {
|
|
9
|
-
--cannoli-error-low: hsl(0, 70%, 94%);
|
|
10
|
-
--cannoli-error: hsl(0, 72%, 42%);
|
|
11
|
-
--cannoli-error-high: hsl(0, 72%, 28%);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
[data-theme="dark"] {
|
|
15
|
-
--cannoli-error-low: hsl(0, 55%, 16%);
|
|
16
|
-
--cannoli-error: hsl(0, 75%, 60%);
|
|
17
|
-
--cannoli-error-high: hsl(0, 80%, 82%);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
5
|
.sl-container:where(.astro-7nkwcw3z) {
|
|
21
6
|
max-width: 50rem;
|
|
22
7
|
}
|
|
@@ -267,11 +252,3 @@ img.note-svg {
|
|
|
267
252
|
filter: invert(1) hue-rotate($DARK_MODE_ROTATE);
|
|
268
253
|
}
|
|
269
254
|
}
|
|
270
|
-
|
|
271
|
-
.tex-compiled {
|
|
272
|
-
background-color: transparent;
|
|
273
|
-
|
|
274
|
-
html[data-theme="dark"] & {
|
|
275
|
-
filter: invert(1) hue-rotate($DARK_MODE_ROTATE);
|
|
276
|
-
}
|
|
277
|
-
}
|
package/package.json
CHANGED