Expand description
Zorite’s reader view: a small read-only markdown renderer for GPUI.
(Editing — WYSIWYG and raw — is the separate zorite-editor crate; the two
engines share nothing, so any markdown behavior added here must be checked
there and vice versa. See AGENTS.md “The three views”.)
It parses markdown to an AST (via the markdown crate) and renders
it with gpui’s own StyledText / InteractiveText, so paragraphs
wrap properly and links are clickable through a real callback — not
cx.open_url, which only opens externally.
It is deliberately host-agnostic: styling comes in via MarkdownStyle,
and clicking a [[wiki-link]] invokes a caller-supplied closure
(on_wiki_link) rather than knowing anything about the host app.
Standard [text](url) links open externally via cx.open_url.
Covers CommonMark + GFM: headings, paragraphs, bold/italic/strikethrough/
inline-code, fenced code blocks, ordered/unordered/nested and task lists,
blockquotes, thematic breaks, hard breaks, tables, links (inline and
reference-style), images (rendered by the host via on_image), footnotes,
and raw HTML (shown literally, never executed — except <mark>, which renders
as highlighted text). [[wiki-links]] and #tags become clickable via caller
callbacks.
Modules§
- syntax
- Shared markdown-construct recognition — the definitions both of
Zorite’s engines consume so they can never drift apart (links navigated in
the reader for months while WYSIWYG ignored clicks; alerts were once
recognized in three separate places). The reader (this crate’s view),
the WYSIWYG editor (
zorite-editor), and any other consumer (PDF export) share what counts as a construct and what’s its payload; each keeps its own rendering. Everything here is engine-neutral and gpui-free.
Structs§
- Alert
Colors - Border + title colors for the five GitHub-style alerts (
> [!NOTE]…). Defaults are GitHub’s dark palette; the host overlays its theme. - Alert
Icons - Per-kind SVG asset paths for the alert title icons.
- Image
Info - A standalone image (a paragraph that is just
, optionally followed by a{width=N}attribute). Handed to the host’sImageRendererso it can render a real, possibly interactive, image element. - Labels
- A rendered markdown document element — the reader view of a note.
- Markdown
Style - Visual configuration for the renderer. The host fills this from its own theme; defaults are a neutral dark palette.
- Markdown
View - A rendered markdown document element — the reader view of a note.
- Snippet
- An authoring snippet for a markdown construct: a label, the text to insert, and the caret offset (bytes) within that text. Exposed so a host’s command palette can offer markdown commands without re-deriving the syntax. Pure data — no rendering involved.
Enums§
- List
Edit - What pressing Enter should do on a markdown list / blockquote line.
Constants§
- INDENT
- The default indent level (two spaces) for Tab / Shift+Tab on list items. The
host passes its configured indent to
indent_list_line/outdent_line; this is just the fallback / a convenience for callers without a setting. - SNIPPETS
- Built-in markdown authoring snippets (for a
/command palette).
Functions§
- alert_
children - If blockquote
bis a GitHub alert, return its kind and a copy of its children with the marker stripped (the first text’s source offset advances by the stripped length, so the rendered→source click map stays aligned). Public so other renderers of the same construct (e.g. a PDF exporter) share the exact recognition. - alert_
parts alert_childrenplus the callout’s fold state (Some(true)= folded) and the marker’s source byte offset — what a foldable callout’s chevron click reports so the host can flip the-/+in the source.- all_
image_ srcs - Every image
srcinsource— block (leading) AND inline — so the host can pre-decode them all (inline images render as rasters too, not just leading ones). Pure: parses the markdown, no I/O. - find_
matches - The block index (top-level column-child index, as rendered) of each match of
queryinsource, in document order. Pair withMarkdownView::track_blocks: the host readsbounds_for_item(find_matches(..)[current])to scroll the active match’s block into view. No I/O; shares the render path’s memoized parse, so calling it per keystroke costs one parse, not one per character. - images
- Every standalone image in
source(a paragraph or list item that begins with), in document order — each with its parsed{width=N}(if any) and theattr_targetbyte range to overwrite to set or replace that width. Mirrors how the renderer detects block images, so the offsets line up with what’s on screen. Pure: parses the markdown, no I/O or storage. - indent_
list_ line - If the caret’s line is a list/quote item, indent it one level (insert
indentat the line start), returning the new text and shifted caret.Nonewhen the line isn’t a list item, so the caller can insert a literal tab instead. - list_
continuation - Decide how Enter continues a markdown list/quote at
cursorinvalue. Recognizes-/*/+bullets,N./N)ordered items,- [ ]task items, and>blockquotes (leading indent preserved). A non-empty item continues with the next marker; an empty item exits the list.Nonewhen the current line isn’t a list/quote item. - match_
count - Count case-insensitive matches of
queryin the rendered (visible) text ofsource— the same matchesMarkdownView::searchhighlights, in the same order. Pure: parses the markdown, no I/O or storage. Empty query → 0. Use it to size a host find bar’s “n of m” and to bound the active-match index. - needs_
warm - Would rendering
sourceblock on a parse — i.e. is it expensive-shaped AND not cached yet? Hosts check this before spawning a warm task, so ordinary notes (which parse inline in microseconds) spawn nothing at all. - outdent_
line - Outdent the caret’s line one level: remove up to
indent’s width of leading spaces (or one leading tab). Returns the new text and caret, orNoneif the line has no leading indent to remove. - reindent
- Re-indent every space-indented list / quote item in
contentfromold-space nesting units tonew-space units (e.g. when the list-indent setting changes), so existing nesting matches the new width. Each item’s level is its leading spaces ÷old. Non-list lines, top-level items, and tab-indented lines are left untouched.Nonewhen nothing changes. - toggle_
task_ at - Toggle the GFM task checkbox on the source line containing byte
offset(a task item’s offset, as reported byMarkdownView::on_task_toggle). Returns the fullcontentwith that one checkbox flipped ([ ]↔[x]), orNoneif there’s no task checkbox on that line. Length is unchanged (one ASCII byte swapped). - warm_
parse - Parse
sourceinto the shared cache unless it’s already there. Pure and gpui-free by design — call it from a background thread (the host usescx.background_executor()), because that is the only place a superlinear parse can run without wedging the UI.
Type Aliases§
- Block
RefCount Fn - Maps a block id to how many pages reference it (0 = no badge).
- Click
Source Handler - Called when the rendered text is clicked (outside a link), with the source
byte offset nearest the click and the click’s window y — so the host can
place its editor caret there and keep it under the cursor when switching into
edit mode. Set via
MarkdownView::on_click_source. - Code
Highlighter - Colors a fenced code block’s tokens:
(language tag, code) → sorted, non-overlapping styled ranges(byte offsets into the code). Supplied by the host (e.g. a tree-sitter highlighter) so the crate stays engine-free; absent it, code renders in the singlecode_color. - Embed
Provider - Resolves a standalone
![[target]]embed to(source label, content)— the host pre-resolves targets from its database (a page, a#^idblock, or a#Headingsection) since render-time providers can’t query.None(or a missing target) falls back to rendering the line as text. - Heading
Toggle Handler - Called when a heading’s fold chevron is clicked, with the heading’s fold
key — its trimmed source line (
## Goals). The host owns the fold set (this view is rebuilt every frame) and passes it back viaMarkdownView::folded_headings. - Image
Preview Handler - A click on an inline image reports its
srcso the host can open a full-size preview. Set viaMarkdownView::on_image_preview. - Image
Renderer - Renders a standalone image. The element’s event handlers run later (with their own context), so building it needs no window/app — letting the host supply a stateful, draggable image while this crate stays host-agnostic.
- Inline
Image Renderer - A renderer for an INLINE image (
amid text): its src → the raster plus logical(w, h)sized to flow at the text’s line height. Like inline math, the caller reserves a spacer in the line and paints the image over it;None(still decoding / no renderer) falls back to a clickable label. - Inline
Math Renderer - Resolves an inline
$…$formula’s LaTeX to its typeset raster + logical (display) px size at text size, so the renderer can reserve a gap in the line and paint the image over it. The host owns the (cached, off-thread) render;Nonewhile it’s still rasterizing (the raw$…$shows until then). Set viaMarkdownView::on_inline_math. - Math
Renderer - Renders a
$$…$$math block as a typeset image, given the block’s LaTeX. LikeMermaidRenderer, the host owns the (cached, off-thread) render — this crate just detects the block and hands over the source. Set viaMarkdownView::on_math. - Mermaid
Renderer - Renders a
```mermaidcode block as a diagram, given the block’s source. The host owns the (expensive, async) render — this crate just detects the fence and hands the source over, staying renderer-agnostic. Set viaMarkdownView::on_mermaid. - Property
Icon Fn - Maps a property key to an icon asset path the host serves, or
Nonefor no icon. Host-provided so the crate makes no assumption about which assets exist. - Task
Toggle Handler - Toggle the task checkbox of a clicked list item — the argument is the source
byte offset of that task item (feed it to
toggle_task_at). Set viaMarkdownView::on_task_toggle. - Wiki
Link Handler - Called when a
[[wiki-link]]is clicked, with the trimmed title.