notesy::blocks
Fenced blocks drawn as pictures. A plugin names the languages it draws in
[contributes] blocks (plugin.toml), which
asks for the markdown permission, and its script draws each block as SVG.
In live preview, a block fenced with one of those languages shows as the
picture; with the caret in it, as its text.
tomlmain = "main.rn"
[contributes]
blocks = ["bars"]
markdown```bars
Mon: 3
Tue: 5
Wed: 2
```
rustuse notesy::blocks;
pub fn ready() {
blocks::on("bars", |source, cx| {
let rows = [];
for line in source.split("\n") {
if let Some((label, value)) = line.split_once(":") {
if let Ok(n) = value.trim().parse::<i64>() {
rows.push((label.trim(), n));
}
}
}
let max = 1;
for (_, n) in rows { if n > max { max = n; } }
let svg = `<svg xmlns="http://www.w3.org/2000/svg" width="320" height="${rows.len() * 24}" font-family="sans-serif" font-size="14">`;
let y = 0;
for (label, n) in rows {
let width = 220 * n / max;
svg += `<text x="0" y="${y + 16}" fill="${cx.colors.text}">${label}</text>`;
svg += `<rect x="80" y="${y + 4}" width="${width}" height="16" rx="3" fill="${cx.colors.accent}"/>`;
y += 24;
}
svg + "</svg>"
});
}
#blocks::refresh(lang)
Every lang block is drawn again, though its text hasn't changed: for a
picture that shows more than its block says, like the notes a query
finds. Call it when what it shows has changed (note.saved, say); each
block on screen is asked for again, and the ones off screen when they show.
#blocks::on(lang, draw)
draw(source, context) makes the picture for a block fenced with lang,
one of the languages its manifest names: source is the block's text, and
it returns SVG text. Returning Err(why), or failing, shows the block as
text, and the plugin's log says why.
context is what the block is drawn for:
| Field | What it is |
|---|---|
dark |
Whether the theme is dark. |
scale |
The editor's text size, relative to the default. Draw at the default size: notesy scales the picture. |
colors |
The theme's colors, as #rrggbb: page (behind it), node (a box's fill), heading, text, line (lines, arrows, quieter text), border, group (a group's fill), note (a note's fill) and accent. |
#How it's drawn
- Never on the window's thread: notesy's diagrams worker asks the plugin's script, which draws on its own thread within the budget for a view. A block the script hasn't drawn within five seconds shows as text.
- A block is drawn again only when its text, the theme's colors, the text size or the screen's pixel density change, or when the script starts again. Drawn blocks share notesy's texture budget with diagrams.
- The SVG is read locked down: an
<image>in it may be inline data, but never a file on this computer. At most 8 MB of SVG; a picture's longest side is at most 4,096 pixels. - An SVG that moves (
<animate>,<animateTransform>and<set>, as an icon's can:notesy::icons) is drawn at each of its frames, as many as fit 24 MB (a big picture keeps fewer), and plays as the Motion setting says: briefly as it comes into sight, always, or not at all. At rest, one that plays once (bars growing in) shows how it ends. mermaidandtypstare notesy's own, and a plugin can't claim them.
Every page
- Overview
- plugin.toml: Every field of plugin.toml
- Permissions: What a plugin can ask for, when notesy asks, and what changes it
- Scripts: How a script runs: its lifecycle, events, limits and errors
- Packing and installing: Making, checking, signing, packing and installing
- notesy::log: Lines for its log on the Plugins page
- notesy::events: Hearing what happens, and every event
- notesy::commands: Adding commands, and running notesy's
- notesy::store: Keeping its own data
- notesy::settings: Reading its settings
- notesy::secrets: Keys and tokens, in the system keychain
- notesy::notes: Reading and changing the vault's notes
- notesy::editor: The note in front
- notesy::templates: What templates fill in, and functions of its own for them
- notesy::files: A folder of its own
- notesy::links: Opening pages in the browser, naming links after their pages
- notesy::clipboard: Copying and pasting
- notesy::view: What panels, tabs and sections show
- notesy::sections: Sidebar sections
- notesy::hidden: Hiding notes, files and folders from the tree
- notesy::status: Status bar items
- notesy::tools: Buttons in the formatting bar
- notesy::notices: Notices
- notesy::dialogs: Asking in a dialog, notesy's kinds or its own
- notesy::wizards: Pages one after another, like a setup
- notesy::boards: Boards' cards and arrows, and kinds of card of its own
- notesy::blocks: Drawing its fenced blocks
- notesy::icons: Drawing its own icons
- notesy::net: Requests to the sites it names
- notesy::ipc: Talking to a program on this computer
- notesy::accounts: Signing in to a service
- notesy::json: Reading and writing JSON
- notesy::toml: Reading and writing TOML
- notesy::yaml: Reading and writing YAML, and a note's front matter
- notesy::time: Now, written in the user's time zone, dates read, how long ago
- notesy::math: Trigonometry and the like, for drawing
- Names: Icon, Color, Tone, Side, Method, Command, Zone, Event: Notesy's names as enums
- notesy::preview: Its own screens for notesy preview
- notesy::perf: Timing its own work
- notesy::drawings: Drawings' shapes, and buttons in their tool strip
- notesy::sound: Playing sounds, and making them as it runs
- notesy::tex: Math macros for every note's formulas
- notesy::views: Side panels, tabs of its own, and its part of the tree's hover cards
- notesy::zones: Notesy's own places — its menus, its bars and its headings