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 generator | setup |
|---|---|
| VitePress | yuhwa/markdown-it |
| VuePress 2 | yuhwa/vuepress |
| Astro, Starlight | yuhwa/astro |
| Docusaurus | yuhwa/remark |
| Vocs | yuhwa/remark |
| Nextra, Fumadocs, any MDX | yuhwa/remark |
| Rspress | yuhwa/remark |
| Eleventy, any markdown-it | yuhwa/markdown-it |
ironmark (.md, .mdx, runtime) | yuhwa/ironmark |
| Vite apps (React, Vue, Svelte, Solid) | yuhwa/vite |
| Docsify, Hugo, Jekyll | the script tag |
| GitHub, GitLab, npm READMEs | yuhwa md |
Install once for all of them:
npm install -D yuhwapnpm add -D yuhwaWhat the plugins do
Each ```yuhwa block becomes:
<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
paperfor light mode andmidnightfor dark mode.yuhwa/style.cssshows the one that matches the site's colour toggle. A block that setstheme: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. Thetitle:setting becomes thealttext. - 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: falseto show them under the diagram instead. - Opt out per block.
```yuhwa no-renderstays a highlighted code block. Use it for syntax examples and fragments.
Options
All integrations take the same options:
| option | default | effect |
|---|---|---|
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 | |
strict | true | false shows errors under the diagram instead of failing the build |
languages | ['yuhwa', 'yu'] | fence languages to render |
root | folder that file= paths and their imports must stay inside; file="/x.yu" starts there | |
zoom | false | true makes every figure a pan and zoom viewer; 'inline' also adds the script to each page |
zoomHeight | the viewer's height with zoom on, in pixels or any CSS length; by default the diagram's own height | |
snapGrid, measure | passed 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:
output | the page gets | fonts | needs |
|---|---|---|---|
'img' (default) | the SVG as an <img> | the reader's system fonts | |
'svg' | the SVG inline; text can be selected, links work | the page's web fonts and system fonts | markdown-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 browser | the page's web fonts and system fonts | the yuhwa/canvas client script |
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-jsorpnpm add -D @resvg/resvg-js. The image keeps the diagram's size and hasscaletimes as many pixels, so it stays sharp on high-density screens.png.fontstakes ttf, otf and ttc files or folders, relative to where the build runs. Setpng.systemFonts: falsefor the same image on every machine. Builds with many diagrams also run faster that way, since resvg then reads onlypng.fonts, not every font installed.canvas keeps the SVG
<img>in the page, so the diagram shows without JavaScript.yuhwa/canvasdraws 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:tsimport 'yuhwa/canvas';
A fence can pick its own output with output=img, output=png or output=canvas:
```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:
```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
rootto keep paths inside one folder. A path outside it is an error. - With
rootset,file="/arch.yu"starts atroot.
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
.mdxfiles re-render. A content collection caches.mdentries by their text, so setdeferRender: trueon 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.
```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:
// .vitepress/theme/index.ts
import 'yuhwa/zoom';Or put the script in the page head. zoomScript holds it as a string:
// 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
// .vitepress/config.ts
import { defineConfig } from 'vitepress';
import yuhwa from 'yuhwa/markdown-it';
export default defineConfig({
markdown: {
config: (md) => md.use(yuhwa),
},
});// .vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme';
import 'yuhwa/style.css';
export default DefaultTheme;VuePress
// .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
// 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
// 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
// vocs.config.ts
import { defineConfig } from 'vocs';
import remarkYuhwa from 'yuhwa/remark';
export default defineConfig({
markdown: { remarkPlugins: [remarkYuhwa] },
});/* docs/styles.css (Vocs loads it automatically) */
@import 'yuhwa/style.css';Nextra
// 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
// 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
// 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
// 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:
// 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:
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:
// vite.config.ts
import { defineConfig } from 'vite';
import yuhwa from 'yuhwa/vite';
export default defineConfig({ plugins: [yuhwa()] });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:
/// <reference types="yuhwa/client" />The plugin takes theme and darkTheme. Errors fail the build, and imported files are watched in dev.
Docsify
<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:
<!-- layouts/_default/_markup/render-codeblock-yuhwa.html -->
<div class="yuhwa">{{ .Inner }}</div>
{{ .Page.Store.Set "hasYuhwa" true }}<!-- 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:
<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:
remarkYuhwafromyuhwa/remark. - Any markdown-it pipeline:
md.use(yuhwa)fromyuhwa/markdown-it. - Your own code:
render(source).svgfromyuhwa. See the API. - No build step: the script tag.
- No JavaScript at all:
yuhwa mdwrites SVG files and image links into the Markdown.