Skip to content

Docs sites and frameworks ​

Write diagrams as ```yuhwa fenced blocks in your Markdown. A build-time plugin turns each block into an SVG figure. Readers download no JavaScript, and a broken diagram fails the build instead of shipping.

site generatorsetup
VitePressyuhwa/markdown-it
VuePress 2yuhwa/vuepress
Astro, Starlightyuhwa/astro
Docusaurusyuhwa/remark
Vocsyuhwa/remark
Nextra, Fumadocs, any MDXyuhwa/remark
Rspressyuhwa/remark
Eleventy, any markdown-ityuhwa/markdown-it
ironmark (.md, .mdx, runtime)yuhwa/ironmark
Vite apps (React, Vue, Svelte, Solid)yuhwa/vite
Docsify, Hugo, Jekyllthe script tag
GitHub, GitLab, npm READMEsyuhwa md

Install once for all of them:

sh
npm install -D yuhwa
sh
pnpm add -D yuhwa

What the plugins do ​

Each ```yuhwa block becomes:

html
<figure class="yuhwa" data-yuhwa>
  <img class="yuhwa-svg yuhwa-light" src="data:image/svg+xml,…" alt="Title" />
  <img class="yuhwa-svg yuhwa-dark" src="data:image/svg+xml,…" alt="Title" />
</figure>
  • Light and dark. Every diagram renders twice: with paper for light mode and midnight for dark mode. yuhwa/style.css shows the one that matches the site's colour toggle. A block that sets theme: renders once.
  • Images, not inline SVG. Vue-based sites strip the <style> inside an SVG, MDX rejects raw HTML, and diagram text would clutter the search index. The title: setting becomes the alt text.
  • Imports. import "./shared.yu" resolves against the Markdown file, so pages can share classes and nodes.
  • Errors fail the build with the file, line and message. Set strict: false to show them under the diagram instead.
  • Opt out per block. ```yuhwa no-render stays a highlighted code block. Use it for syntax examples and fragments.

Options ​

All integrations take the same options:

optiondefaulteffect
theme'paper'theme for light mode
darkTheme'midnight'theme for dark mode; false renders one image
darkMode'class''class': two images, switched by style.css; 'media': a <picture> that follows the OS setting and needs no CSS
output'img'what the page gets: 'img', 'svg', 'png' or 'canvas', see Output
png{ scale, fonts, systemFonts } for output: 'png'; scale 2 and system fonts by default
stricttruefalse shows errors under the diagram instead of failing the build
languages['yuhwa', 'yu']fence languages to render
rootfolder that file= paths and their imports must stay inside; file="/x.yu" starts there
zoomfalsetrue makes every figure a pan and zoom viewer; 'inline' also adds the script to each page
zoomHeightthe viewer's height with zoom on, in pixels or any CSS length; by default the diagram's own height
snapGrid, measurepassed to render

style.css switches to dark mode under .dark, [data-theme="dark"], [data-mode="dark"] or .theme-dark on any ancestor. That covers the toggles of every generator on this page. On a page without a toggle it follows the OS.

Output ​

output picks what the page shows for each diagram:

outputthe page getsfontsneeds
'img' (default)the SVG as an <img>the reader's system fonts
'svg'the SVG inline; text can be selected, links workthe page's web fonts and system fontsmarkdown-it or Astro; not Vue sites
'png'a PNG drawn at build time, as an <img>the build machine's fonts and png.fonts@resvg/resvg-js at build time
'canvas'a <canvas> drawn in the reader's browserthe page's web fonts and system fontsthe yuhwa/canvas client script
ts
remarkYuhwa({ output: 'png', png: { scale: 3, fonts: ['fonts/Inter.ttf'] } });
  • png draws the diagram with resvg, the same way as yuhwa render -o x.png. Install it as a dev dependency: npm install -D @resvg/resvg-js or pnpm add -D @resvg/resvg-js. The image keeps the diagram's size and has scale times as many pixels, so it stays sharp on high-density screens. png.fonts takes ttf, otf and ttc files or folders, relative to where the build runs. Set png.systemFonts: false for the same image on every machine. Builds with many diagrams also run faster that way, since resvg then reads only png.fonts, not every font installed.

  • canvas keeps the SVG <img> in the page, so the diagram shows without JavaScript. yuhwa/canvas draws each one into a canvas, with the page's web fonts embedded, and swaps it in as it comes near the viewport. Astro and VuePress load the script for you. Elsewhere, import it once in the site's client code:

    ts
    import 'yuhwa/canvas';

A fence can pick its own output with output=img, output=png or output=canvas:

md
```yuhwa output=png
a -> b
```

A fence cannot pick svg, because MDX and Vue-based sites cannot take it.

Diagrams from files ​

A block can render a .yu or .yuhwa file instead of its own text:

md
```yuhwa file="../diagrams/arch.yu"

```
  • The path is relative to the Markdown file.
  • Imports inside the file resolve relative to that file.
  • Leave the block empty. If it has text, the text is ignored with a warning.
  • A missing file fails the build, like a broken diagram.
  • Set root to keep paths inside one folder. A path outside it is an error.
  • With root set, file="/arch.yu" starts at root.
ts
remarkYuhwa({ root: 'docs' });

yuhwa md does not read file= blocks.

Live reload ​

In dev, a page re-renders when a file= target or an imported .yu file changes:

  • VitePress and VuePress: the plugin hands the files to the dev server.
  • Astro: pages and .mdx files re-render. A content collection caches .md entries by their text, so set deferRender: true on its loader: glob({ pattern: '**/*.md', base: './src/content/docs', deferRender: true }).
  • ironmark and Vite apps: Vite watches the files.
  • Eleventy: add config.addWatchTarget('**/*.yu'); Eleventy then rebuilds.
  • Other remark hosts (Docusaurus, Nextra, Fumadocs, Rspress, Vocs) have no way to report the files: save the Markdown file or restart the dev server.

Zoom and pan ​

Large diagrams get small on a docs page. A zoom flag on a block turns it into a viewer: drag to pan, pinch or Ctrl/⌘ + scroll to zoom, double-click to zoom in, and buttons for zoom and full screen. The keys +, -, 0 and the arrows work once it has focus. A plain scroll still scrolls the page.

md
```yuhwa zoom
web -> api -> db
```

```yuhwa zoom=480
web -> api -> db
```

zoom alone keeps the diagram's own height. zoom=480 makes the viewer 480 pixels high and fits the diagram inside, zoom="60vh" takes any CSS length.

Set the zoom option to make every block a viewer, and zoomHeight for their height. A no-zoom flag then leaves one block out.

The page needs a small script. Astro and VuePress add it for you. Elsewhere, import yuhwa/zoom once in the client:

ts
// .vitepress/theme/index.ts
import 'yuhwa/zoom';

Or put the script in the page head. zoomScript holds it as a string:

ts
// vocs.config.ts
import { zoomScript } from 'yuhwa/zoom';

export default defineConfig({
  head: <script dangerouslySetInnerHTML={{ __html: zoomScript }} />,
  markdown: { remarkPlugins: [[remarkYuhwa, { zoom: true }]] },
});

For plain HTML output, set zoom: 'inline'. Each page with a diagram then carries the script itself. Do not use 'inline' with MDX or Vue sites.

The viewer uses the light or dark colours of the page. Set --yuhwa-zoom-bg to change its background in full screen.

VitePress ​

ts
// .vitepress/config.ts
import { defineConfig } from 'vitepress';
import yuhwa from 'yuhwa/markdown-it';

export default defineConfig({
  markdown: {
    config: (md) => md.use(yuhwa),
  },
});
ts
// .vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme';
import 'yuhwa/style.css';

export default DefaultTheme;

VuePress ​

ts
// .vuepress/config.ts
import { defineUserConfig } from 'vuepress';
import { yuhwaPlugin } from 'yuhwa/vuepress';

export default defineUserConfig({
  plugins: [yuhwaPlugin()],
});

The plugin also loads style.css.

Astro and Starlight ​

js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import yuhwa from 'yuhwa/astro';

export default defineConfig({
  integrations: [starlight({ title: 'Docs' }), yuhwa()],
});

The integration renders blocks in .md and .mdx files and loads style.css. Leave out starlight(...) for a plain Astro site.

It works with either Markdown processor: Sätteri, the Astro 7 default, and unified() from @astrojs/markdown-remark. With Sätteri, output: 'svg' works in .md and .mdx alike.

Docusaurus ​

js
// docusaurus.config.js
import remarkYuhwa from 'yuhwa/remark';

export default {
  presets: [
    [
      'classic',
      {
        docs: { remarkPlugins: [remarkYuhwa] },
        blog: { remarkPlugins: [remarkYuhwa] },
        pages: { remarkPlugins: [remarkYuhwa] },
        theme: { customCss: ['./src/css/custom.css', require.resolve('yuhwa/style.css')] },
      },
    ],
  ],
};

In an ES module config, replace require.resolve(...) with import.meta.resolve('yuhwa/style.css').replace('file://', ''), or add @import 'yuhwa/style.css'; to custom.css.

Vocs ​

ts
// vocs.config.ts
import { defineConfig } from 'vocs';
import remarkYuhwa from 'yuhwa/remark';

export default defineConfig({
  markdown: { remarkPlugins: [remarkYuhwa] },
});
css
/* docs/styles.css (Vocs loads it automatically) */
@import 'yuhwa/style.css';

Nextra ​

js
// next.config.mjs
import nextra from 'nextra';
import remarkYuhwa from 'yuhwa/remark';

const withNextra = nextra({
  mdxOptions: { remarkPlugins: [remarkYuhwa] },
});

export default withNextra({});

Import yuhwa/style.css in app/layout.tsx (or pages/_app.tsx).

Fumadocs ​

ts
// source.config.ts
import { defineConfig } from 'fumadocs-mdx/config';
import remarkYuhwa from 'yuhwa/remark';

export default defineConfig({
  mdxOptions: { remarkPlugins: [remarkYuhwa] },
});

Import yuhwa/style.css in your root layout. Any other MDX setup works the same way: add remarkYuhwa to remarkPlugins.

Rspress ​

ts
// rspress.config.ts
import path from 'node:path';
import { defineConfig } from 'rspress/config';
import remarkYuhwa from 'yuhwa/remark';

export default defineConfig({
  markdown: { remarkPlugins: [remarkYuhwa] },
  globalStyles: path.join(import.meta.dirname, 'node_modules/yuhwa/dist/style.css'),
});

Rspress 1 compiles MDX with a Rust compiler that skips remark plugins. There, also set markdown.mdxRs: false.

Eleventy ​

js
// eleventy.config.js
import yuhwa from 'yuhwa/markdown-it';

export default function (config) {
  config.amendLibrary('md', (md) => md.use(yuhwa, { darkMode: 'media' }));
  // rebuild when a diagram file changes
  config.addWatchTarget('**/*.yu');
}

darkMode: 'media' follows the reader's OS setting and needs no stylesheet. The same md.use(yuhwa) line works in any markdown-it setup: Slidev, Marp, markdown-it in Node scripts.

ironmark ​

ironmark compiles .md and .mdx files to components. Put the yuhwa plugin before ironmark's plugin. Both are pre plugins, so they run in the order you list them:

ts
// vite.config.ts
import { defineConfig } from 'vite';
import ironmark from 'ironmark/vite';
import yuhwa from 'yuhwa/ironmark';

export default defineConfig({ plugins: [yuhwa(), ironmark()] });

Import yuhwa/style.css in your app entry to get the light/dark switch.

At runtime, render the fences first and then parse the result:

js
import ironmark from 'ironmark';
import { renderFences } from 'yuhwa/ironmark';

const html = ironmark.parse(renderFences(markdown, {}, 'docs/page.md')).html();

The third argument is the file path. yuhwa resolves imports relative to it and uses it in error messages. In .mdx files, the figure uses className instead of class.

Vite apps ​

Import .yu files as SVG strings in React, Vue, Svelte or Solid apps:

ts
// vite.config.ts
import { defineConfig } from 'vite';
import yuhwa from 'yuhwa/vite';

export default defineConfig({ plugins: [yuhwa()] });
tsx
import svg, { darkSvg, title } from './architecture.yu';

export const Architecture = () => <div role="img" aria-label={title} dangerouslySetInnerHTML={{ __html: svg }} />;

For TypeScript, add the module types once, in any .d.ts file or as "types": ["yuhwa/client"] in tsconfig.json:

ts
/// <reference types="yuhwa/client" />

The plugin takes theme and darkTheme. Errors fail the build, and imported files are watched in dev.

Docsify ​

html
<script>
  window.$docsify = {
    plugins: [(hook) => hook.doneEach(() => Yuhwa.run())],
  };
</script>
<script src="https://cdn.jsdelivr.net/npm/docsify@4"></script>
<script src="https://cdn.jsdelivr.net/npm/yuhwa/dist/yuhwa.iife.js" data-manual></script>

Hugo ​

Add a render hook for the yuhwa language and load the script once in your base layout:

html
<!-- layouts/_default/_markup/render-codeblock-yuhwa.html -->
<div class="yuhwa">{{ .Inner }}</div>
{{ .Page.Store.Set "hasYuhwa" true }}
html
<!-- layouts/_default/baseof.html, before </body> -->
{{ if .Store.Get "hasYuhwa" }}
<script src="https://cdn.jsdelivr.net/npm/yuhwa/dist/yuhwa.iife.js"></script>
{{ end }}

Jekyll and plain HTML ​

Markdown renderers turn ```yuhwa into <pre><code class="language-yuhwa"> (and ```yu into language-yu). The script tag renders those in place:

html
<script src="https://cdn.jsdelivr.net/npm/yuhwa/dist/yuhwa.iife.js"></script>

Without a theme: setting each diagram follows the reader's colour scheme. See Embedding for the web component and the API.

Something else ​

  • Any remark or rehype pipeline: remarkYuhwa from yuhwa/remark.
  • Any markdown-it pipeline: md.use(yuhwa) from yuhwa/markdown-it.
  • Your own code: render(source).svg from yuhwa. See the API.
  • No build step: the script tag.
  • No JavaScript at all: yuhwa md writes SVG files and image links into the Markdown.

Released under the MIT License.