Markdown pipeline
Shared primitives — markdown pipeline
Everything between the .md bytes on disk and the op log: parsing, rendering, external-markdown coercion and ingest, reconcile / matching / diff, the .outl sidecar.
Plus what reads that layer back — in-flight outline AST helpers, indices and search, inline tokenizers, editor view helpers, and asset links.
If a primitive reads or writes markdown, it lives here.
Part of the Shared primitives catalog — the index of every part lives in shared-primitives.md.
Before writing any helper, scan these tables first.
Most “I need a small string transform / id helper / md coercion / tree walk” needs already have an owner here —
the cost of finding the existing one is a grep;
the cost of missing it shows up later as drift between two parallel implementations (the user is the one who hits the divergence).
For the reuse-first rule (why this matters, past drift incidents, what to do when a primitive doesn’t exist yet), see Contributing → Reuse-first.
1. Parse / render (outl-md::parse + render)
| Intent | Use this | File |
|---|---|---|
Parse .md → outline AST (no IDs) | outl_md::parse::parse → ParsedPage (includes warnings: Vec<ParseWarning>) | crates/outl-md/src/parse.rs |
Render outline AST → .md (clean, no IDs) | outl_md::render::render | crates/outl-md/src/render.rs |
| Non-fatal parser recovery records (heading instead of bullet, etc.) | outl_md::ParseWarning + outl_md::ParseWarningKind (re-exported from parse) | crates/outl-md/src/ast.rs |
The outline AST node DTO (UI-friendly, no Workspace coupling) | outl_md::OutlineNode / outl_actions::outline::OutlineNode | crates/outl-md/src/ast.rs + crates/outl-actions/src/outline.rs |
Read one key:: value line (page property or block property) — never hand-roll the :: split, both positions share this reader | outl_md::parse::parse_property_line (re-exported from property) | crates/outl-md/src/property.rs |
| Project the workspace tree under a node into the UI DTO | outl_actions::outline::project_outline / project_outline_node | crates/outl-actions/src/outline.rs |
Project a parsed subtree (.md AST, no sidecar) into wire OutlineNodes with tokens attached — ids are transient (fresh per call), for read-only surfaces that re-resolve on navigation (the !((blk)) embed subtree expansion) | outl_actions::outline::project_parsed_subtree (re-exported outl_actions::project_parsed_subtree) | crates/outl-actions/src/outline.rs |
Flatten an OutlineNode subtree to DFS paths (no production caller since the TUI’s backlink selection dropped its subtree walk; kept with its own tests) | outl_actions::outline::flatten_subtree_paths | crates/outl-actions/src/outline.rs |
| Read a page from disk + project to outline view in one call | outl_actions::outline::read_page_view / read_page_view_with_workspace | crates/outl-actions/src/outline.rs |
| Read a page and surface parser warnings (banner, doctor, status line) | outl_actions::outline::read_page_outline / read_page_outline_with_workspace → PageOutline { nodes, warnings, sidecar_identity } | crates/outl-actions/src/outline.rs |
Does the sidecar an outline was built through name that page’s root? Rides every PageOutline as sidecar_identity, off the sidecar the read already parsed — no Workspace, no extra I/O. It reports and never refuses: this is the page-open path of every client, and build_backlink_index_from_disk skips a page whose read errors, so an Err here would take the refs of 1,775 pages out of the backlinks panel the mismatch was reported from. Flag any caller that turns NamesAnotherPage into an error or a skip | outl_actions::outline::SidecarIdentity (re-exported outl_actions::SidecarIdentity) | crates/outl-actions/src/outline/sidecar.rs |
Read a block’s text as a table (cells + per-column alignment), None unless the whole text is one | outl_md::table::parse_table → Table / ColumnAlign | crates/outl-md/src/table.rs |
| Does a table start at this line? (what lets the parser claim pasted rows as one block instead of one per row) | outl_md::table::table_span / is_delimiter_row | crates/outl-md/src/table.rs |
| Write a table back as canonical markdown, every column padded to its widest cell — for where outl creates one (a tabular paste, the TUI’s grid), never to reformat what the user typed | outl_md::table::render_table | crates/outl-md/src/table.rs |
Split one table row into cells (escape-aware: | splits nothing), or resolve a cell for display (| → ` | `) | outl_md::table::split_cells / unescape_cell |
Slugify a user-visible page name into a filesystem-safe slug (NFC, lowercase, folds Latin diacritics á → a, keeps every other letter or digit so [[你好]] is pages/你好.md, non-alphanumerics collapse to -; capped at MAX_SLUG_BYTES with a digest suffix; empty input → UNTITLED_SLUG) — never hand-roll an ASCII-only copy | outl_md::slug::slugify / UNTITLED_SLUG / MAX_SLUG_BYTES | crates/outl-md/src/slug.rs |
2. External markdown coercion & ingest (outl-md::frontmatter + wikilink, outl-actions::paste + ingest)
| Intent | Use this | File |
|---|---|---|
| Tab-separated clipboard text → a markdown table, and the owner of the “is this tabular” gate both runtimes answer from | outl_md::table::tsv_to_markdown / from_delimited | crates/outl-md/src/table.rs |
| Does a payload carry structure the paste pipeline will act on (an outline, a markdown table, tabular data)? The one predicate a client asks before paying for a round trip | outl_actions::paste::looks_structured (and looks_like_table / looks_like_tabular) | crates/outl-actions/src/paste/detect.rs |
Coerce external markdown (line endings, indent unit 4→2, Roam/GitHub/Logseq tokens, long-form dates → ISO, strip id:: with Crockford validation, strip unknown {{…}} / ^^…^^) | outl_actions::paste::normalize_external_syntax | crates/outl-actions/src/paste/normalize.rs |
Split a leading --- YAML frontmatter fence off a .md body (CRLF-safe, honours ... end marker, no-fence → verbatim body) | outl_md::frontmatter::split_frontmatter | crates/outl-md/src/frontmatter.rs |
Parse a YAML frontmatter block into flat key:: value properties (title lifted, tags normalized to #name, caller-supplied drop-list; values verbatim — date normalization stays with the caller) | outl_md::frontmatter::parse_frontmatter → Frontmatter | crates/outl-md/src/frontmatter.rs |
Lift a leading # H1 line into a page title (first non-blank line only) | outl_md::frontmatter::extract_leading_h1 | crates/outl-md/src/frontmatter.rs |
Split a leading --- YAML frontmatter fence off a .md body, plus the number of source lines it occupied — what parse needs to keep ParseWarning::line file-relative | outl_md::frontmatter::split_frontmatter_counted | crates/outl-md/src/frontmatter.rs |
How many leading lines a well-formed --- fence occupies (0 when there is none) — allocation-free, for a caller that only needs to skip the region | outl_md::frontmatter::frontmatter_line_count | crates/outl-md/src/frontmatter.rs |
Render a frontmatter body back to its fenced form (the inverse of split_frontmatter; a ... closer normalizes to ---) | outl_md::frontmatter::render_frontmatter | crates/outl-md/src/frontmatter.rs |
The page-property key that carries a page’s verbatim frontmatter through the op log (Op::SetProp on the page root), so a projection from the tree re-emits the fence instead of deleting it — issue #281 | outl_md::frontmatter::PAGE_FRONTMATTER_KEY | crates/outl-md/src/frontmatter.rs |
Parse a markdown fragment (clipboard text, a pasted subtree) where a leading --- is content, not page metadata — parse would split it off as frontmatter | outl_md::parse::parse_fragment | crates/outl-md/src/parse.rs |
Collapse external wiki-link variants ([[Note|alias]], [[Note#h]], [[Note^blk]], [[folder/Note]]) to canonical [[Note]] | outl_md::wikilink::rewrite_wikilinks (whole text) / clean_wikilink_target (one target) | crates/outl-md/src/wikilink.rs |
Convert image wiki-links / embeds (![[img.png]], [[a/b.jpeg|cap]]) into CommonMark links, folder path preserved | outl_md::wikilink::convert_image_links (+ is_image_target predicate) | crates/outl-md/src/wikilink.rs |
| “Does this clipboard look like an outline?” classifier | outl_actions::paste::looks_like_outline | crates/outl-actions/src/paste/detect.rs |
| Convert clipboard markdown into outl ops grafted at a position | outl_actions::paste::paste_markdown → PasteOutcome (anchor described by PasteAnchor) | crates/outl-actions/src/paste/mod.rs |
| Paste raw text as a single block with no normalisation or outline parsing (the “without formatting” path) | outl_actions::paste::paste_plain(workspace, hlc, anchor, raw) → PasteOutcome | crates/outl-actions/src/paste/mod.rs |
Serialize a block selection (+ subtrees) to clean outl markdown for the clipboard (the inverse of paste_markdown / parse) | outl_actions::clipboard::copy_markdown (workspace + NodeIds; GUI backends) / copy_markdown_nodes (already-projected OutlineNodes; the TUI’s AST-first yank) | crates/outl-actions/src/clipboard.rs |
3. Reconcile & matching (outl-md::reconcile + matching + diff)
| Intent | Use this | File |
|---|---|---|
Reconcile an existing .md against its sidecar (3-level matching → diff → min ops) | outl_md::reconcile::reconcile_md (no sidecar = fresh random id) / reconcile_md_with_page_id (pin id for first ingest) | crates/outl-md/src/reconcile.rs |
Same reconcile, with an explicit orphan-volume policy — reconcile_md delegates here with OrphanGuard::Enforced; pass OrphanGuard::Disabled only from a confirmed user opt-in (outl reconcile --allow-bulk-delete) | outl_md::reconcile::reconcile_md_with_guard | crates/outl-md/src/reconcile.rs |
Content lines a .md holds that no block the op log knows can account for — the single owner of “does the log know this line”, asked by reconcile_md before advancing last_synced_hash (invariant 8), by outl_actions::apply_page_md_with_sidecar_if_stale before re-projecting, and by outl doctor’s read-only listing. Re-exported at outl_actions::content_lines_missing_from | outl_md::unlogged::content_lines_missing_from | crates/outl-md/src/unlogged.rs |
| The same verdict from block texts alone, for the one caller whose reference is a render and not a sidecar. Byte-identical result; it exists so the survey stops minting a throwaway ULID + SHA-256 per block on every sweep | outl_md::unlogged::content_lines_missing_from_texts | crates/outl-md/src/unlogged.rs |
Would writing this render over this .md delete the page’s YAML frontmatter fence? The second channel of the same “does the log know this” question — the fence rides Op::SetProp, so a block list cannot answer for it and content_lines_missing_from skips it. Narrow on purpose: a differing fence is a peer edit, not a loss | outl_md::unlogged::frontmatter_lines_missing_from | crates/outl-md/src/unlogged.rs |
Whether a sidecar’s blocks can answer the question above at all — false for a pre-0.11 sidecar whose entries all carry text: ""; an empty verdict from a reference that cannot answer is not “nothing at risk”. Re-exported at outl_actions::sidecar_can_answer | outl_md::unlogged::sidecar_can_answer | crates/outl-md/src/unlogged.rs |
Can this sidecar vouch for the .md on disk: the sidecar-capability gate every write path asks before the content checks. Not the whole verdict on its own: it returns true for any answerable sidecar, even over text the log never saw, so a writer must still refuse when content_lines_missing_from returns a non-empty line and when frontmatter_lines_missing_from is non-zero (journal::guard’s unlogged_content_error / frontmatter_loss_error phrase both). sidecar_can_answer is one arm of it; the other asks whether the file holds anything needing vouching for, since an all-empty sidecar is also what a page nobody has written in yet looks like (#332). Re-exported at outl_actions::sidecar_can_vouch_for | outl_md::unlogged::sidecar_can_vouch_for | crates/outl-md/src/unlogged.rs |
Reconcile every .md in a directory | outl_md::reconcile::reconcile_dir | crates/outl-md/src/reconcile.rs |
Materialise a page root in the tree (Op::Create at root + page-slug / page-kind SetProps, idempotent) without running the full reconcile pipeline | outl_md::reconcile::ensure_page_root_in_tree | crates/outl-md/src/reconcile/page_root.rs |
| Reconcile error / report types | outl_md::ReconcileError / ReconcileReport | crates/outl-md/src/reconcile/outcome.rs |
3-level matching algorithm (hash → positional fallback → similarity → orphan log); level 2 diffs SidecarBlock::text with normalized Levenshtein > 0.8 and preserves id + ref_handle | outl_md::matching::match_blocks → Match / MatchLevel | crates/outl-md/src/matching.rs |
Same matching, with the volume of the resulting deletion checked before the caller can act on it. Use this wherever orphans become Move(node, TRASH_ROOT): match_blocks alone treats 1 orphan and 5,000 identically, so a truncated .md (iCloud placeholder, half-flushed write) empties a page as quietly as deleting one bullet. Refusal is an Err over the whole pass — never a shortened orphan list | outl_md::matching::guard::match_blocks_guarded → MatchGuardError | crates/outl-md/src/matching/guard.rs |
The thresholds that refusal uses, and the explicit opt-out a caller wires to a user-facing flag (OrphanGuard::Disabled, reached by outl reconcile --allow-bulk-delete). Defaults: MAX_ORPHANED_BLOCKS = 500 absolute, MAX_ORPHANED_RATIO = 0.75 of the page, ratio ignored under RATIO_FLOOR_BLOCKS = 20 known blocks | outl_md::matching::guard::{OrphanGuard, OrphanVolume} | crates/outl-md/src/matching/guard.rs |
Diff old AST + new AST + old sidecar → minimum sequence of Ops | outl_md::diff::diff_to_ops → DiffPlan | crates/outl-md/src/diff.rs |
Same diff, plus propagate page-level properties (title::, type::, pinned::, icon::, …) into the op log as Op::SetProp on the page root so the CRDT tree agrees with what’s on disk (legacy .md files populated via fixtures / external editors get materialised here on the next reconcile) | outl_md::diff::diff_to_ops_with_page_props | crates/outl-md/src/diff.rs |
Reconcile-pipeline version number stamped on every sidecar — orphan scanner re-runs reconcile_md when a sidecar’s version is below this constant, so a binary that gains a new pipeline pass automatically rematerialises every legacy page on the next boot | outl_md::sidecar::CURRENT_PIPELINE_VERSION | crates/outl-md/src/sidecar/payload.rs |
4. Sidecar (outl-md::sidecar + atomic)
| Intent | Use this | File |
|---|---|---|
| The full sidecar struct + per-block entries | outl_md::Sidecar / SidecarBlock | crates/outl-md/src/sidecar/payload.rs |
| Construct a fresh sidecar for a new page | outl_md::sidecar::Sidecar::new_for_page(page_id, &file_hash) | crates/outl-md/src/sidecar/payload.rs |
Build one sidecar block entry — the only way to build one unless you’re preserving an expanded ref_handle; keeps content_hash, ref_handle and the level-2 text derived from the same revision | outl_md::sidecar::SidecarBlock::from_text(id, line, indent, text) | crates/outl-md/src/sidecar/payload.rs |
Sidecar format version — currently 2. Feature-detect by field presence, never by version number: an additive #[serde(default)] field (text, pipeline_version) does NOT bump it, because a reader that doesn’t know the field still reads every field it does know correctly. Bump only when an existing field changes meaning or encoding — there, an older reader’s UnsupportedVersion is the desired outcome. Bumping for an additive field is what makes an already-shipped binary reject the file, rebuild the sidecar from scratch, and duplicate every block | outl_md::sidecar::SIDECAR_VERSION / MIN_READABLE_SIDECAR_VERSION | crates/outl-md/src/sidecar/payload.rs |
Read / write sidecar (JSON, writes SIDECAR_VERSION = 2, backward-reads v1) | outl_md::sidecar::read / write | crates/outl-md/src/sidecar.rs |
Sidecar read / write failure — UnsupportedVersion is a refusal, not corruption: a newer peer wrote the file, so reconcile_md propagates it instead of rebuilding the page with fresh ids | outl_md::sidecar::SidecarError | crates/outl-md/src/sidecar/payload.rs |
Sidecar path resolution for a .md | outl_md::sidecar::sidecar_path_for / resolve_sidecar_path | crates/outl-md/src/sidecar/paths.rs |
Derive ((blk-XXXXXX)) ref handle from NodeId (deterministic, collision-aware) | outl_md::sidecar::derive_ref_handle | crates/outl-md/src/sidecar/digest.rs |
Hash block / file content for sidecar (content_hash = single block; file_hash = whole .md) | outl_md::sidecar::content_hash / file_hash | crates/outl-md/src/sidecar/digest.rs |
Low-level crash-safe write (use the journal::write_md_atomic wrapper unless you have a reason) | outl_md::atomic::write_atomic | crates/outl-md/src/atomic.rs |
Read a .md you are about to mutate and write back (missing → empty, every other I/O error propagates) | outl_md::atomic::read_for_rewrite | crates/outl-md/src/atomic.rs |
Own a publish-by-rename scratch file so it is unlinked on every in-process exit — an early ?, a panic, a cancelled future — instead of on the one failure path someone remembered | outl_md::atomic::TempFile (new / path / keep) | crates/outl-md/src/atomic.rs |
fsync a parent directory so a rename into it is durable (best-effort; Windows refuses to open a directory) | outl_md::atomic::sync_dir | crates/outl-md/src/atomic.rs |
Path of a workspace’s orphan log — every reconcile_md caller must pass this, never None. The one owner: outl_ws::layout::Paths::at derives its orphans field from it rather than re-joining the path | outl_actions::sync::orphans_log_path / SyncEngine::orphans_log | crates/outl-actions/src/sync.rs |
5. In-flight outline AST helpers (outl-md::outline_ops)
These operate on Vec<OutlineNode> before the tree is rebuilt from the op log — typing into a buffer that hasn’t been parsed back yet.
UI-agnostic; both TUI and mobile consume them.
| Intent | Use this | File |
|---|---|---|
| Flat count / TODO+DONE counts across an outline | outline_ops::flat_count / count_todos | crates/outl-md/src/outline_ops.rs |
| Convert flat index ↔ path / look up a node at a path | outline_ops::path_for_index / index_for_path / node_at_path / node_at_path_mut | crates/outl-md/src/outline_ops.rs |
| Count descendants under a path / grab a mutable siblings slice | outline_ops::descendants_count_at_path / siblings_mut | crates/outl-md/src/outline_ops.rs |
| Insert a sibling before / after a path | outline_ops::insert_sibling_before / outline_ops::insert_sibling_after | crates/outl-md/src/outline_ops.rs |
| Insert a sibling after a path, seeded with text (the TUI’s in-flight block-split: tail of the split goes into the new sibling) | outline_ops::insert_sibling_after_with_text | crates/outl-md/src/outline_ops.rs |
| Indent / outdent / delete / move up / move down at a path | outline_ops::indent_at_path / outdent_at_path / delete_at_path / move_up_at_path / move_down_at_path | crates/outl-md/src/outline_ops.rs |
6. Indices and search (outl-md::index + block_index)
| Intent | Use this | File |
|---|---|---|
| Build / query the workspace-wide index (slug → page, backlinks, block lookups) | outl_md::WorkspaceIndex::build / by_slug / by_title / pages / pages_by_title_prefix / pages_by_type | crates/outl-md/src/index.rs |
| Populate that index from the op-log tree instead of from disk (id-carrying nodes, no sidecar, cannot drop a block on a stale hash) | outl_md::IdentifiedNode + WorkspaceIndex::insert_page / collect_page_blocks_from_tree (per page) / collect_refs_from_indexed (once, after every page is in) | crates/outl-md/src/index.rs, block_index/ |
| Patch / remove a page in an existing index | WorkspaceIndex::patch_page / remove_page | crates/outl-md/src/index.rs |
Resolve ((blk-XXXXXX)) to a block / look a block up by id or location | WorkspaceIndex::resolve_block_ref / block_by_id / block_at_location | crates/outl-md/src/index.rs |
| Reverse refs to a block / iterate / search | WorkspaceIndex::block_refs_to / iter_blocks / search_block_text / block_count / block_index (borrow the inner BlockIndex) | crates/outl-md/src/index.rs |
| Stand-alone block-level index (when you don’t need the page facade) | outl_md::BlockIndex + BlockEntry + BlockReference | crates/outl-md/src/block_index/ |
PageEntry DTO returned by WorkspaceIndex lookups | outl_md::PageEntry | crates/outl-md/src/index.rs |
Split a comma-separated page-property value (alias::, and the template params:: list) into trimmed, non-empty entries — never hand-roll a second comma splitter | outl_md::parse_alias_list | crates/outl-md/src/index.rs |
7. View helpers for editors (outl-md::view + inline)
| Intent | Use this | File |
|---|---|---|
| Char ↔ (line, col) on a buffer (both TUI and mobile editors share) | outl_md::view::char_to_line_col / line_col_to_char | crates/outl-md/src/view.rs |
Project a block to renderable rows (with BlockRowKind discrimination) | outl_md::view::block_to_rows → BlockRow / BlockRowKind | crates/outl-md/src/view.rs |
Tokenize inline markdown (**bold**, [[refs]], #tags, ((blk-…)), !((blk-…)), ![[page]]) | outl_md::inline::tokenize → InlineTok | crates/outl-md/src/inline.rs |
Read a block as a table with every cell tokenized, for a client that renders from tokens (BlockNode.table) | outl_md::table::tokenize_table → TableView | crates/outl-md/src/table.rs |
| Tokenize inline markdown into an owned, Serde-friendly form for wire / DTO payloads (mobile renders these straight; no parallel TS tokenizer) | outl_md::inline::tokenize_owned → InlineToken | crates/outl-md/src/inline.rs |
Reconstruct the source markdown from a Vec<InlineTok> (Bold / Italic / Strike now carry recursively-tokenized inners; use this when a surface wants the whole inner span as one styled string instead of dispatching per-variant) | outl_md::inline::inline_to_source | crates/outl-md/src/inline.rs |
Resolve the ref under a caret position (Page / Journal / Tag / Block) | outl_md::inline::ref_at_cursor → RefTarget | crates/outl-md/src/cursor.rs |
Resolve the markdown link [text](url) under a caret position (anchor OR url) — the URL a client opens externally (TUI gx) | outl_md::inline::link_at_cursor → Option<&str> | crates/outl-md/src/cursor.rs |
Does a text mention #tag as a whole tag token? Boundary-correct via the tokenizer (#tag-longer / #tagged / #tag/sub never match tag; #tag inside a code span is not a tag) — never use text.contains("#tag") | outl_md::tag::text_contains_tag | crates/outl-md/src/tag.rs |
Same question, case-insensitive and answering for namespace children (#ops/deploy matches ops, #opsec does not). The ```query DSL’s tag: / not-tag: | outl_md::tag::text_contains_tag_or_child | crates/outl-md/src/tag.rs |
Validate a ((blk-XXXXXX)) handle string | outl_md::inline::is_valid_block_handle | crates/outl-md/src/reference.rs |
The ![[page]] page embed — the page-level twin of !((blk-…)), issue #190. try_page_embed sits in match_one ahead of both other ! openers (most specific wins) and ahead of try_md_link, or the ! strands and the [[name]] behind it reads as a plain ref. An image target is refused (![[photo.png]] stays Plain("!") + PageRef) so wikilink::convert_image_links keeps sole ownership of that spelling. It is a page reference, not an inert token: outl_actions::mentions collects its backlink and outl_actions::link_rewrite respells it on a rename, so both deliberately-exhaustive matches name it. inline_to_source re-emits the literal ![[name]], plain_text keeps the name and drops the punctuation, and ref_at_cursor resolves it to RefTarget::Page / Journal with the caret anywhere in the token, ! included | outl_md::InlineTok::PageEmbed { name } / owned InlineToken::PageEmbed { value } (serde "pageembed"); matcher outl_md::reference::try_page_embed | crates/outl-md/src/reference.rs, crates/outl-md/src/token.rs |
Flatten a block’s inline markup to the prose a human reads (notification bodies, a11y labels, plain-text export) — refs / tags keep their name, emphasis drops its markers, ((blk-…)) resolves to nothing | outl_md::plain_text (also outl_md::inline::plain_text) | crates/outl-md/src/plain.rs |
| Byte offset for a char index (UTF-8 safe) | outl_md::inline::byte_index_for_char | crates/outl-md/src/cursor.rs |
Canonicalize a fence info-string (rs → rust, js/javascript/node → js, …) — single source of truth for both outl-exec’s runtime dispatch and the frontend syntax highlighter | outl_md::lang::canonical, outl_md::lang::KNOWN_ALIASES | crates/outl-md/src/lang.rs |
Resolve a :shortcode: to its unicode glyph (one-way; never retro-translate glyph → shortcode, multiple shortcodes can alias the same codepoint) | outl_md::emoji::shortcode_to_unicode | crates/outl-md/src/emoji.rs |
Validate the [a-z0-9_+-]+ shape of an emoji shortcode (does not check the catalog — that’s shortcode_to_unicode) | outl_md::emoji::is_valid_shortcode | crates/outl-md/src/emoji.rs |
Validate one char of a shortcode ([a-z0-9_+-]) — use this when walking the buffer char-by-char (try_emoji, TUI’s detect_trigger) so you don’t allocate a 1-char String per keystroke just to call is_valid_shortcode | outl_md::emoji::is_valid_shortcode_char | crates/outl-md/src/emoji.rs |
Search the GitHub gemoji catalog for shortcodes matching a query (exact → prefix → substring; shorter shortcodes win ties) — powers the :emoji: autocomplete in every client through one shared outl_emoji_search Tauri command | outl_md::emoji::search → EmojiHit | crates/outl-md/src/emoji.rs |
8. Asset links (outl-md::asset + outl-actions::asset)
Uploaded files (PDFs, images) referenced from a block as [name](assets/<hash>.<ext>).
The bytes are not workspace state and never enter the op log; only the link does, as an ordinary Op::Edit.
| Intent | Use this | File |
|---|---|---|
| Directory name for uploaded assets, relative to the workspace root | outl_md::ASSETS_DIR | crates/outl-md/src/asset.rs |
| Content-hash an uploaded file’s bytes (hex SHA-256, used as the on-disk filename stem so identical uploads dedupe to one file) | outl_md::hash_bytes | crates/outl-md/src/asset.rs |
| Build the workspace-relative link target for a hash + extension | outl_md::asset_rel_path | crates/outl-md/src/asset.rs |
| Does a link target point at a workspace asset rather than an external URL? | outl_md::is_asset_link | crates/outl-md/src/asset.rs |
Is name a safe asset basename (<hash>.<ext>, no traversal)? The one owner of the anti-traversal check — the P2P transport validates every peer-sent name through it | outl_md::is_safe_asset_name | crates/outl-md/src/asset.rs |
Copy an uploaded file into <root>/assets/<hash>.<ext> and return the ready-to-insert markdown link (content-addressed, atomic tmp+rename, size-capped by [assets] max_bytes from outl-config); import_asset_bytes is the same for already-in-memory bytes (a remote image downloaded during a Roam import) | outl_actions::import_asset / outl_actions::import_asset_bytes → ImportedAsset | crates/outl-actions/src/asset.rs |
Resolve a [name](assets/…) link back to an on-disk path for “open outside outl” handlers (rejects traversal / external schemes via ActionError::InvalidAssetPath) | outl_actions::resolve_asset_path | crates/outl-actions/src/asset.rs |
9. Cross-runtime TS contracts (@outl/shared)
TS-side pieces that mirror a Rust canonical source above, so mobile and desktop consume the same file instead of drifting copies under each client’s own lib/.
Moved out of crates/outl-mobile/CLAUDE.md (that file was pinned near the per-crate CLAUDE.md size ceiling); this catalog is the one owner now.
| Intent | Use this | Mirrors (Rust) |
|---|---|---|
| Detect whether pasted plain text looks like an outline (drives paste-as-outline vs. paste-as-block) | looksLikeOutline (@outl/shared/paste) | outl_actions::paste::looks_like_outline |
Render inline markdown tokens to JSX; variant picks the ref/tag style (pill chips vs inline TUI-style text) and blockAssets decides whether an image may render as a block <img> (defaults to variant !== "inline", so compact contexts keep a chip; the desktop’s main BlockRow passes variant="inline" blockAssets) | <MarkdownInline variant? blockAssets? embeds? /> (@outl/shared/markdown) | outl_md::tokenize_owned (backend produces the tokens; the renderer is a discriminant-to-JSX switch) |
Render a block’s table as an HTML <table> (per-column alignment, horizontal scroll so a wide grid doesn’t stretch the outline, cells through <MarkdownInline />) | <MarkdownTable table variant? onEdit? /> (@outl/shared/markdown) | outl_md::tokenize_table (backend decides the grid; the renderer is a <tr>/<td> walk) |
Convert a clipboard <table> to a markdown table (Turndown ships no table rule) | tableElementToMarkdown (@outl/shared/paste) | TypeScript-only — HTML never reaches the Rust side |
| Detect a markdown table / tab-separated data in pasted plain text (gates the round trip) | looksLikeTable / looksLikeTabular (@outl/shared/paste) | outl_actions::paste::looks_like_table / looks_like_tabular |
Detect a [[ / (( / # / @ autocomplete trigger under the caret, plus the accept/insert helpers (autoClose/DeletePair, insertPair/Text, applySuggestion) | detectRefContext (@outl/shared/autocomplete) | outl_tui::actions::overlay::detect_trigger (the [[, (( and # triggers; the # alphabet on both sides is outl_md::reference::try_tag’s, so a popup never offers to complete past where the tokenizer ends a tag; TUI also covers /) |
Auto-pair (/[/{ and step over an auto-inserted closer; wired via onBeforeInput since iOS soft keyboards skip per-char keydown | autoPairBracket (@outl/shared/autocomplete) | outl_tui::input::insert (insert_pair) + EditBuffer::delete_pair_back |
Convert a textarea’s UTF-16 selectionStart to a codepoint offset before splicing text the backend expects in codepoints | utf16OffsetToCharOffset (@outl/shared/paste) | runtime gap, no Rust mirror — a supplementary-plane char otherwise shifts the splice |
Convert a codepoint offset from the backend back into the UTF-16 units setSelectionRange counts in | charOffsetToUtf16Offset (@outl/shared/paste) | the inverse of the row above; needed for PasteReply.host_caret |
| Decide what an editor becomes after a paste — the host block’s new text and the caret in it, or nothing when the paste left that block alone | pasteEditorUpdate (@outl/shared/paste) | reads outl_actions::PasteOutcome’s host_text / host_caret, never re-derived; issue #488 |
Decide what a gesture on a backlink row targets, what its reply may touch, and what to say when a create lands elsewhere — the (pageId, blockId) pair a cross-page mutation needs (null for an orphan row, which every client leaves inert), whether the returned PageView may be installed as the open page’s (only when the source page is the open one, which a page citing itself makes reachable) and the sentence after a create, since the new block cites nothing and so is a backlink of no page | backlinkEditTarget / backlinkCommitPlan / backlinkCreatedElsewhere (@outl/shared/backlink-edit) | no Rust mirror — the decisions are client-side. The strict write underneath is outl_tauri_shared::commands::backlink_edit::edit_backlink_block, and the TUI says its own terminal-shaped version in create_beside_a_backlink |
Write a Palette (from get_theme) onto <html> as --color-outl-* CSS custom properties, plus <body>’s inline background/foreground and color-scheme | applyPaletteToRoot (@outl/shared/theme) | no direct Rust mirror — it’s the sole writer of what outl_theme::Palette describes. Its color-scheme decision uses a local isLightHex copy, hand-synced against outl_theme::Palette::is_light() (crates/outl-theme/src/palette.rs) since a method can’t cross the Tauri wire — two implementations by design, not drift |
Adding a new cross-runtime contract = add it in @outl/shared from day one.
Never add it under a client’s own src/lib/ first — the next client to catch up on the feature has to consume from the same file.