### Run the application with pnpm dev Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/2.getting-started.md Start Nuxt and open the route for the Markdown page. ```bash pnpm dev ``` -------------------------------- ### Install module and Nuxt Content peer Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/README.md Install the module and its Nuxt Content peer dependency using pnpm. ```bash pnpm add @barzhsieh/nuxt-content-mermaid @nuxt/content ``` -------------------------------- ### Prepare release branch Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/RELEASING.md Start from the latest main and create a branch named for the version being prepared. Uses the version variable set in the script. ```bash version=3.0.4 branch="chore/prepare-release-v$version" git switch main git pull --ff-only origin main git switch -c "$branch" ``` -------------------------------- ### Rename module key from mermaidContent to contentMermaid Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V3.md Shows the v2 configuration key that is removed and the v3 replacement. The v2 key does not fall back to the new key; Nuxt setup stops with a public configuration-error fingerprint. ```ts // v2 — removed export default defineNuxtConfig({ mermaidContent: { debug: true }, }) // v3 export default defineNuxtConfig({ contentMermaid: { debug: true }, }) ``` -------------------------------- ### Property-Presence Merge Example Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V3.md Shows how package-owned configuration layers merge: only absent properties fall back, while present values (including arrays, null, false, 0, empty strings, and empty arrays) replace lower layers unless both are plain objects. Do not rely on defu-style backfilling for these values. ```ts // Lower layer { tags: ['default'], label: 'Mermaid', limit: 3, theme: 'dark' } // Higher layer { tags: [], label: '', limit: 0, theme: null } // Result { tags: [], label: '', limit: 0, theme: null } ``` -------------------------------- ### Configure contentMermaid in nuxt.config.ts Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/4.configuration.md Sets package-owned defaults for the module and built-in renderer under the `contentMermaid` key in `nuxt.config.ts`. The example enables lazy loading and sets light/dark themes. Note that `enabled` is setup-only and cannot be placed in public runtime configuration. ```ts export default defineNuxtConfig({ contentMermaid: { loader: { lazy: true }, theme: { light: 'default', dark: 'dark' }, }, }) ``` -------------------------------- ### Approve builds for pnpm v10+ Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/2.getting-started.md With pnpm v10 or later, native connector build scripts need explicit approval. Run this command to approve builds. ```bash pnpm approve-builds ``` -------------------------------- ### Allow only the selected connector in package.json Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/2.getting-started.md Alternatively, allow only the connector you selected in package.json. Replace the example with your chosen connector. ```json { "pnpm": { "onlyBuiltDependencies": ["better-sqlite3"] } } ``` -------------------------------- ### Keep module activation at build time with contentMermaid.enabled Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/7.migration/1.v3.md Set `contentMermaid.enabled` in Nuxt configuration to control whether the Markdown transform and runtime integration are installed. Do not move `enabled` into `runtimeConfig.public.contentMermaid`; changing public runtime data cannot activate or deactivate the module after Nuxt starts. ```ts export default defineNuxtConfig({ contentMermaid: { enabled: false }, }) ``` -------------------------------- ### Set config in page frontmatter Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/3.writing-diagrams.md After declaring the `config` field in the schema, set it in the page frontmatter to configure Mermaid diagrams on that page. The example sets the flowchart curve to basis. ```md --- config: flowchart: curve: basis --- ```mermaid flowchart LR Page --> Diagram ``` ``` -------------------------------- ### Implement a complete custom renderer (components/CustomMermaid.vue) Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/2.custom-rendering.md A resolved Custom Renderer receives `code` (decoded Mermaid source), `spinner` (configured or fallback), and the default slot (source fallback). It does not receive built-in `pageConfig`, direct `config`, toolbar options, loading/error slots, automatic theme resolution, or `components.error`. The example owns failure rendering and uses `useNuxtApp().$mermaid()` to render. ```Vue ``` -------------------------------- ### Mermaid flowchart with subgraphs and cross-links Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/flowchart/subgraphs.md Use this Mermaid flowchart to visually group nodes into subgraphs (API and UI) and test arrow routing with cross-links between groups. The example uses placeholder nodes and a basis curve for smooth edges. Keep one cross-link to verify arrow routing. ```mermaid graph LR subgraph API A[Auth] --> B[Fetch] end subgraph UI C[Render list] --> D[Handle click] end A --> C B --> D D --> B ``` -------------------------------- ### Mermaid flowchart example Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/1.index.md Use a Mermaid code fence in Markdown to create an interactive diagram. The module transforms the fence into a theme-aware diagram. ```mermaid flowchart TD Source["Write a Mermaid fence
in Markdown"] Content["Nuxt Content
parses the page"] Module["The module
transforms the fence"] Diagram["Interactive,
theme-aware diagram"] Source --> Content Content --> Module Module --> Diagram ``` -------------------------------- ### Control Mermaid theme manually with useMermaidTheme Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/1.themes-and-styling.md Uses the auto-imported composable to get reactive theme state and methods. currentTheme is a Ref holding the manual override; setMermaidTheme sets it, getMermaidTheme returns it, and resetMermaidTheme clears it (equivalent to setMermaidTheme(null)). Pass null to return to automatic selection. Do not import from the package root. ```vue ``` -------------------------------- ### Mermaid flowchart: graph TD with choice Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/test/fixtures/transform/multiple-blocks.md A Mermaid flowchart diagram showing a start node leading to a choice and a result. Use for simple decision flows. ```mermaid graph TD A[Start] --> B{Choice} B -->|Yes| C[Result] ``` -------------------------------- ### Wrap the built-in renderer (components/DiagramCard.vue) Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/2.custom-rendering.md An ordinary application component that preserves built-in configuration, interactions, loading, and error behavior while adding presentation. It uses the `#loading` and `#error` slots of ``. Add `import { computed } from 'vue'` if your Nuxt setup does not auto-import Vue utilities. ```Vue ``` -------------------------------- ### Run release preparation script Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/RELEASING.md Run exactly one preparation script. The minor and major variants are commented out; uncomment the one needed. ```bash pnpm release:prepare:patch # pnpm release:prepare:minor # pnpm release:prepare:major ``` -------------------------------- ### Mermaid usecase-beta diagram with actor and system boundary Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/usecase/basic.md Renders a basic use case diagram using the beta syntax. One actor (Customer) connects to three use cases inside an 'Order system' boundary. Requires Mermaid 12 and Object.groupBy support. ```mermaid usecase-beta direction LR actor Customer("Customer") systemBoundary "Order system" Browse("Browse catalog") Checkout("Place order") Track("Track delivery") end Customer --> Browse Customer --> Checkout Customer --> Track ``` -------------------------------- ### Minimal Mermaid diagram to test rendering Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/6.troubleshooting.md Use this small diagram to verify that Mermaid fences render correctly. If it works, restore the original source incrementally and validate its syntax with Mermaid's documentation. ```md ```mermaid flowchart LR A --> B ``` ``` -------------------------------- ### Basic async request lifecycle state diagram Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/state/basic.md Shows a flat state machine for an async request lifecycle with start/end markers and transitions for fetch, success, error, and retry. Use to verify state diagrams render correctly with the module and respond to theme changes. ```mermaid stateDiagram-v2 [*] --> Idle Idle --> Loading: Click "Fetch data" Loading --> Success: 200 OK Loading --> Error: 4xx / 5xx Error --> Idle: Retry Success --> [*] ``` -------------------------------- ### Create and push annotated release tag Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/RELEASING.md Update main, verify the release identity, then create and push an annotated tag. The command chain stops if any check fails. ```bash git switch main git pull --ff-only origin main version=3.0.4 release_commit=$(git rev-parse HEAD) test "$(node -p "require('./package.json').version")" = "$version" && grep -Fxq "## v$version" CHANGELOG.md && git tag -a "v$version" "$release_commit" -m "v$version" && git push origin "refs/tags/v$version" ``` -------------------------------- ### Transport only pure data at runtime in runtimeConfig.public.contentMermaid Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/7.migration/1.v3.md Only serializable data (strings, booleans, `null`, finite numbers, plain objects, arrays) should be placed in `runtimeConfig.public.contentMermaid`. Avoid functions, class instances, symbols, `undefined`, cycles, or client-only capabilities. Pass supported client-only values directly to `` instead. ```ts export default defineNuxtConfig({ runtimeConfig: { public: { contentMermaid: { loader: { init: { flowchart: { curve: 'basis' } } }, }, }, }, }) ``` -------------------------------- ### Watch publish workflow and verify outputs Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/RELEASING.md Watch the publish workflow run and verify both published outputs: the npm package version and the GitHub release details. ```bash gh run watch "$(gh run list \ --workflow publish.yml \ --commit "$release_commit" \ --limit 1 \ --json databaseId \ --jq '.[0].databaseId')" \ --exit-status npm view "@barzhsieh/nuxt-content-mermaid@$version" version dist-tags.latest --json gh release view "v$version" --json tagName,isDraft,isPrerelease,url ``` -------------------------------- ### Mermaid Gantt chart with dateFormat, dependencies, and milestone Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/gantt/basic.md Use this Mermaid gantt diagram to render a simple feature delivery pipeline with phases, dependencies, and a milestone marker. The axis is formatted as MM/DD for easy scanning in the playground. Verify basic gantt syntax including dateFormat, dependencies, and milestones. ```mermaid gantt title Feature delivery timeline dateFormat YYYY-MM-DD axisFormat %m/%d section Planning Spec requirements :done, spec, 2025-03-01, 4d UX wireframes :active, ux, 2025-03-03, 5d section Implementation API implementation :api, after ux, 6d Frontend integration :fe, after api, 6d section Validation Internal QA :qa, after fe, 4d Beta rollout :crit, beta, 2025-03-24, 5d Production launch :milestone, launch, 2025-03-29, 0d ``` -------------------------------- ### Runtime Mermaid Config with layout dagre Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/7.migration/2.v4.md Sets runtime defaults for the loader init, using `layout: 'dagre'` and `look: 'classic'`. ```ts export default defineNuxtConfig({ contentMermaid: { loader: { init: { layout: 'dagre', look: 'classic' } }, }, }) ``` -------------------------------- ### Default loader.init Mermaid configuration Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/4.configuration.md Baseline Mermaid initialization data used by the loader. It sets startOnLoad to false, the default theme, a font family including Chinese characters, dagre layout, classic look, and strict security level. Functions and client-only capabilities are not accepted in this configuration. ```ts { startOnLoad: false, theme: 'default', fontFamily: 'Arial, sans-serif, 微軟正黑體', layout: 'dagre', look: 'classic', mindmap: { layout: 'cose-bilkent' }, swimlane: { layout: 'swimlane' }, securityLevel: 'strict', } ``` -------------------------------- ### Configure expand with enabled and margin Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/4.configuration.md Use this configuration to patch the expand state with an object. Setting `enabled: true` explicitly re-enables expansion even if a lower-priority preset disabled it. `margin` sets the space around the expanded diagram in pixels. ```ts export default defineNuxtConfig({ contentMermaid: { expand: { enabled: true, margin: 24 }, }, }) ``` -------------------------------- ### Runtime Mermaid Config with layout and look Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V4.md Sets application-wide shared defaults for `layout` and `look` in `contentMermaid.loader.init`. ```ts export default defineNuxtConfig({ contentMermaid: { loader: { init: { layout: 'dagre', look: 'classic' } }, }, }) ``` -------------------------------- ### setMermaidTheme usage with dark, forest, and null Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/1.themes-and-styling.md Shows how to manually set the Mermaid theme using the setMermaidTheme function. 'dark' uses the configured dark strategy, 'forest' is passed directly to Mermaid, and null removes the manual override to enable automatic mode. ```ts setMermaidTheme('dark') // configured dark strategy setMermaidTheme('forest') // direct Mermaid theme setMermaidTheme(null) // automatic mode ``` -------------------------------- ### Minimal pie chart with base theme Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/pie/minimal.md Smallest valid pie definition using only the pie keyword and data rows. Uses a base theme and adjusted label radius; slice sizes stay proportionate even with uneven totals. ```mermaid pie "Backend tasks" : 14 "Frontend polish" : 9 "Docs & demos" : 5 "Bug triage" : 4 ``` -------------------------------- ### Gantt chart for sprint tracking with todayMarker Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/gantt/sprint-tracking.md Illustrates two sprints with overlapping tasks, critical items, and a today marker. Uses relative dependencies like `after` and marks critical tasks with `crit`. Good for checking how compact displayMode looks and how todayMarker overlays on the chart. ```mermaid gantt title Sprint tracking view dateFormat YYYY-MM-DD axisFormat %b %d todayMarker stroke-width:4px,stroke:#f97316,opacity:0.6 section Sprint 1 Plan backlog :done, s1plan, 2025-04-01, 2d Implement core feature :crit, s1core, 2025-04-03, 5d Write tests :active, s1test, after s1core, 3d section Sprint 2 Refine UX :s2ux, 2025-04-10, 4d Integrate feedback :s2fb, after s2ux, 3d Hardening & release :crit, s2rel, 2025-04-18, 4d ``` -------------------------------- ### Nested auth state machine state diagram Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/state/basic.md Demonstrates a composite state with nested states for login/logout flow. Includes start/end markers and transitions for submitting credentials, success, failure, and retry. Use to exercise composite states in state diagrams. ```mermaid stateDiagram-v2 [*] --> Auth Auth --> [*]: Logout state Auth { [*] --> LoggedOut LoggedOut --> LoggingIn: Submit credentials LoggingIn --> LoggedIn: Success LoggingIn --> LoginError: Failure LoginError --> LoggedOut: Retry LoggedIn --> LoggedOut: Logout } ``` -------------------------------- ### Move client-only capability to Direct Mermaid Config Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V3.md This configuration is invalid for runtime transport because it uses a function. Move this client-only capability to Direct Mermaid Config instead. ```ts // v3: move this client-only capability to Direct Mermaid Config runtimeConfig: { public: { contentMermaid: { loader: { init: { sequence: { actorFont: () => ({ fontSize: 14 }) } } }, }, }, } ``` -------------------------------- ### Mermaid YAML frontmatter for compact Gantt displayMode Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/3.writing-diagrams.md Configure compact Gantt layout via Mermaid YAML frontmatter. The legacy `{displayMode="compact"}` fence attribute is not supported in v3.0.1. ```markdown ```mermaid --- config: gantt: displayMode: compact --- gantt title Compact schedule ``` ``` -------------------------------- ### Mermaid class diagram with inheritance, composition, aggregation, and interface realization Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/classdiagram/relationships.md Shows inheritance (User <|-- Admin), composition (Cart *-- CartItem), aggregation (User o-- Cart), interface implementation (StripeGateway ..|> PaymentGateway), and labelled associations. Includes attributes/methods to verify layout and font rendering. Uses Mermaid realization syntax (..|>), composition (*--), and aggregation (o--). ```mermaid classDiagram direction LR class User { +String id +String name +login() -hashPassword() } class Admin { +suspendUser(id) } class Session { +token: String +expiresAt: Date } class Cart { +items: CartItem[] +addItem(item) } class CartItem { +sku: String +qty: Number } class PaymentGateway { <> +charge(amount) } class StripeGateway { +charge(amount) } User <|-- Admin User "1" --> "many" Session : creates User "1" o-- "1" Cart : aggregates Cart "1" *-- "*" CartItem : composed of Cart --> PaymentGateway : uses StripeGateway ..|> PaymentGateway : implements Session --> Cart : binds ``` -------------------------------- ### Page Mermaid Config with frontmatter and Mermaid diagram Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V3.md Content-authored Markdown uses Page Mermaid Config. Put pure data in the page frontmatter `config` field and declare that field in the Nuxt Content collection schema; the Markdown Diagram Protocol supplies it as `pageConfig`. ```markdown --- config: theme: forest --- ```mermaid flowchart LR PAGE --> CONFIG ``` ``` -------------------------------- ### Commit and push release PR Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/RELEASING.md Stage the generated files, commit with a conventional message, push the branch, and create a pull request against main. ```bash git add -- package.json pnpm-lock.yaml CHANGELOG.md README.md README.zh-TW.md docs website/content git commit -m "chore(release): prepare v$version" git push -u origin "$branch" gh pr create \ --base main \ --head "$branch" \ --title "chore(release): prepare v$version" \ --body "Prepare v$version package version and changelog." ``` -------------------------------- ### Direct Mermaid Config for a single diagram Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V4.md Selects ELK for just one diagram instance by passing `layout: 'elk'` via the `config` prop. ```vue ``` -------------------------------- ### Valid runtime transport for runtimeConfig.public.contentMermaid Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V3.md Use this configuration to pass pure data (strings, booleans, null, finite numbers, plain objects, arrays) to the runtime config. Functions, class instances, accessors, symbols, undefined, cycles, non-finite numbers, and negative zero are rejected. ```ts // v3: valid runtime transport runtimeConfig: { public: { contentMermaid: { loader: { init: { flowchart: { curve: 'basis' } } }, }, }, } ``` -------------------------------- ### Manual color mode control with useMermaidTheme Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/1.themes-and-styling.md Use setMermaidTheme and resetMermaidTheme to override the color-mode selection for a view, then reset to resume automatic selection. Manual state is app-scoped, so plan a reset when leaving a view that locks a diagram theme. ```ts const { resetMermaidTheme, setMermaidTheme } = useMermaidTheme() setMermaidTheme('dark') resetMermaidTheme() ``` -------------------------------- ### Mermaid frontmatter inside a diagram code fence Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/7.migration/2.v4.md Single-diagram source configuration using Mermaid frontmatter inside the diagram's code fence, distinct from Content page frontmatter. ```markdown ```mermaid --- config: layout: elk --- flowchart LR A --> B ``` ``` -------------------------------- ### Mermaid YAML frontmatter for title, config, and toolbar Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/3.writing-diagrams.md Use Mermaid YAML frontmatter at the beginning of the diagram source for several values. The YAML `title`, `displayMode`, and `config` remain Mermaid-owned, while `toolbar` is converted into a built-in renderer prop. ```markdown ```mermaid --- title: Request flow config: theme: forest toolbar: title: Flow buttons: copy: false --- flowchart LR Browser --> Server --> Database ``` ``` -------------------------------- ### Opt into ELK for supporting diagrams across a Content page Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V4.md Uses a top-level `layout: elk` to apply ELK to all supporting diagram types (flowchart, class, state, ER, requirement, use case) on that page. ```yaml # Opt into ELK for supporting diagrams across this Content page config: layout: elk flowchart: curve: basis ``` -------------------------------- ### One-to-one migration: flowchart-only layout Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V4.md Replaces `flowchart.defaultRenderer: 'elk'` with `flowchart.layout: 'elk'` to keep the choice limited to flowcharts. ```yaml # Keep the choice flowchart-only (one-to-one migration) config: flowchart: layout: elk curve: basis ``` -------------------------------- ### Register module in nuxt.config Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/README.md Register the module in the Nuxt configuration file. ```ts export default defineNuxtConfig({ modules: ['@barzhsieh/nuxt-content-mermaid'], }) ``` -------------------------------- ### Mermaid frontmatter inside a diagram code fence Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V4.md Single-diagram source configuration using Mermaid frontmatter inside the code fence, distinct from Content page frontmatter. ```markdown ```mermaid --- config: layout: elk --- flowchart LR A --> B ``` ``` -------------------------------- ### Search for defaultRenderer in content Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V4.md Command to find occurrences of `defaultRenderer` in Markdown content, which Mermaid 12 ignores without warning. ```bash grep -rn "defaultRenderer" content/ ``` -------------------------------- ### Basic request/response sequenceDiagram with activation Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/sequence/basic.md Shows core sequenceDiagram syntax with participants, synchronous and asynchronous messages, and activation/deactivation. Use to verify rendering and theme changes. ```mermaid sequenceDiagram participant User participant Browser participant Server User->>Browser: Click "Save" activate Browser Browser->>Server: POST /api/save activate Server Server-->>Browser: 200 OK (JSON) deactivate Server Browser-->>User: Show "Saved" toast deactivate Browser ``` -------------------------------- ### Remove generated Content cache Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/6.troubleshooting.md Run from the application root to clear the default generated Content cache after upgrading, so Content reparses Markdown and picks up the new :page-data binding. Restart or rebuild afterward; in CI, invalidate any restored cache before building. ```sh rm -rf .data/content ``` -------------------------------- ### Configure expand open/close controls in defineNuxtConfig Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/3.interactions.md Configure the expand feature's margin and independent open/close controls. `expand` is enabled by default; set `expand: false` to disable it entirely. `margin` keeps pixels around the expanded SVG. ```TypeScript export default defineNuxtConfig({ contentMermaid: { expand: { margin: 24, invokeOpenOn: { diagramClick: true, }, invokeCloseOn: { esc: true, wheel: true, swipe: true, overlayClick: true, closeButtonClick: true, }, }, }, }) ``` -------------------------------- ### Expand booleans as resets in Mermaid configuration Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/7.migration/1.v3.md `expand: true` and `expand: false` reset the complete expand state to the package preset. An options object patches individual properties. To re-enable expansion after a lower layer disabled it, use `{ expand: { enabled: true, margin: 32 } }`. ```ts // A lower layer disabled expansion. { expand: false } // This changes the margin but does not re-enable expansion. { expand: { margin: 32 } } // Re-enable it explicitly. { expand: { enabled: true, margin: 32 } } ``` -------------------------------- ### Alternative paths with alt/else in sequenceDiagram Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/sequence/basic.md Demonstrates conditional branching with alt and else blocks, including activation and deactivation around API calls. Use to test alternative message flows. ```mermaid sequenceDiagram participant Client participant Auth participant API Client->>Auth: Sign in with credentials activate Auth alt Valid credentials Auth-->>Client: Issue token Client->>API: Call protected endpoint activate API API-->>Client: 200 OK deactivate API else Invalid credentials Auth-->>Client: Error message end deactivate Auth ``` -------------------------------- ### Keep Module Activation at build time Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V3.md Shows valid build-time activation via contentMermaid.enabled and an invalid public runtime transport. The public runtime transport is read once per Nuxt application and per SSR render context, producing a frozen Runtime Mermaid Snapshot; later mutations are not a rerender or activation API. ```ts // v3: valid build-time activation export default defineNuxtConfig({ contentMermaid: { enabled: false }, }) // v3: invalid public runtime transport export default defineNuxtConfig({ runtimeConfig: { public: { contentMermaid: { enabled: false }, }, }, }) ``` -------------------------------- ### Pie chart with showData and title Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/pie/basic.md Basic Mermaid pie chart syntax with showData and a title. Slices are declared in clockwise order with positive numbers. Uses neutral theme and textPosition 0.72. ```mermaid pie showData title Daily caffeine sources "Espresso shots" : 30 "Pour over" : 18 "Cold brew" : 22 "Tea" : 17 "Energy drinks" : 13 ``` -------------------------------- ### Mermaid fence with JSON toolbar configuration Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/3.writing-diagrams.md Use a single JSON object for the toolbar attribute, equivalent to dot notation. The `title` attribute is Mermaid diagram-title metadata, not the toolbar title. ```markdown ```mermaid {title="Request flow" config='{"theme":"forest"}' toolbar='{"title":"Flow","buttons":{"copy":false}}'} flowchart LR Browser --> Server --> Database ``` ``` -------------------------------- ### Mermaid quadrantChart for product backlog priorities Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/quadrant/product-priorities.md Use this Mermaid quadrant chart to visualize product backlog items by impact versus effort. The chart defines four quadrants with custom labels and includes point data for various backlog items. The configuration in the frontmatter adjusts chart dimensions, font sizes, and point styling for readability. ```mermaid quadrantChart title Product backlog priorities x-axis Low effort --> High effort y-axis Low value --> High value quadrant-1 Focus and ship quadrant-2 Schedule research quadrant-3 Reevaluate later quadrant-4 Explore Analytics dashboard : [0.78, 0.72] Multi-tenant isolation : [0.45, 0.48] In-app walkthrough : [0.28, 0.65] Local dev environment tweak : [0.62, 0.33] Cross-team OKR integration : [0.35, 0.38] Augmented onboarding demo : [0.15, 0.55] Beta pricing experiment : [0.52, 0.28] Custom report builder : [0.65, 0.6] ``` -------------------------------- ### Basic Mermaid fence in Markdown Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/3.writing-diagrams.md Use `mermaid` as the fenced-code language to create a diagram in Nuxt Content. Only a valid, non-empty top-level Mermaid fence is transformed; other Markdown stays unchanged. ```markdown ```mermaid flowchart TD A[Write Markdown] --> B[Nuxt Content] B --> C[Rendered diagram] ``` ``` -------------------------------- ### Configure built-in toolbar controls in Nuxt config Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/3.interactions.md Use in nuxt.config.ts to customize the built-in renderer's toolbar. All controls are enabled by default; set a button to false to hide it. The download control enables after a directly accessible SVG renders, and fullscreen shows only when the Fullscreen API is supported. ```ts export default defineNuxtConfig({ contentMermaid: { toolbar: { title: 'Architecture', fontSize: '14px', fullscreenToolbarScale: 1.25, buttons: { copy: true, fullscreen: true, expand: true, }, labels: { copy: 'Copy source', copied: 'Source copied', copyFailed: 'Copy failed', resetZoom: 'Reset view', download: 'Download diagram', downloadSvg: 'Download as SVG', downloadPng: 'Download as PNG', }, }, }, }) ``` -------------------------------- ### Normal Mermaid Chart with Toolbar Config Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/test-debug.md A Mermaid graph with frontmatter disabling the copy button and enabling fullscreen. Expected to log render time in debug mode. ```mermaid --- toolbar: buttons: copy: false fullscreen: true --- graph TD A[Start] --> B[Process] B --> C[End] ``` -------------------------------- ### Mermaid diagram with frontmatter and init directive Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/index.md Use this Mermaid code block in Markdown to render an interactive flowchart. The frontmatter sets the title, base theme, and toolbar options, while the init directive overrides the theme to dark and uses step curves. The diagram includes styled nodes and is displayed with a custom title and toolbar. ```mermaid --- title: Sample Flowchart config: theme: base toolbar: title: "Sample Diagram" fontSize: 24 fullscreenToolbarScale: 1.5 --- %%{init: { 'theme': 'dark', 'flowchart': { 'curve': 'step' } }}%% graph LR A[Start] --> B{Is it working?} B -->|Yes| C[Great!] B -->|No| D[Check Config] C --> E[Explore Gallery] D --> F[Read Docs] F --> B style A fill:#f9f,stroke:#333,stroke-width:2px,color:#333 style E fill:#bbf,stroke:#333,stroke-width:2px,color:#333 ``` -------------------------------- ### Mermaid requirementDiagram for thermal/battery stack Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/requirement/thermal-headset.md Defines a hardware thermal/battery requirement stack with requirement types, elements, classDef styling, and relations. Uses class assignments to highlight critical items and prototypes. Demonstrates styling via classDef plus requirement relations. ```mermaid requirementDiagram requirement thermal_limit { id: "HW-THERM-01" text: Skin temp stays under 42°C during 2h session. risk: high verifymethod: test } performanceRequirement battery_budget { id: "HW-THERM-02" text: Battery delivers 2h at 12W avg draw. risk: medium verifymethod: analysis } physicalRequirement heat_sink { id: "HW-THERM-03" text: Passive spreader dissipates 15W peak. risk: medium verifymethod: demonstration } interfaceRequirement vent_path { id: "HW-THERM-04" text: Vent path avoids camera fogging. risk: low verifymethod: inspection } designConstraint silent_fans { id: "HW-THERM-05" text: Fans stay under 25dBA at 30cm. risk: low verifymethod: test } element chamber { type: "environmental chamber" docRef: "lab/chamber-setup.md" } element headset_revC { type: "prototype" docRef: "cad/revC.step" } element test_matrix { type: "spreadsheet" docRef: "qa/thermal-battery-cases.xlsx" } classDef critical fill:#fee2e2,stroke:#ef4444,stroke-width:2px,color:#991b1b; classDef prototype fill:#e0f2fe,stroke:#0369a1,stroke-width:2px,color:#0f172a; class thermal_limit,heat_sink critical class headset_revC prototype thermal_limit - contains -> battery_budget battery_budget - derives -> heat_sink heat_sink - traces -> vent_path vent_path - refines -> silent_fans headset_revC - satisfies -> battery_budget chamber - verifies -> thermal_limit thermal_limit <- copies - test_matrix ``` -------------------------------- ### Add Mermaid fence to Markdown Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/README.md Add a Mermaid code fence to a Content Markdown file to render a diagram. ```markdown ```mermaid flowchart LR Markdown --> Content --> Mermaid --> SVG ``` ``` -------------------------------- ### Mermaid GitGraph feature train to release Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/gitgraph/feature-train.md Shows a feature flow branching off develop, merging multiple feature branches, and tagging a release. Uses rotateCommitLabel to keep labels readable when branches are dense. Demonstrates parallel feature branches merging back before a release tag. ```mermaid gitGraph commit id:"init" branch develop checkout develop commit id:"ci-setup" branch feature/login checkout feature/login commit id:"login-ui" commit id:"login-auth" checkout develop merge feature/login id:"merge-login" branch feature/metrics checkout feature/metrics commit id:"metrics-dash" commit id:"metrics-api" checkout develop merge feature/metrics id:"merge-metrics" checkout main merge develop id:"prep-release" commit id:"v1.0.0" tag:"v1.0.0" ``` -------------------------------- ### Pass supported function directly to Mermaid component Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V3.md Use this Vue component to pass a supported function or provider-owned capability directly, instead of through runtime config. ```vue ``` -------------------------------- ### Declare config field in collection schema Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/3.writing-diagrams.md Declare the `config` field in the content collection schema so that Mermaid pageConfig can receive it. Without this declaration, diagrams on the page do not use page configuration. ```ts import { defineCollection, defineContentConfig, z } from '@nuxt/content' export default defineContentConfig({ collections: { content: defineCollection({ type: 'page', source: '**', schema: z.object({ // Declare config as a collection field so Mermaid pageConfig can receive it. config: z.record(z.unknown()).optional(), }).passthrough(), }), }, }) ``` -------------------------------- ### Configure light and dark Mermaid themes in nuxt.config Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/1.themes-and-styling.md Sets the Mermaid themes used for automatic color mode in the Nuxt Content Mermaid module. Defaults are 'default' for light and 'dark' for dark. The deprecated 'theme.useColorModeTheme' key has no effect. ```ts export default defineNuxtConfig({ contentMermaid: { theme: { light: 'default', dark: 'dark', }, }, }) ``` -------------------------------- ### Mermaid journey diagram for mobile food ordering Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/userjourney/mobile-ordering.md Defines a two-actor journey (customer and kitchen) with sections for Discover, Select, Pay, and Fulfill. Uses actorColours and sectionColours to differentiate swimlanes without touching the theme. Satisfaction scores mix highs and lows to check rendering of gradients. ```mermaid journey title Mobile food ordering journey section Discover See promo push : 3: customer Open app homepage : 4: customer Update daily specials : 2: kitchen section Select Browse menu : 4: customer Apply dietary filter : 3: customer Mark sold-out items : 2: kitchen section Pay Checkout with Apple Pay : 5: customer Confirm order ticket : 3: kitchen section Fulfill Prepare order : 4: kitchen Pickup ready notification : 5: customer ``` -------------------------------- ### Legacy Page Mermaid Config with defaultRenderer Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V4.md Shows the old configuration using `flowchart.defaultRenderer: elk` that must be replaced. Mermaid 12 silently ignores this key at runtime. ```yaml # Legacy Page Mermaid Config config: flowchart: defaultRenderer: elk curve: basis ``` -------------------------------- ### Mermaid class diagram for personal finance ledger Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/classdiagram/finance-ledger.md Renders a class diagram with multiplicity, composition, and shared references for accounts, transactions, categories, budgets, tags, and attachments. Uses ASCII comments and labels for readability in both themes. Highlights many-to-many tags, optional recurring transactions, and shared currency across accounts. ```mermaid classDiagram direction LR %% Entities class User { +userId: int +name: String +email: String +passwordHash: String +createdAt: Date } class Account { +accountId: int +name: String +type: String +balance: float +currencyCode: String } class Transaction { +transactionId: int +date: Date +amount: float +note: String +isRecurring: boolean } class RecurringTransaction { +recurringId: int +interval: String +nextDate: Date } class Category { +categoryId: int +name: String +type: String } class Budget { +budgetId: int +amount: float +period: String +startDate: Date +endDate: Date } class Currency { +code: String +symbol: String +name: String } class Tag { +tagId: int +name: String } class Attachment { +attachmentId: int +fileName: String +url: String } %% Relationships User "1" --> "0..*" Account : owns Account "1" --> "0..*" Transaction : logs Transaction "1" --> "1" Category : categorized as User "1" --> "0..*" Budget : plans Budget "1" --> "1" Category : applies to Transaction "0..1" --> "1" RecurringTransaction : recurrence rule Account "1" --> "1" Currency : denominated in Transaction "0..*" --> "0..*" Tag : labeled with Transaction "0..*" --> "0..*" Attachment : supporting files ``` -------------------------------- ### Expand Booleans as Resets Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/docs/en/MIGRATION_V3.md Shows that expand: true and expand: false reset the complete expand preset, discarding lower-layer custom values. An object is a Property-Presence patch instead. ```ts // Lower layer { expand: false } // Does not reactivate expansion { expand: { margin: 32 } } // Explicitly reactivates expansion { expand: { enabled: true, margin: 32 } } ``` -------------------------------- ### Configure custom renderer and spinner in nuxt.config.ts Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/2.custom-rendering.md Sets `components.renderer` to a custom component name and optionally a spinner. The package searches `~/components` recursively for a matching filename, ignoring case, spaces, underscores, hyphens, path segments, and an optional `.vue` suffix. ```TypeScript export default defineNuxtConfig({ contentMermaid: { components: { renderer: 'CustomMermaid', spinner: 'MermaidSpinner', }, }, }) ``` -------------------------------- ### Set default toolbar labels in nuxt.config.ts Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/website/content/5.advanced/3.interactions.md Use `toolbar.labels` in `nuxt.config.ts` to set application-wide defaults for the Mermaid diagram toolbar controls. The object is a partial override: only configured labels change, omitted labels keep defaults, and an empty string is preserved as an explicit value. Each resolved label is reused as visible text, `title`, and `aria-label`. ```ts export default defineNuxtConfig({ contentMermaid: { toolbar: { labels: { copy: 'Copy source', copied: 'Source copied', copyFailed: 'Copy failed', expand: 'Expand diagram', collapse: 'Collapse diagram', minimize: 'Minimize diagram', enterFullscreen: 'Enter fullscreen', exitFullscreen: 'Exit fullscreen', zoomIn: 'Zoom in', zoomOut: 'Zoom out', resetZoom: 'Reset zoom', download: 'Download diagram', downloadSvg: 'Download as SVG', downloadPng: 'Download as PNG', }, }, }, }) ``` -------------------------------- ### Mermaid flowchart with various node shapes Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/flowchart/shapes.md Defines a flowchart (graph LR) that renders distinct node silhouettes: stadium, parallelogram, rectangle, rounded, diamond, database, subroutine, circle, and output. Labels can be swapped freely to test mixed languages. ```mermaid graph LR start([Stadium start]) --> input[/User input/] input --> rect[Rect box] rect --> rounded(Rounded step) rounded --> decision{Valid?} decision -->|Yes| db[(Database)] decision -->|No| subroutine[[Subroutine]] db --> circle((Circle)) subroutine --> output[\Output report\] circle --> done([Stop]) output --> done ``` -------------------------------- ### GitGraph hotfix backport diagram Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/playground/content/mermaid/gitgraph/hotfix-backport.md Mermaid gitGraph diagram illustrating a hotfix branched from main, merged to main and develop, with tags before and after. Keeps rotateCommitLabel false to see default label orientation; useful for checking branch rendering when backporting fixes. ```mermaid gitGraph commit id:"init" branch develop commit id:"feat-A" commit id:"feat-B" checkout main merge develop id:"release-1.0" commit id:"v1.0.0" tag:"v1.0.0" branch hotfix/critical commit id:"fix-null" checkout main merge hotfix/critical id:"main-hotfix" commit id:"v1.0.1" tag:"v1.0.1" checkout develop merge hotfix/critical id:"backport-hotfix" branch feature/cleanup checkout feature/cleanup commit id:"linting" checkout develop merge feature/cleanup id:"cleanup-merge" ``` -------------------------------- ### Mermaid sequence diagram: Alice and Bob Source: https://github.com/andy820621/nuxt-content-mermaid/blob/main/test/fixtures/transform/multiple-blocks.md A Mermaid sequence diagram with participants Alice and Bob exchanging a message. Use for interaction flows. ```mermaid sequenceDiagram participant Alice participant Bob Alice->>Bob: Hello Bob-->>Alice: Hi! ```