starlight-cannoli-plugins 1.2.1 → 1.2.3
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
|
@@ -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}
|
|
@@ -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.
|
|
@@ -170,6 +170,9 @@ function hashLatexCode(code) {
|
|
|
170
170
|
return createHash("md5").update(normalized).digest("hex").slice(0, 16);
|
|
171
171
|
}
|
|
172
172
|
function buildLatexSource(latexCode) {
|
|
173
|
+
if (latexCode.includes("\\documentclass") && latexCode.includes("\\begin{document}")) {
|
|
174
|
+
return latexCode.trim();
|
|
175
|
+
}
|
|
173
176
|
const separatorRegex = /%[ \t]*---/;
|
|
174
177
|
const parts = latexCode.split(separatorRegex);
|
|
175
178
|
let preamble = "";
|
|
@@ -238,6 +241,13 @@ Error: ${errorOutput}`
|
|
|
238
241
|
}
|
|
239
242
|
|
|
240
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
|
+
}
|
|
241
251
|
function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
242
252
|
if (!node) return;
|
|
243
253
|
const children = node.children;
|
|
@@ -247,6 +257,10 @@ function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
|
247
257
|
if (child.type === "code" && (child.lang === "tex" || child.lang === "latex") && String(child.meta || "").includes("compile")) {
|
|
248
258
|
try {
|
|
249
259
|
const result = compileLatexToSvg(String(child.value), svgOutputDir);
|
|
260
|
+
const customClasses = extractClassesFromMeta(
|
|
261
|
+
String(child.meta || "")
|
|
262
|
+
);
|
|
263
|
+
const allClasses = ["tex-compiled", ...customClasses];
|
|
250
264
|
children[i] = {
|
|
251
265
|
type: "paragraph",
|
|
252
266
|
children: [
|
|
@@ -256,7 +270,7 @@ function traverseTree(node, svgOutputDir, filePath, depth = 0) {
|
|
|
256
270
|
alt: "LaTeX diagram",
|
|
257
271
|
data: {
|
|
258
272
|
hProperties: {
|
|
259
|
-
className:
|
|
273
|
+
className: allClasses
|
|
260
274
|
}
|
|
261
275
|
}
|
|
262
276
|
}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED