starlight-cannoli-plugins 1.2.2 → 1.2.4
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
CHANGED
|
@@ -57,7 +57,7 @@ Automatically compiles fenced `tex compile` and `latex compile` code blocks to S
|
|
|
57
57
|
- Compiles LaTeX/TikZ code blocks to SVG automatically
|
|
58
58
|
- Caches compiled SVGs by content hash (no recompilation if unchanged)
|
|
59
59
|
- Comprehensive error reporting with line numbers and formatted LaTeX source
|
|
60
|
-
- Supports custom preamble via
|
|
60
|
+
- Supports custom preamble via `% ===` separator in code blocks
|
|
61
61
|
- Works seamlessly with Starlight's content pipeline
|
|
62
62
|
- Requires `svgOutputDir` configuration (no defaults)
|
|
63
63
|
|
|
@@ -99,6 +99,8 @@ export default defineConfig({
|
|
|
99
99
|
|
|
100
100
|
**Markdown Syntax:**
|
|
101
101
|
|
|
102
|
+
Use either ` ```tex compile ` or ` ```latex compile ` — both work identically:
|
|
103
|
+
|
|
102
104
|
````markdown
|
|
103
105
|
```tex compile
|
|
104
106
|
\begin{tikzpicture}
|
|
@@ -111,13 +113,13 @@ export default defineConfig({
|
|
|
111
113
|
|
|
112
114
|
**Custom Preamble:**
|
|
113
115
|
|
|
114
|
-
Use
|
|
116
|
+
Use `% ===` to separate custom preamble from diagram content:
|
|
115
117
|
|
|
116
118
|
````markdown
|
|
117
119
|
```tex compile
|
|
118
120
|
\usepackage{tikz-3dplot}
|
|
119
121
|
|
|
120
|
-
|
|
122
|
+
% ===
|
|
121
123
|
|
|
122
124
|
\begin{tikzpicture}
|
|
123
125
|
% diagram code here
|
|
@@ -125,6 +127,40 @@ Use `%---` to separate custom preamble from diagram content:
|
|
|
125
127
|
```
|
|
126
128
|
````
|
|
127
129
|
|
|
130
|
+
**Complete Document Control:**
|
|
131
|
+
|
|
132
|
+
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:
|
|
133
|
+
|
|
134
|
+
````markdown
|
|
135
|
+
```tex compile
|
|
136
|
+
\documentclass[border=10pt]{standalone}
|
|
137
|
+
\usepackage{tikz}
|
|
138
|
+
\usepackage{amsmath}
|
|
139
|
+
|
|
140
|
+
\begin{document}
|
|
141
|
+
|
|
142
|
+
\begin{equation*}
|
|
143
|
+
E = mc^2
|
|
144
|
+
\end{equation*}
|
|
145
|
+
|
|
146
|
+
\end{document}
|
|
147
|
+
```
|
|
148
|
+
````
|
|
149
|
+
|
|
150
|
+
**Custom CSS Classes:**
|
|
151
|
+
|
|
152
|
+
Add custom CSS classes to the generated `<img>` that defines the compiled LaTeX diagram using `class="..."`:
|
|
153
|
+
|
|
154
|
+
````markdown
|
|
155
|
+
```tex compile class="bg-white rounded-1"
|
|
156
|
+
\begin{tikzpicture}
|
|
157
|
+
\node {Custom styled diagram};
|
|
158
|
+
\end{tikzpicture}
|
|
159
|
+
```
|
|
160
|
+
````
|
|
161
|
+
|
|
162
|
+
The img element will have classes: `tex-compiled bg-white rounded-1` (note: the `tex-compiled` class is always included by default).
|
|
163
|
+
|
|
128
164
|
### Remark LaTeX Compile
|
|
129
165
|
|
|
130
166
|
The underlying remark plugin that powers `starlightLatexCompile`. Use this directly in Astro projects that don't use Starlight.
|
|
@@ -173,7 +173,7 @@ function buildLatexSource(latexCode) {
|
|
|
173
173
|
if (latexCode.includes("\\documentclass") && latexCode.includes("\\begin{document}")) {
|
|
174
174
|
return latexCode.trim();
|
|
175
175
|
}
|
|
176
|
-
const separatorRegex = /%[ \t]
|
|
176
|
+
const separatorRegex = /%[ \t]*===/;
|
|
177
177
|
const parts = latexCode.split(separatorRegex);
|
|
178
178
|
let preamble = "";
|
|
179
179
|
let content = latexCode.trim();
|
|
@@ -241,6 +241,13 @@ Error: ${errorOutput}`
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
// src/plugins/remark-latex-compile/index.ts
|
|
244
|
+
function extractClassesFromMeta(meta) {
|
|
245
|
+
const classMatch = meta.match(/class="([^"]+)"/);
|
|
246
|
+
if (classMatch && classMatch[1]) {
|
|
247
|
+
return classMatch[1].split(/\s+/).filter(Boolean);
|
|
248
|
+
}
|
|
249
|
+
return [];
|
|
250
|
+
}
|
|
244
251
|
function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
245
252
|
if (!node) return;
|
|
246
253
|
const children = node.children;
|
|
@@ -250,6 +257,10 @@ function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
|
250
257
|
if (child.type === "code" && (child.lang === "tex" || child.lang === "latex") && String(child.meta || "").includes("compile")) {
|
|
251
258
|
try {
|
|
252
259
|
const result = compileLatexToSvg(String(child.value), svgOutputDir);
|
|
260
|
+
const customClasses = extractClassesFromMeta(
|
|
261
|
+
String(child.meta || "")
|
|
262
|
+
);
|
|
263
|
+
const allClasses = ["tex-compiled", ...customClasses];
|
|
253
264
|
children[i] = {
|
|
254
265
|
type: "paragraph",
|
|
255
266
|
children: [
|
|
@@ -259,7 +270,7 @@ function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
|
259
270
|
alt: "LaTeX diagram",
|
|
260
271
|
data: {
|
|
261
272
|
hProperties: {
|
|
262
|
-
className:
|
|
273
|
+
className: allClasses
|
|
263
274
|
}
|
|
264
275
|
}
|
|
265
276
|
}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED