Canvas
Render Obsidian .canvas files (JSON Canvas 1.0) as diagrams.
Usage
import { defineConfig } from "@riebeckite/core";
import { canvas } from "@riebeckite/plugin-canvas";
export default defineConfig({
// ...
plugins: [canvas({ render: "both" })],
});
The plugin runs with order: -15, after obsidian-markdown.
Accepted inputs
- A
```canvasfence whose body is raw JSON Canvas -
A
```canvasfence whose body is![[diagram.canvas]]or[[diagram.canvas]], read throughcontentSource - A direct
![[diagram.canvas]]embed, resolved as an attachment
When a canvas is missing or cannot be parsed, the code block is kept and a
message with source: "@riebeckite/plugin-canvas" is reported.
Output
The plugin emits div.rb-canvas with data-canvas (the input), data-canvas-nodes,
data-canvas-edges, and data-canvas-render (static / client / both, or
ready after hydration). It contains:
-
script[type="application/json"][data-canvas-payload]— escaped JSON Canvas; inert, never executed -
div.rb-canvas__static— whenrenderis"static"or"both": a no-JS layered fallback with absolutely positioned node cards and an SVG edge list -
div.rb-canvas__stage— whenrenderis"client"or"both": an empty stage filled byinitCanvas() details.rb-canvas__fallback— a node/edge list for accessibility and no-JS
file nodes resolve through contentIndex: notes link to their permalink and
other files link to their attachment URL. Note links are finalised in
onManifestCreated from the manifest, rewriting the manifest entry's HTML. Core
synchronizes that HTML with the content the route renders. text nodes get
minimal Markdown handling (wikilinks and escaping).
Client
initCanvas() finds elements whose data-canvas-render is client / both,
builds positioned nodes and SVG edges from the payload, then sets
data-canvas-render="ready"; CSS hides the static fallback once ready. It also
supports wheel zoom and drag pan (pan/zoom-lite).
Options
| Option | Default | Description |
|---|---|---|
className |
"rb-canvas" |
Wrapper class name |
language |
"canvas" |
Code fence language |
render |
"both" |
"static", "client", or "both" |
height |
unset | Stage height (px number or CSS length) |
maxNodes |
unset | Maximum number of nodes drawn |
Exports
canvas(options?)/canvasPlugin— plugin factoryinitCanvas()— client initializerparseCanvas(json)— pure JSON Canvas parserbuildCanvasLayout(doc)— pure coordinate/edge normaliserresolveCanvasOptions(options)— apply defaults-
Types:
CanvasOptions,CanvasRenderMode,CanvasDocument,CanvasNode,CanvasEdge, and more