A collection of powerful plugins for Astro Starlight documentation sites.
Automatically generates a nested Starlight sidebar by recursively scanning directories for index.md/index.mdx files. Only directories with index files appear in the sidebar, creating a clean, minimal navigation structure.
Features:
- Recursively scans directories for
index.mdorindex.mdxfiles - Creates sidebar entries only for pages with index files
- Respects frontmatter:
draft: trueandsidebar.hidden: truehide entries - Automatically collapses single-child groups (no intermediate wrappers)
- Configurable depth limiting to flatten deeply nested content
- Two labeling modes: directory names or frontmatter titles
- Ignores
assetsdirectories entirely
Options:
directories(required): Array of directory names to scan (e.g.,["guides", "api"])maxDepthNesting(optional, default:100): Maximum nesting depth. Root is level 0. At max depth, deeper index files are flattened as sibling items.dirnameDeterminesLabels(optional, default:true): Whentrue, all labels use raw directory names. Whenfalse, slug item labels come from frontmattertitlefield; group labels still use directory names.
Usage:
// astro.config.mjs
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import { starlightIndexOnlySidebar } from "starlight-cannoli-plugins";
export default defineConfig({
integrations: [
starlight({
title: "My Docs",
plugins: [
starlightIndexOnlySidebar({
directories: ["guides", "api", "tutorials"],
maxDepthNesting: 2, // optional
dirnameDeterminesLabels: false, // optional
}),
],
}),
],
});Automatically compiles fenced tex compile and latex compile code blocks to SVG diagrams during the build process. Uses pdflatex and dvisvgm for high-quality, cached SVG output.
Features:
- Compiles LaTeX/TikZ code blocks to SVG automatically
- Caches compiled SVGs by content hash (no recompilation if unchanged)
- Comprehensive error reporting with line numbers and formatted LaTeX source
- Supports custom preamble via
% ===separator in code blocks - Works with Starlight and plain Astro projects
- Requires
svgOutputDirconfiguration (no defaults)
System Requirements:
This plugin requires the following CLI tools to be installed and available on your system:
pdflatex— LaTeX compiler that produces PDF outputdvisvgm— Converts PDF to SVG format
Verify installation by running:
pdflatex --version
dvisvgm --versionOptions:
svgOutputDir(required): Directory where compiled SVG files are written. Must be insidepublic/so Astro serves them as static assets.removeOrphanedSvgs(optional, default:false): Whentrue, SVG files that are no longer referenced by anytex compileblock are deleted automatically. In dev mode, stale SVGs are removed immediately when a block is edited. On build, any remaining orphans are swept at the end.
Usage:
// astro.config.mjs
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import { astroLatexCompile } from "starlight-cannoli-plugins";
export default defineConfig({
integrations: [
astroLatexCompile({
svgOutputDir: "public/static/tex-svgs",
removeOrphanedSvgs: true, // optional
}),
starlight({ title: "My Docs" }),
],
});Markdown Syntax:
Use either ```tex compile or ```latex compile — both work identically:
```tex compile
\begin{tikzpicture}
\node (A) at (0,0) {A};
\node (B) at (2,0) {B};
\draw (A) -- (B);
\end{tikzpicture}
```Minimal approach:
Use % === to separate an optional custom preamble from your diagram content. The plugin wraps everything in the following document structure:
\documentclass[border=5pt]{standalone}
{your preamble}
\begin{document}
\Large
{your content}
\end{document}Example minimal tex code block:
```tex compile
\usepackage{tikz-3dplot}
% ===
\begin{tikzpicture}
% diagram code here
\end{tikzpicture}
```If no % === separator is present, the entire block is treated as content and wrapped in the same default document structure (with an empty preamble).
Complete Document Control:
If your code block contains both \documentclass and \begin{document}, the plugin treats it as a complete, self-contained LaTeX document and uses it as-is without checking for a % === separator for a preamble:
```tex compile
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
E = mc^2
\end{equation*}
\end{document}
```Custom CSS Classes:
Add custom CSS classes the tex compile code block to have them applied to the resulting <img> element:
```tex compile class="bg-white rounded-1"
\begin{tikzpicture}
\node {Custom styled diagram};
\end{tikzpicture}
```The img element will have classes: tex-compiled bg-white rounded-1 (note: the tex-compiled class is always included by default).
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.
Usage:
// astro.config.mjs
import { defineConfig } from "astro/config";
import { remarkLatexCompile } from "starlight-cannoli-plugins/astro-latex-compile";
export default defineConfig({
markdown: {
remarkPlugins: [
[remarkLatexCompile, { svgOutputDir: "public/static/tex-svgs" }],
],
},
});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.
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.
Features:
- Validates
<a href>and<img src>attributes - Supports relative paths (
../other) and absolute paths (/some/page) - Auto-expands extensionless links to match
.mdor.mdxfiles - Converts internal links to site-absolute paths
- Throws build errors for broken links
- Skip validation for forward-reference links using multiple approaches
Usage:
// astro.config.mjs
import { defineConfig } from "astro/config";
import { rehypeValidateLinks } from "starlight-cannoli-plugins";
export default defineConfig({
markdown: {
rehypePlugins: [rehypeValidateLinks],
},
});Or import directly:
import { rehypeValidateLinks } from "starlight-cannoli-plugins/rehype-validate-links";Skipping Link Validation:
There are three ways to skip validation for specific links:
1. Question Mark Prefix (Per-link, in markdown)
Prepend a ? to the link href to skip validation:
[Grade Calculator](?csci-320-331-obrenic/grade-calculator)
[Grade Calculator](?./csci-320-331-obrenic/grade-calculator)
[Grade Calculator](?/csci-320-331-obrenic/grade-calculator)2. HTML Data Attribute (Per-link, requires HTML syntax)
Use the data-no-link-check attribute on anchor tags:
<a href="csci-320-331-obrenic/grade-calculator" data-no-link-check>
Grade Calculator
</a>3. Global Skip Patterns (Configuration-based)
Use the skipPatterns option to exclude links matching glob patterns:
// astro.config.mjs
export default defineConfig({
markdown: {
rehypePlugins: [
[
rehypeValidateLinks,
{
skipPatterns: [
"/csci-320-331-obrenic/grade-calculator", // exact match
"**/draft-*", // glob pattern
],
},
],
],
},
});Syncs src/content/docs/ to public/ so local files (e.g., PDFs, images) referenced in markdown are served by the dev server and included in builds. In dev mode, it watches for file changes and re-syncs automatically — no restart needed.
Features:
- Syncs once at build start
- Watches for changes in dev mode and re-syncs automatically (debounced)
- Preserves specified child directories in
public/during sync (e.g.,static/) - Supports glob patterns to exclude files from syncing
Usage:
// astro.config.mjs
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import { syncDocsToPublic } from "starlight-cannoli-plugins";
export default defineConfig({
integrations: [
syncDocsToPublic({ preserveDirs: ["static"] }),
starlight({ title: "My Docs" }),
],
});Options:
preserveDirs(required): Names of child directories insidepublic/to preserve during sync. These will not be deleted when re-syncing.ignorePatterns(optional): Glob patterns for files to exclude from syncing. Patterns are matched against paths relative tosrc/content/docs/.
syncDocsToPublic({
preserveDirs: ["static"],
ignorePatterns: ["**/*.txt", "**/drafts/**"],
});A manual cleanup utility for the LaTeX compile plugin. Scans your markdown source files for all tex compile code blocks, hashes them, and identifies orphaned SVG files in the output directory that are no longer referenced by any code block.
Note: If you use
removeOrphanedSvgs: truein yourastroLatexCompileconfig, this CLI is generally not needed — orphaned SVGs are cleaned up automatically during both dev and build.
Usage:
Check for orphaned SVGs without deleting:
npx cannoli-latex-cleanup --svg-dir public/static/tex-svgs --checkDelete orphaned SVGs:
npx cannoli-latex-cleanup --svg-dir public/static/tex-svgs --deleteWith custom docs directory (defaults to src/content/docs):
npx cannoli-latex-cleanup --svg-dir public/static/tex-svgs --docs-dir ./src/content/docs --deleteOptions:
--svg-dir(required): Path to the SVG output directory configured inastroLatexCompile--docs-dir(optional, default:src/content/docs): Path to markdown source directory--check: List orphaned SVGs without deleting--delete: Delete orphaned SVGs
npm install starlight-cannoli-pluginsWith pnpm:
pnpm add starlight-cannoli-pluginsWith yarn:
yarn add starlight-cannoli-pluginsastro≥ 5.0.0@astrojs/starlight≥ 0.30.0 (optional, only needed if usingstarlightIndexOnlySidebar)
MIT
Contributions welcome! Feel free to open issues or submit pull requests.