astro-dgmo 0.9.2 → 0.10.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/LICENSE +1 -1
- package/README.md +27 -0
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/package.json +26 -12
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -36,6 +36,33 @@ npm install astro-dgmo @diagrammo/dgmo
|
|
|
36
36
|
|
|
37
37
|
`@diagrammo/dgmo` is a peer dependency.
|
|
38
38
|
|
|
39
|
+
### On Astro 7, add one more package
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pnpm add @astrojs/markdown-remark
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Astro 7 changed its default Markdown processor to Sätteri, which does not run
|
|
46
|
+
remark plugins — and diagrams are rendered by one. Without this package Astro
|
|
47
|
+
stops the build and tells you to install it.
|
|
48
|
+
|
|
49
|
+
With it installed there is nothing else to do: `astro-dgmo` puts the site back
|
|
50
|
+
on the `unified` processor it has always rendered through, so Markdown behaves
|
|
51
|
+
exactly as it did on Astro 6, and prints a one-line notice saying it did. If you
|
|
52
|
+
would rather own that yourself, configure `unified` and the integration adds
|
|
53
|
+
itself to your processor instead of replacing it:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { unified } from '@astrojs/markdown-remark';
|
|
57
|
+
|
|
58
|
+
export default defineConfig({
|
|
59
|
+
markdown: { processor: unified() },
|
|
60
|
+
integrations: [dgmo()],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Astro 4, 5 and 6 need none of this.
|
|
65
|
+
|
|
39
66
|
## Quick start
|
|
40
67
|
|
|
41
68
|
Add the integration to `astro.config.mjs`:
|
package/dist/index.js
CHANGED
|
@@ -15,12 +15,29 @@ function dgmoIntegration(options = {}) {
|
|
|
15
15
|
return {
|
|
16
16
|
name: "astro-dgmo",
|
|
17
17
|
hooks: {
|
|
18
|
-
"astro:config:setup"({ updateConfig, injectScript }) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
async "astro:config:setup"({ config, updateConfig, injectScript, logger }) {
|
|
19
|
+
const plugin = [
|
|
20
|
+
remarkDgmo,
|
|
21
|
+
optionsWithLegacy
|
|
22
|
+
];
|
|
23
|
+
const markdownRemark = await import("@astrojs/markdown-remark").catch(
|
|
24
|
+
() => void 0
|
|
25
|
+
);
|
|
26
|
+
const unified = markdownRemark?.unified;
|
|
27
|
+
const isUnifiedProcessor = markdownRemark?.isUnifiedProcessor;
|
|
28
|
+
const processor = config?.markdown?.processor;
|
|
29
|
+
if (!unified || !isUnifiedProcessor || processor === void 0) {
|
|
30
|
+
updateConfig({ markdown: { remarkPlugins: [plugin] } });
|
|
31
|
+
} else if (isUnifiedProcessor(processor)) {
|
|
32
|
+
processor.options.remarkPlugins.push(plugin);
|
|
33
|
+
} else {
|
|
34
|
+
logger.warn(
|
|
35
|
+
`astro-dgmo renders diagrams through a remark plugin, which your \`${processor?.name ?? "configured"}\` Markdown processor does not run. Switching \`markdown.processor\` to \`unified()\` so diagrams render. To keep your own processor and control this yourself, set \`markdown: { processor: unified({ remarkPlugins: [[remarkDgmo, options]] }) }\` \u2014 astro-dgmo will then add itself to that processor instead of replacing it.`
|
|
36
|
+
);
|
|
37
|
+
updateConfig({
|
|
38
|
+
markdown: { processor: unified({ remarkPlugins: [plugin] }) }
|
|
39
|
+
});
|
|
40
|
+
}
|
|
24
41
|
const clientJsPath = fileURLToPath(
|
|
25
42
|
import.meta.resolve("remark-dgmo/client.js")
|
|
26
43
|
);
|
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 'astro:config:setup'({ updateConfig, injectScript }) {\n
|
|
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 // 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 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 `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: { processor: unified({ remarkPlugins: [plugin] }) },\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,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;AAChC,cAAM,qBAAqB,gBAAgB;AAC3C,cAAM,YACJ,QAAQ,UACP;AAEH,YAAI,CAAC,WAAW,CAAC,sBAAsB,cAAc,QAAW;AAE9D,uBAAa,EAAE,UAAU,EAAE,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC;AAAA,QACxD,WAAW,mBAAmB,SAA6B,GAAG;AAG5D,UACE,UACA,QAAQ,cAAc,KAAK,MAAM;AAAA,QACrC,OAAO;AAcL,iBAAO;AAAA,YACL,qEACQ,WAAiC,QAAQ,YAAY;AAAA,UAK/D;AACA,uBAAa;AAAA,YACX,UAAU,EAAE,WAAW,QAAQ,EAAE,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE;AAAA,UAC9D,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"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-dgmo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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
|
+
"author": "Diagrammo LLC",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
9
|
"url": "https://github.com/diagrammo/astro-dgmo.git"
|
|
@@ -66,24 +67,37 @@
|
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
69
|
"@diagrammo/dgmo": ">=0.61.0 <1",
|
|
69
|
-
"astro": "^4.0.0 || ^5.0.0 || ^6.0.0"
|
|
70
|
+
"astro": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
71
|
+
"@astrojs/markdown-remark": "^7.0.0"
|
|
72
|
+
},
|
|
73
|
+
"pnpm": {
|
|
74
|
+
"overrides": {
|
|
75
|
+
"esbuild": ">=0.28.1 <1",
|
|
76
|
+
"sharp": ">=0.35.0 <1"
|
|
77
|
+
}
|
|
70
78
|
},
|
|
71
79
|
"dependencies": {
|
|
72
80
|
"remark-dgmo": "^0.14.2"
|
|
73
81
|
},
|
|
74
82
|
"devDependencies": {
|
|
75
|
-
"@
|
|
83
|
+
"@astrojs/markdown-remark": "^7.2.2",
|
|
84
|
+
"@diagrammo/dgmo": ">=0.66.0 <1",
|
|
76
85
|
"@eslint/js": "^10.0.1",
|
|
77
|
-
"@types/node": "^22.
|
|
78
|
-
"astro": "^
|
|
86
|
+
"@types/node": "^22.20.1",
|
|
87
|
+
"astro": "^7.2.0",
|
|
79
88
|
"depcheck": "^1.4.7",
|
|
80
|
-
"eslint": "^10.
|
|
81
|
-
"jscpd": "^4.
|
|
82
|
-
"knip": "^6.
|
|
83
|
-
"prettier": "^3.
|
|
89
|
+
"eslint": "^10.8.1",
|
|
90
|
+
"jscpd": "^4.2.5",
|
|
91
|
+
"knip": "^6.32.1",
|
|
92
|
+
"prettier": "^3.9.6",
|
|
84
93
|
"tsup": "^8.5.1",
|
|
85
|
-
"typescript": "^6.0.
|
|
86
|
-
"typescript-eslint": "^8.
|
|
87
|
-
"vitest": "^4.1.
|
|
94
|
+
"typescript": "^6.0.3",
|
|
95
|
+
"typescript-eslint": "^8.66.0",
|
|
96
|
+
"vitest": "^4.1.10"
|
|
97
|
+
},
|
|
98
|
+
"peerDependenciesMeta": {
|
|
99
|
+
"@astrojs/markdown-remark": {
|
|
100
|
+
"optional": true
|
|
101
|
+
}
|
|
88
102
|
}
|
|
89
103
|
}
|