astro-dgmo 0.10.4 → 0.11.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 -19
- package/dist/index.d.ts +35 -8
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -76,16 +76,7 @@ export default defineConfig({
|
|
|
76
76
|
});
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```astro
|
|
82
|
-
---
|
|
83
|
-
// src/layouts/Base.astro
|
|
84
|
-
import 'remark-dgmo/client.css';
|
|
85
|
-
---
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
That's the whole integration. Anywhere in your Markdown or MDX content, write a fenced block with the language `dgmo`:
|
|
79
|
+
That's the whole integration — no stylesheet to wire up, no layout to edit. (Before 0.11.0 you had to add `import 'remark-dgmo/client.css'` to a global layout yourself, and a site that skipped it rendered every diagram twice.) Anywhere in your Markdown or MDX content, write a fenced block with the language `dgmo`:
|
|
89
80
|
|
|
90
81
|
````markdown
|
|
91
82
|
```dgmo
|
|
@@ -198,31 +189,37 @@ Opens at http://localhost:4321 with four example diagrams (plain auto, colored t
|
|
|
198
189
|
|
|
199
190
|
## How CSS is delivered
|
|
200
191
|
|
|
201
|
-
|
|
192
|
+
Under the default `colorMode: 'auto'` each fence renders **two** SVGs, light and dark. `remark-dgmo/client.css` is what hides the one you are not currently in, and since 0.11.0 the integration delivers it for you: `injectScript('page-ssr', "import 'remark-dgmo/client.css';")` imports the module into every page's frontmatter, and Astro's Vite pipeline turns that into a `<style>` block in `<head>` (or a linked stylesheet above its inline threshold).
|
|
193
|
+
|
|
194
|
+
Opt out with `dgmo({ injectClientCss: false })` if you ship your own copy of the color-mode rules. Importing the stylesheet yourself as well is harmless — Vite resolves both to one module.
|
|
195
|
+
|
|
196
|
+
**Why this changed.** Through 0.10.x the import was a manual step, and this README called it unavoidable on the grounds that Astro's `IntegrationHook` has no stylesheet API. That premise is true and the conclusion was wrong: `page-ssr` is the route [Astro's own integration reference](https://docs.astro.build/en/reference/integrations-reference/) documents for injecting CSS. Meanwhile a site that did not know to add the line rendered the same diagram twice, stacked, with a green build and no warning anywhere.
|
|
202
197
|
|
|
203
198
|
A small client script (~600 bytes) is injected via `injectScript('page', …)`. It tightens each diagram's `viewBox` to its content bounds and binds showcase-mode copy buttons. If your site forbids inline scripts via CSP, ignore this script — diagrams still render, but layout may have extra whitespace and copy buttons won't function.
|
|
204
199
|
|
|
205
200
|
## Custom color-mode selector
|
|
206
201
|
|
|
207
|
-
The shipped
|
|
202
|
+
The shipped stylesheet keys dark mode on **both** conventions, so nothing is needed for either of these:
|
|
203
|
+
|
|
204
|
+
- `data-theme="dark"` on `<html>` — Starlight, Docusaurus
|
|
205
|
+
- `class="dark"` on `<html>` — Tailwind, next-themes
|
|
206
|
+
|
|
207
|
+
If your site marks dark mode some third way (`data-color-scheme="dark"`, `:root[data-mode="dark"]`), add the pair of rules with your own selector — no need to opt out of the injected stylesheet, since these simply layer on top:
|
|
208
208
|
|
|
209
209
|
```css
|
|
210
|
-
.dgmo-
|
|
211
|
-
display: none;
|
|
212
|
-
}
|
|
213
|
-
html.dark .dgmo-light {
|
|
210
|
+
[data-mode='dark'] .dgmo-light {
|
|
214
211
|
display: none;
|
|
215
212
|
}
|
|
216
|
-
|
|
213
|
+
[data-mode='dark'] .dgmo-dark {
|
|
217
214
|
display: block;
|
|
218
215
|
}
|
|
219
216
|
```
|
|
220
217
|
|
|
221
|
-
|
|
218
|
+
If your site has no dark mode at all, you get the light diagram and nothing else to do: the dark wrapper ships with the `hidden` attribute, so it stays hidden until one of the rules above overrides it.
|
|
222
219
|
|
|
223
220
|
## How it works
|
|
224
221
|
|
|
225
|
-
1. The Astro integration registers a remark plugin via `astro:config:setup
|
|
222
|
+
1. The Astro integration registers a remark plugin via `astro:config:setup`, inline-injects the `remark-dgmo` client script via `injectScript('page', …)`, and adds the color-mode stylesheet via `injectScript('page-ssr', …)`.
|
|
226
223
|
2. The remark plugin walks `.md`/`.mdx` ASTs after parse, finding `code` nodes whose `lang === 'dgmo'`.
|
|
227
224
|
3. Each block is rendered to an SVG string by calling `render()` from `@diagrammo/dgmo` — once per theme under default `colorMode: 'auto'`, or once total under `'light'` / `'dark'`. Width/height are stripped and a `viewBox` is added so the diagram scales responsively.
|
|
228
225
|
4. The original `code` node is replaced with an `html` node containing the rendered wrapper(s).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { AstroIntegration } from 'astro';
|
|
2
2
|
import { DgmoOptions } from 'remark-dgmo';
|
|
3
|
-
export {
|
|
3
|
+
export { Mode, Theme, default as remarkDgmo } from 'remark-dgmo';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Backward-compat shim. The real types live in `remark-dgmo`; this module
|
|
7
|
+
* re-exports them under the conventional `DgmoIntegrationOptions` name so
|
|
8
|
+
* existing user code continues to type-check.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `remark-dgmo`'s options, plus the one setting that is Astro's alone.
|
|
13
|
+
*/
|
|
14
|
+
type DgmoIntegrationOptions = DgmoOptions & {
|
|
15
|
+
/**
|
|
16
|
+
* Whether the integration adds `remark-dgmo/client.css` to every page.
|
|
17
|
+
* Default `true`.
|
|
18
|
+
*
|
|
19
|
+
* Under the default `colorMode: 'auto'` each fence renders TWO SVGs, and
|
|
20
|
+
* that stylesheet is what hides the one you are not in. It used to be a
|
|
21
|
+
* manual `import` in a layout, which people reasonably did not know to do,
|
|
22
|
+
* and the result was the same diagram printed twice with a green build and
|
|
23
|
+
* nothing said (issue 507).
|
|
24
|
+
*
|
|
25
|
+
* Set `false` only if you ship your own copy of those rules — e.g. you
|
|
26
|
+
* re-key the dark selector onto a signal neither `data-theme="dark"` nor
|
|
27
|
+
* `html.dark` covers. Leaving it `true` while also importing the stylesheet
|
|
28
|
+
* yourself is harmless: Vite resolves both to one module.
|
|
29
|
+
*/
|
|
30
|
+
injectClientCss?: boolean;
|
|
31
|
+
};
|
|
4
32
|
|
|
5
33
|
/**
|
|
6
34
|
* Astro integration that renders DGMO fenced code blocks at build time.
|
|
@@ -25,12 +53,11 @@ export { DgmoOptions as DgmoIntegrationOptions, Mode, Theme, default as remarkDg
|
|
|
25
53
|
* by setting `colorMode: 'light'` or `colorMode: 'dark'` in the integration
|
|
26
54
|
* options.
|
|
27
55
|
*
|
|
28
|
-
* **CSS
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* import 'remark-dgmo/client.css';
|
|
56
|
+
* **CSS is automatic since v0.11.0.** The integration adds
|
|
57
|
+
* `remark-dgmo/client.css` to every page itself, so a fresh install renders
|
|
58
|
+
* one diagram rather than two. Opt out with `injectClientCss: false` if you
|
|
59
|
+
* ship your own copy of the color-mode rules.
|
|
33
60
|
*/
|
|
34
|
-
declare function dgmoIntegration(options?:
|
|
61
|
+
declare function dgmoIntegration(options?: DgmoIntegrationOptions): AstroIntegration;
|
|
35
62
|
|
|
36
|
-
export { dgmoIntegration as default };
|
|
63
|
+
export { type DgmoIntegrationOptions, dgmoIntegration as default };
|
package/dist/index.js
CHANGED
|
@@ -63,6 +63,9 @@ function dgmoIntegration(options = {}) {
|
|
|
63
63
|
import.meta.resolve("remark-dgmo/client.js")
|
|
64
64
|
);
|
|
65
65
|
injectScript("page", readFileSync(clientJsPath, "utf8"));
|
|
66
|
+
if (options.injectClientCss !== false) {
|
|
67
|
+
injectScript("page-ssr", `import 'remark-dgmo/client.css';`);
|
|
68
|
+
}
|
|
66
69
|
if (options.liveLink?.refresh === "render") {
|
|
67
70
|
const renderJsPath = fileURLToPath(
|
|
68
71
|
import.meta.resolve("remark-dgmo/client-render.js")
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport type { AstroIntegration } from 'astro';\nimport remarkDgmo from 'remark-dgmo';\nimport type { DgmoIntegrationOptions } from './options.js';\n\nexport type { DgmoIntegrationOptions, Mode, Theme } from './options.js';\nexport { default as remarkDgmo } from 'remark-dgmo';\n\n/**\n * Astro integration that renders DGMO fenced code blocks at build time.\n *\n * @example\n * ```js\n * // astro.config.mjs\n * import dgmo from 'astro-dgmo';\n *\n * export default defineConfig({\n * integrations: [dgmo()],\n * });\n * ```\n *\n * v0.3.0 changes the rendered HTML class-name prefix from `astro-dgmo-*` to\n * `dgmo-*`. Both are emitted for one minor cycle via the shared `remark-dgmo`\n * `legacyClassNames` option, so existing user CSS keeps working until v0.4.\n *\n * v0.3.0 also defaults to `colorMode: 'auto'` (dual-render, light+dark SVGs)\n * to fix the silent dark/light-mismatch bug on Starlight and any toggle-\n * enabled Astro site. Users on single-mode sites can opt back to single-render\n * by setting `colorMode: 'light'` or `colorMode: 'dark'` in the integration\n * options.\n *\n * **CSS:** Astro 6's IntegrationHook has no programmatic stylesheet\n * injection — only `injectScript`. You must import the color-mode stylesheet\n * yourself in a global layout (e.g. `src/layouts/Base.astro`):\n *\n * import 'remark-dgmo/client.css';\n */\nexport default function dgmoIntegration(\n options: DgmoIntegrationOptions = {}\n): AstroIntegration {\n // Emit BOTH new (`dgmo-*`) and legacy (`astro-dgmo-*`) class names so user\n // CSS targeting the v0.2 classes keeps working. Removed in v0.4.\n const optionsWithLegacy: DgmoIntegrationOptions = {\n ...options,\n legacyClassNames: [\n ...(options.legacyClassNames ?? []),\n 'astro-dgmo',\n 'astro-dgmo-card',\n ],\n };\n\n return {\n name: 'astro-dgmo',\n hooks: {\n async 'astro:config:setup'({ config, updateConfig, injectScript, logger }) {\n const plugin: [typeof remarkDgmo, DgmoIntegrationOptions] = [\n remarkDgmo,\n optionsWithLegacy,\n ];\n\n // 🔴 Astro 7 stopped running remark plugins, and does it QUIETLY.\n //\n // Sätteri replaced unified as the default Markdown processor, and\n // `markdown.remarkPlugins` is simply not consulted by it. The build\n // stays green, exits 0, and every diagram is gone — measured on this\n // repo's own fixture 2026-08-10: 423,794 bytes and 14 SVGs became\n // 6,625 bytes and 1. Astro prints one warning and carries on.\n //\n // So this hook asks what processor it has rather than assuming, and\n // says out loud what it did. Feature detection, not a version check:\n // `processor` does not exist in Astro 4-6's config at all, and\n // `unified`/`isUnifiedProcessor` are only exported by the Astro 7 line\n // of `@astrojs/markdown-remark`, so the two together identify the new\n // world without anyone parsing a version string.\n const markdownRemark = await import('@astrojs/markdown-remark').catch(\n () => undefined\n );\n const unified = markdownRemark?.unified;\n const isUnifiedProcessor = markdownRemark?.isUnifiedProcessor;\n const processor = (\n config?.markdown as { processor?: { name?: string } } | undefined\n )?.processor;\n\n if (!unified || !isUnifiedProcessor || processor === undefined) {\n // Astro 4-6: remark IS the Markdown pipeline, so this is all it takes.\n updateConfig({ markdown: { remarkPlugins: [plugin] } });\n } else if (isUnifiedProcessor(processor as { name: string })) {\n // The site already runs unified. Push into it rather than replacing\n // it — replacing would silently drop every other plugin they set.\n (\n processor as { options: { remarkPlugins: unknown[] } }\n ).options.remarkPlugins.push(plugin);\n } else {\n // 🔴 Something else is configured — Sätteri, or a third processor.\n //\n // We take it over, because the alternative is rendering nothing, and\n // unified is the engine this integration has always run on: a site\n // arriving from Astro 6 gets the Markdown semantics it already had.\n //\n // 🔴 Carry the whole pipeline, not just our plugin. Integrations\n // that ran before us — Starlight, most importantly — have already\n // pushed their remark and rehype plugins into `config.markdown`,\n // where the processor being replaced never looked. Neither did the\n // first version of this takeover, which rebuilt the pipeline as\n // `[plugin]` alone: Starlight's `:::note` asides are remark\n // plugins, so every aside on a Starlight site rendered as literal\n // `:::` text while the diagrams worked (issue 191, 2026-08-11).\n // The site's own gfm / smartypants / remarkRehype settings ride\n // along for the same reason — the takeover's contract is \"your\n // Markdown, plus diagrams\", never \"our Markdown instead\".\n //\n // It is announced rather than done quietly, and that is not\n // squeamishness — Astro materialises its DEFAULT processor before\n // integrations run (verified 2026-08-10: `config.markdown.processor`\n // is already `satteri` inside this hook on a config that never\n // mentioned it). So \"the site asked for Sätteri\" and \"the site asked\n // for nothing\" are indistinguishable here, and a silent swap would\n // sometimes be overruling a real choice with no way to notice.\n const md = (config?.markdown ?? {}) as {\n remarkPlugins?: unknown[];\n rehypePlugins?: unknown[];\n remarkRehype?: Record<string, unknown>;\n gfm?: boolean;\n smartypants?: boolean;\n };\n // 🔴 An integration that ran BEFORE us may have registered plugins\n // into the processor being replaced — Starlight, when it sees\n // Sätteri, pushes its aside/anchor plugins into the processor's own\n // `mdastPlugins`/`hastPlugins` rather than into `config.markdown`,\n // and those cannot be carried onto unified(). We cannot fix that\n // from here; we CAN name it and name the fix, because the silent\n // version of this was a Starlight site whose every `:::` aside\n // rendered as plain text (issue 191). Listing dgmo() before those\n // integrations makes them find the unified processor already in\n // place and join it through their own unified support.\n const opts = (\n processor as {\n options?: { mdastPlugins?: unknown[]; hastPlugins?: unknown[] };\n }\n ).options;\n const strandedCount =\n (opts?.mdastPlugins?.length ?? 0) + (opts?.hastPlugins?.length ?? 0);\n if (strandedCount > 0) {\n logger.warn(\n `The \\`${(processor as { name?: string })?.name ?? 'configured'}\\` processor being replaced already ` +\n `carries ${strandedCount} plugin(s) registered by integrations that ran before astro-dgmo ` +\n `(Starlight registers its \\`:::\\` asides this way). Those plugins CANNOT be carried over and ` +\n `their output will be missing. Fix: list dgmo() BEFORE those integrations in \\`integrations: []\\`, ` +\n `so they find the unified() processor already in place and join it instead.`\n );\n }\n const carried = {\n remarkPlugins: [...(md.remarkPlugins ?? []), plugin],\n rehypePlugins: [...(md.rehypePlugins ?? [])],\n ...(md.remarkRehype !== undefined && {\n remarkRehype: md.remarkRehype,\n }),\n ...(md.gfm !== undefined && { gfm: md.gfm }),\n ...(md.smartypants !== undefined && {\n smartypants: md.smartypants,\n }),\n };\n logger.warn(\n `astro-dgmo renders diagrams through a remark plugin, which your ` +\n `\\`${(processor as { name?: string })?.name ?? 'configured'}\\` Markdown processor does not run. ` +\n `Switching \\`markdown.processor\\` to \\`unified()\\` so diagrams render, ` +\n `carrying the ${md.remarkPlugins?.length ?? 0} remark and ` +\n `${md.rehypePlugins?.length ?? 0} rehype plugins already registered. ` +\n `To keep your own processor and control this yourself, set ` +\n `\\`markdown: { processor: unified({ remarkPlugins: [[remarkDgmo, options]] }) }\\` ` +\n `— astro-dgmo will then add itself to that processor instead of replacing it.`\n );\n updateConfig({\n markdown: {\n processor: unified(carried as Parameters<typeof unified>[0]),\n },\n });\n }\n // Inline the shared remark-dgmo client script so showcase-mode copy\n // buttons + viewBox tightening light up without users wiring scripts\n // manually. Read at config-setup time so the absolute path resolves\n // through node_modules.\n const clientJsPath = fileURLToPath(\n import.meta.resolve('remark-dgmo/client.js')\n );\n injectScript('page', readFileSync(clientJsPath, 'utf8'));\n\n // Live links, `refresh: 'render'` only (story 10.4). The base\n // client NOTICES that a referenced diagram moved; this second module is\n // what re-renders it, and it is separate because its dynamic import is\n // static-analyzable — injecting it unconditionally took this repo's own\n // fixture from 1 chunk / 7,990 gzipped bytes to 90 chunks / 634,199.\n // Lazy for the reader, not free for the site, so it is opt-in.\n if (options.liveLink?.refresh === 'render') {\n const renderJsPath = fileURLToPath(\n import.meta.resolve('remark-dgmo/client-render.js')\n );\n injectScript('page', readFileSync(renderJsPath, 'utf8'));\n }\n },\n },\n };\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAE9B,OAAO,gBAAgB;AAIvB,SAAoB,WAAXA,gBAA6B;AA+BvB,SAAR,gBACL,UAAkC,CAAC,GACjB;AAGlB,QAAM,oBAA4C;AAAA,IAChD,GAAG;AAAA,IACH,kBAAkB;AAAA,MAChB,GAAI,QAAQ,oBAAoB,CAAC;AAAA,MACjC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,MACL,MAAM,qBAAqB,EAAE,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ACR,WAAW,QAAQ,OAAwC;AAAA,YAC7D;AAAA,UACF,CAAC;AAAA,QACH;AAKA,cAAM,eAAe;AAAA,UACnB,YAAY,QAAQ,uBAAuB;AAAA,QAC7C;AACA,qBAAa,QAAQ,aAAa,cAAc,MAAM,CAAC;AAQvD,YAAI,QAAQ,UAAU,YAAY,UAAU;AAC1C,gBAAM,eAAe;AAAA,YACnB,YAAY,QAAQ,8BAA8B;AAAA,UACpD;AACA,uBAAa,QAAQ,aAAa,cAAc,MAAM,CAAC;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["default"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport type { AstroIntegration } from 'astro';\nimport remarkDgmo from 'remark-dgmo';\nimport type { DgmoIntegrationOptions } from './options.js';\n\nexport type { DgmoIntegrationOptions, Mode, Theme } from './options.js';\nexport { default as remarkDgmo } from 'remark-dgmo';\n\n/**\n * Astro integration that renders DGMO fenced code blocks at build time.\n *\n * @example\n * ```js\n * // astro.config.mjs\n * import dgmo from 'astro-dgmo';\n *\n * export default defineConfig({\n * integrations: [dgmo()],\n * });\n * ```\n *\n * v0.3.0 changes the rendered HTML class-name prefix from `astro-dgmo-*` to\n * `dgmo-*`. Both are emitted for one minor cycle via the shared `remark-dgmo`\n * `legacyClassNames` option, so existing user CSS keeps working until v0.4.\n *\n * v0.3.0 also defaults to `colorMode: 'auto'` (dual-render, light+dark SVGs)\n * to fix the silent dark/light-mismatch bug on Starlight and any toggle-\n * enabled Astro site. Users on single-mode sites can opt back to single-render\n * by setting `colorMode: 'light'` or `colorMode: 'dark'` in the integration\n * options.\n *\n * **CSS is automatic since v0.11.0.** The integration adds\n * `remark-dgmo/client.css` to every page itself, so a fresh install renders\n * one diagram rather than two. Opt out with `injectClientCss: false` if you\n * ship your own copy of the color-mode rules.\n */\nexport default function dgmoIntegration(\n options: DgmoIntegrationOptions = {}\n): AstroIntegration {\n // Emit BOTH new (`dgmo-*`) and legacy (`astro-dgmo-*`) class names so user\n // CSS targeting the v0.2 classes keeps working. Removed in v0.4.\n const optionsWithLegacy: DgmoIntegrationOptions = {\n ...options,\n legacyClassNames: [\n ...(options.legacyClassNames ?? []),\n 'astro-dgmo',\n 'astro-dgmo-card',\n ],\n };\n\n return {\n name: 'astro-dgmo',\n hooks: {\n async 'astro:config:setup'({ config, updateConfig, injectScript, logger }) {\n const plugin: [typeof remarkDgmo, DgmoIntegrationOptions] = [\n remarkDgmo,\n optionsWithLegacy,\n ];\n\n // 🔴 Astro 7 stopped running remark plugins, and does it QUIETLY.\n //\n // Sätteri replaced unified as the default Markdown processor, and\n // `markdown.remarkPlugins` is simply not consulted by it. The build\n // stays green, exits 0, and every diagram is gone — measured on this\n // repo's own fixture 2026-08-10: 423,794 bytes and 14 SVGs became\n // 6,625 bytes and 1. Astro prints one warning and carries on.\n //\n // So this hook asks what processor it has rather than assuming, and\n // says out loud what it did. Feature detection, not a version check:\n // `processor` does not exist in Astro 4-6's config at all, and\n // `unified`/`isUnifiedProcessor` are only exported by the Astro 7 line\n // of `@astrojs/markdown-remark`, so the two together identify the new\n // world without anyone parsing a version string.\n const markdownRemark = await import('@astrojs/markdown-remark').catch(\n () => undefined\n );\n const unified = markdownRemark?.unified;\n const isUnifiedProcessor = markdownRemark?.isUnifiedProcessor;\n const processor = (\n config?.markdown as { processor?: { name?: string } } | undefined\n )?.processor;\n\n if (!unified || !isUnifiedProcessor || processor === undefined) {\n // Astro 4-6: remark IS the Markdown pipeline, so this is all it takes.\n updateConfig({ markdown: { remarkPlugins: [plugin] } });\n } else if (isUnifiedProcessor(processor as { name: string })) {\n // The site already runs unified. Push into it rather than replacing\n // it — replacing would silently drop every other plugin they set.\n (\n processor as { options: { remarkPlugins: unknown[] } }\n ).options.remarkPlugins.push(plugin);\n } else {\n // 🔴 Something else is configured — Sätteri, or a third processor.\n //\n // We take it over, because the alternative is rendering nothing, and\n // unified is the engine this integration has always run on: a site\n // arriving from Astro 6 gets the Markdown semantics it already had.\n //\n // 🔴 Carry the whole pipeline, not just our plugin. Integrations\n // that ran before us — Starlight, most importantly — have already\n // pushed their remark and rehype plugins into `config.markdown`,\n // where the processor being replaced never looked. Neither did the\n // first version of this takeover, which rebuilt the pipeline as\n // `[plugin]` alone: Starlight's `:::note` asides are remark\n // plugins, so every aside on a Starlight site rendered as literal\n // `:::` text while the diagrams worked (issue 191, 2026-08-11).\n // The site's own gfm / smartypants / remarkRehype settings ride\n // along for the same reason — the takeover's contract is \"your\n // Markdown, plus diagrams\", never \"our Markdown instead\".\n //\n // It is announced rather than done quietly, and that is not\n // squeamishness — Astro materialises its DEFAULT processor before\n // integrations run (verified 2026-08-10: `config.markdown.processor`\n // is already `satteri` inside this hook on a config that never\n // mentioned it). So \"the site asked for Sätteri\" and \"the site asked\n // for nothing\" are indistinguishable here, and a silent swap would\n // sometimes be overruling a real choice with no way to notice.\n const md = (config?.markdown ?? {}) as {\n remarkPlugins?: unknown[];\n rehypePlugins?: unknown[];\n remarkRehype?: Record<string, unknown>;\n gfm?: boolean;\n smartypants?: boolean;\n };\n // 🔴 An integration that ran BEFORE us may have registered plugins\n // into the processor being replaced — Starlight, when it sees\n // Sätteri, pushes its aside/anchor plugins into the processor's own\n // `mdastPlugins`/`hastPlugins` rather than into `config.markdown`,\n // and those cannot be carried onto unified(). We cannot fix that\n // from here; we CAN name it and name the fix, because the silent\n // version of this was a Starlight site whose every `:::` aside\n // rendered as plain text (issue 191). Listing dgmo() before those\n // integrations makes them find the unified processor already in\n // place and join it through their own unified support.\n const opts = (\n processor as {\n options?: { mdastPlugins?: unknown[]; hastPlugins?: unknown[] };\n }\n ).options;\n const strandedCount =\n (opts?.mdastPlugins?.length ?? 0) + (opts?.hastPlugins?.length ?? 0);\n if (strandedCount > 0) {\n logger.warn(\n `The \\`${(processor as { name?: string })?.name ?? 'configured'}\\` processor being replaced already ` +\n `carries ${strandedCount} plugin(s) registered by integrations that ran before astro-dgmo ` +\n `(Starlight registers its \\`:::\\` asides this way). Those plugins CANNOT be carried over and ` +\n `their output will be missing. Fix: list dgmo() BEFORE those integrations in \\`integrations: []\\`, ` +\n `so they find the unified() processor already in place and join it instead.`\n );\n }\n const carried = {\n remarkPlugins: [...(md.remarkPlugins ?? []), plugin],\n rehypePlugins: [...(md.rehypePlugins ?? [])],\n ...(md.remarkRehype !== undefined && {\n remarkRehype: md.remarkRehype,\n }),\n ...(md.gfm !== undefined && { gfm: md.gfm }),\n ...(md.smartypants !== undefined && {\n smartypants: md.smartypants,\n }),\n };\n logger.warn(\n `astro-dgmo renders diagrams through a remark plugin, which your ` +\n `\\`${(processor as { name?: string })?.name ?? 'configured'}\\` Markdown processor does not run. ` +\n `Switching \\`markdown.processor\\` to \\`unified()\\` so diagrams render, ` +\n `carrying the ${md.remarkPlugins?.length ?? 0} remark and ` +\n `${md.rehypePlugins?.length ?? 0} rehype plugins already registered. ` +\n `To keep your own processor and control this yourself, set ` +\n `\\`markdown: { processor: unified({ remarkPlugins: [[remarkDgmo, options]] }) }\\` ` +\n `— astro-dgmo will then add itself to that processor instead of replacing it.`\n );\n updateConfig({\n markdown: {\n processor: unified(carried as Parameters<typeof unified>[0]),\n },\n });\n }\n // Inline the shared remark-dgmo client script so showcase-mode copy\n // buttons + viewBox tightening light up without users wiring scripts\n // manually. Read at config-setup time so the absolute path resolves\n // through node_modules.\n const clientJsPath = fileURLToPath(\n import.meta.resolve('remark-dgmo/client.js')\n );\n injectScript('page', readFileSync(clientJsPath, 'utf8'));\n\n // 🔴 The color-mode stylesheet, which used to be a manual `import` in\n // the consumer's own layout — and therefore was routinely missing.\n //\n // Under `colorMode: 'auto'` (the default) every fence renders TWO\n // SVGs; the rule that hides the one you are not in lives only in\n // `client.css`. A site that never imported it printed the SAME\n // diagram twice, stacked, with a green build and no warning anywhere\n // (issue 507, reported from a real Astro site 2026-08-26).\n //\n // Both this file and the README said the manual step was\n // \"unavoidable\" because `IntegrationHook` has no stylesheet API. The\n // premise is right and the conclusion was wrong: `page-ssr` imports a\n // module into every page's frontmatter, and Vite turns a CSS import\n // there into a real stylesheet. It is the route Astro's own\n // integration reference documents for exactly this. Measured on this\n // repo's fixture under Astro 7.2.0 (2026-08-26): a probe page that\n // imports nothing carried zero stylesheets before and\n // `.dgmo-dark,[data-theme=dark] .dgmo-light{display:none}` after.\n //\n // Importing it again by hand costs nothing — Vite resolves both to\n // one module.\n if (options.injectClientCss !== false) {\n injectScript('page-ssr', `import 'remark-dgmo/client.css';`);\n }\n\n // Live links, `refresh: 'render'` only (story 10.4). The base\n // client NOTICES that a referenced diagram moved; this second module is\n // what re-renders it, and it is separate because its dynamic import is\n // static-analyzable — injecting it unconditionally took this repo's own\n // fixture from 1 chunk / 7,990 gzipped bytes to 90 chunks / 634,199.\n // Lazy for the reader, not free for the site, so it is opt-in.\n if (options.liveLink?.refresh === 'render') {\n const renderJsPath = fileURLToPath(\n import.meta.resolve('remark-dgmo/client-render.js')\n );\n injectScript('page', readFileSync(renderJsPath, 'utf8'));\n }\n },\n },\n };\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAE9B,OAAO,gBAAgB;AAIvB,SAAoB,WAAXA,gBAA6B;AA8BvB,SAAR,gBACL,UAAkC,CAAC,GACjB;AAGlB,QAAM,oBAA4C;AAAA,IAChD,GAAG;AAAA,IACH,kBAAkB;AAAA,MAChB,GAAI,QAAQ,oBAAoB,CAAC;AAAA,MACjC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,MACL,MAAM,qBAAqB,EAAE,QAAQ,cAAc,cAAc,OAAO,GAAG;AACzE,cAAM,SAAsD;AAAA,UAC1D;AAAA,UACA;AAAA,QACF;AAgBA,cAAM,iBAAiB,MAAM,OAAO,0BAA0B,EAAE;AAAA,UAC9D,MAAM;AAAA,QACR;AACA,cAAM,UAAU,gBAAgB;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AAQ,oBAAoB,OAAO;AACrC,uBAAa,YAAY,kCAAkC;AAAA,QAC7D;AAQA,YAAI,QAAQ,UAAU,YAAY,UAAU;AAC1C,gBAAM,eAAe;AAAA,YACnB,YAAY,QAAQ,8BAA8B;AAAA,UACpD;AACA,uBAAa,QAAQ,aAAa,cAAc,MAAM,CAAC;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["default"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-dgmo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Astro integration to render DGMO diagrams from fenced code blocks at build time. Powered by @diagrammo/dgmo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Diagrammo LLC",
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
"prepublishOnly": "pnpm build && pnpm test"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
+
"@astrojs/markdown-remark": "^7.0.0",
|
|
69
70
|
"@diagrammo/dgmo": ">=0.61.0 <1",
|
|
70
|
-
"astro": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
71
|
-
"@astrojs/markdown-remark": "^7.0.0"
|
|
71
|
+
"astro": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
72
72
|
},
|
|
73
73
|
"pnpm": {
|
|
74
74
|
"overrides": {
|
|
@@ -77,11 +77,11 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"remark-dgmo": "^0.
|
|
80
|
+
"remark-dgmo": "^0.15.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@astrojs/markdown-remark": "^7.2.2",
|
|
84
|
-
"@diagrammo/dgmo": ">=0.
|
|
84
|
+
"@diagrammo/dgmo": ">=0.76.0 <1",
|
|
85
85
|
"@eslint/js": "^10.0.1",
|
|
86
86
|
"@types/node": "^22.20.1",
|
|
87
87
|
"astro": "^7.2.0",
|