astro-mermaid 2.0.4 → 2.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/README.md +16 -0
- package/astro-mermaid-integration.js +72 -7
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -75,6 +75,22 @@ npm install @mermaid-js/layout-elk
|
|
|
75
75
|
|
|
76
76
|
Learn more about [Mermaid layouts](https://mermaid.js.org/config/layouts.html) or [The Eclipse Layout Kernel](https://eclipse.dev/elk/).
|
|
77
77
|
|
|
78
|
+
## Astro Compatibility
|
|
79
|
+
|
|
80
|
+
`astro-mermaid` works across Astro 4, 5, 6, and 7 — no configuration needed. It
|
|
81
|
+
detects the active markdown engine at build time and registers its transform the
|
|
82
|
+
right way for each:
|
|
83
|
+
|
|
84
|
+
| Astro version | Markdown engine | How mermaid hooks in |
|
|
85
|
+
|---------------|-----------------|----------------------|
|
|
86
|
+
| 7+ | Sätteri (`@astrojs/markdown-satteri`, the new default) | a Sätteri **mdast plugin** |
|
|
87
|
+
| 6.4 – 6.x | `unified()` processor | remark + rehype plugins via `markdown.processor` |
|
|
88
|
+
| < 6.4 | legacy pipeline | `markdown.remarkPlugins` / `markdown.rehypePlugins` |
|
|
89
|
+
|
|
90
|
+
If you previously pinned `markdown.processor` to `unified()` purely to keep
|
|
91
|
+
mermaid working on Astro 7, you can now drop that workaround and let Astro use
|
|
92
|
+
its default Sätteri processor.
|
|
93
|
+
|
|
78
94
|
## Integration Order (Important!)
|
|
79
95
|
|
|
80
96
|
When using with Starlight or other markdown-processing integrations, place mermaid **first**:
|
|
@@ -81,6 +81,40 @@ function remarkMermaidPlugin(options = {}) {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Sätteri mdast plugin to transform mermaid code blocks at the markdown level.
|
|
86
|
+
*
|
|
87
|
+
* Astro 7 ships `@astrojs/markdown-satteri` as the default markdown processor,
|
|
88
|
+
* which has its own mdast/hast plugin model instead of remark/rehype. This is
|
|
89
|
+
* the Sätteri equivalent of `remarkMermaidPlugin`: it visits `code` nodes and
|
|
90
|
+
* replaces mermaid blocks with a `<pre class="mermaid">` HTML node. Fixes #71.
|
|
91
|
+
*
|
|
92
|
+
* The visitor returns a plain `{ type: 'html' }` node — NOT Sätteri's
|
|
93
|
+
* `{ rawHtml }` escape hatch. `rawHtml` applies MDX-style brace escaping that
|
|
94
|
+
* corrupts mermaid syntax (e.g. a decision node `B{Decision}` becomes
|
|
95
|
+
* `B{'{'}Decision{'}'}`), whereas an `html` node is emitted verbatim.
|
|
96
|
+
*
|
|
97
|
+
* @returns {{ name: string, code: Function }} a Sätteri mdast plugin definition
|
|
98
|
+
*/
|
|
99
|
+
function satteriMermaidPlugin(options = {}) {
|
|
100
|
+
return {
|
|
101
|
+
name: 'astro-mermaid',
|
|
102
|
+
code(node, context) {
|
|
103
|
+
if (node.lang !== 'mermaid') return;
|
|
104
|
+
|
|
105
|
+
if (options.logger) {
|
|
106
|
+
const file = context?.fileURL?.pathname || 'unknown file';
|
|
107
|
+
options.logger.info(`Sätteri transformed mermaid block in ${file}`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
type: 'html',
|
|
112
|
+
value: `<pre class="mermaid">${escapeHtml(node.value)}</pre>`
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
84
118
|
/**
|
|
85
119
|
* Escape a string for safe use inside an HTML attribute value.
|
|
86
120
|
*/
|
|
@@ -259,16 +293,20 @@ export default function astroMermaid(options = {}) {
|
|
|
259
293
|
const rehypeEntry = [rehypeMermaidPlugin, { logger }];
|
|
260
294
|
const viteConfig = { optimizeDeps: { include: viteOptimizeDepsInclude } };
|
|
261
295
|
|
|
262
|
-
// Astro
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
// (
|
|
296
|
+
// Newer Astro versions expose the markdown engine on
|
|
297
|
+
// `config.markdown.processor`, and the deprecated top-level
|
|
298
|
+
// `markdown.remarkPlugins` / `markdown.rehypePlugins` arrays no longer
|
|
299
|
+
// run on it. We dispatch on the processor's `name`:
|
|
300
|
+
// - 'unified' (Astro 6.4+): pass plugins via `unified({...})`. Fixes #62.
|
|
301
|
+
// - 'satteri' (Astro 7+): register an mdast plugin via `satteri({...})`. Fixes #71.
|
|
302
|
+
// - no processor (Astro <6.4): fall back to the still-supported arrays.
|
|
303
|
+
// Branching on `name` (rather than importing both helper packages)
|
|
304
|
+
// matters because Astro 7 does not ship `@astrojs/markdown-remark`, so a
|
|
305
|
+
// blind import there would emit a misleading warning.
|
|
268
306
|
const existingProcessor = config.markdown?.processor;
|
|
269
307
|
let usedProcessor = false;
|
|
270
308
|
|
|
271
|
-
if (existingProcessor) {
|
|
309
|
+
if (existingProcessor?.name === 'unified') {
|
|
272
310
|
try {
|
|
273
311
|
const { unified, isUnifiedProcessor } = await import('@astrojs/markdown-remark');
|
|
274
312
|
if (isUnifiedProcessor(existingProcessor)) {
|
|
@@ -294,6 +332,33 @@ export default function astroMermaid(options = {}) {
|
|
|
294
332
|
`to remark/rehype plugin arrays: ${error.message}`
|
|
295
333
|
);
|
|
296
334
|
}
|
|
335
|
+
} else if (existingProcessor?.name === 'satteri') {
|
|
336
|
+
try {
|
|
337
|
+
const { satteri, isSatteriProcessor } = await import('@astrojs/markdown-satteri');
|
|
338
|
+
if (isSatteriProcessor(existingProcessor)) {
|
|
339
|
+
const existingOptions = existingProcessor.options || {};
|
|
340
|
+
updateConfig({
|
|
341
|
+
markdown: {
|
|
342
|
+
processor: satteri({
|
|
343
|
+
...existingOptions,
|
|
344
|
+
mdastPlugins: [
|
|
345
|
+
...(existingOptions.mdastPlugins || []),
|
|
346
|
+
satteriMermaidPlugin({ logger })
|
|
347
|
+
]
|
|
348
|
+
})
|
|
349
|
+
},
|
|
350
|
+
vite: viteConfig
|
|
351
|
+
});
|
|
352
|
+
usedProcessor = true;
|
|
353
|
+
}
|
|
354
|
+
} catch (error) {
|
|
355
|
+
// Dynamic import failed or updateConfig rejected the processor —
|
|
356
|
+
// fall through to the legacy plugin arrays below.
|
|
357
|
+
logger.warn(
|
|
358
|
+
`Could not configure the Sätteri markdown processor, falling back ` +
|
|
359
|
+
`to remark/rehype plugin arrays: ${error.message}`
|
|
360
|
+
);
|
|
361
|
+
}
|
|
297
362
|
}
|
|
298
363
|
|
|
299
364
|
if (!usedProcessor) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-mermaid",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "An Astro integration for rendering Mermaid diagrams with automatic theme switching and client-side rendering",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./astro-mermaid-integration.js",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"semantic-release": "semantic-release"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
+
"@astrojs/markdown-satteri": "^0.3.2",
|
|
61
62
|
"@types/hast": "^3.0.4",
|
|
62
63
|
"@vitest/ui": "^4.1.8",
|
|
63
64
|
"astro": "^6.4.6",
|
|
@@ -67,6 +68,7 @@
|
|
|
67
68
|
"rehype-stringify": "^10.0.1",
|
|
68
69
|
"remark-mermaid": "^0.2.0",
|
|
69
70
|
"remark-parse": "^11.0.0",
|
|
71
|
+
"satteri": "^0.9.2",
|
|
70
72
|
"semantic-release": "^25.0.3",
|
|
71
73
|
"typescript": "^5.0.0",
|
|
72
74
|
"unified": "^11.0.5",
|