Skip to content

feat(render): bullets, task boxes, quote bars and hanging indents from the parse - #152

Merged
backnotprop merged 1 commit into
mainfrom
feat/markdown-decoration
Nov 15, 2026
Merged

backnotprop merged 1 commit into
mainfrom
feat/markdown-decoration

Conversation

@backnotprop

Copy link
Copy Markdown
Contributor

Lists and quotes get bullets, task boxes, quote bars and hanging indents, and thematic breaks are drawn across the width. The idea and the first version come from @Manho in #135. This PR rebuilds it so that every decision comes from the parse, never from the rendered glyphs.

How it works

tui-markdown writes its own - , 1. , [x] and > into the output. For list and quote blocks only:

  1. decorate/syntax.rs walks the block's pulldown-cmark events once. It records the quote and item containers with their source ranges, each item's marker bytes, number and task box, and the leaf ranges (text, code, HTML, math).
  2. Alignment runs against the source with each marker spelled the way tui-markdown writes it (*/+ → -, 1) → 1., [X] → [x], lazy 1. → 2.). Bytes are swapped in place, so offsets are unchanged.
  3. decorate.rs decides, for each rendered line, how much of the start is container syntax. A character counts only when its aligned source byte is an item marker, a task box, or a > outside every leaf. Whitespace counts when it is outside every leaf. The quote prefix that tui-markdown writes counts too, up to one character per quote around the line, even where the diff left it unmapped. That run is replaced by a prefix built from the containers around the line's text: a bar per quote, then each item's marker on its first line and blank space of the same width after that. The new prefix maps to no source byte.
  4. wrap/hang.rs repeats the blank-and-bar prefix on wrapped rows. It is told the prefix length and does not look at characters.

As a result:

  • \- on a continuation line, \> and > at a quote line start, and - © all stay literal.
  • Code fences stay visible, exactly as on main. Nothing tracks fence state, so a ``` line inside a 4-backtick fence is just code.
  • A second paragraph or a code block inside a list item now gets the item's indent.
  • If a line's rendered marker can't be matched to its source marker, the line is left as tui-markdown rendered it. This happens with lazy numbering that changes digit count, such as 8. rendered as 10..

Glyphs and width

∙ ◦ ▪ for bullets by depth, ☐ ☑ for task boxes, ╎ for the quote bar, and ╌ for rules. All of them are East Asian Neutral, so they stay one column wide where Ambiguous glyphs are drawn wide. A test checks width_cjk() == 1 for each. The app has no ambiguous-width setting, so I chose glyphs that don't depend on one, instead of #135's • │ ─.

Anchoring

Notes still anchor to exact source bytes. originalText across a decorated bullet is now login page write instead of login page - [ ] write, which matches what the web client's DOM shows. Resolution is quote-first against the source, so existing notes are unaffected.

New tests:

  • tests/decorated_anchors.rs: --annotate with a quote across two items, one spanning a hanging-indent wrap, and a task item. For each, source[start..end] must equal the quote, and originalText must have no glyphs.
  • app/tests.rs: a mouse drag across a hanging row, starting in the indent, selects exactly that row's text.
  • decorate/tests.rs: nesting, task boxes, quote bars, escapes and entities, nested fences, hang offsets, rule width, and rendered text.

Bench (--bench, release, 5 interleaved runs against main)

file main render+align+wrap this PR reflow
samples/big.md (2.5 MB, 516 list lines) 286–310 ms 283–340 ms overlapping (54–78 vs 53–88 ms)
780 KB of nothing but lists and quotes 48–52 ms 67–73 ms +5–10%

Rendering runs once per block and is cached. The extra cost is one pulldown-cmark pass per list or quote block, plus rebuilding those lines. Row counts are unchanged on both files.

Checks

cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace (626 passed, 14 new) and python3 herdr/test-manifest.py, on macOS. I also compared --snapshot of samples/, a slice of big.md, #135's CJK sample and an edge-case file with main.

Known limits, unchanged from main

  • tui-markdown joins lines of a fenced block nested in a list item when the block contains a shorter fence.
  • A soft break inside a quote gives a double space in originalText (line second).

Co-authored-by: Manho [email protected]

…m the parse

tui-markdown leaves `- `, `1. `, `[x] ` and `>` in its output. List and
quote blocks now replace that leading syntax with a prefix built from the
pulldown-cmark containers around each line: a bar per quote, then the
item's marker on its first line and blank space of the same width after.
Which rendered characters are syntax is decided by their aligned source
bytes (item marker, task box, or a `>` outside any text), never by the
glyphs, so escaped and entity text stays literal and code fences, kept
visible, cannot flip any state. Wrapped rows repeat the prefix.

Thematic breaks are drawn across the width. Every glyph is East Asian
Neutral, so rows keep their width where ambiguous glyphs are drawn wide.

Co-authored-by: Manho <[email protected]>
@backnotprop
backnotprop force-pushed the feat/markdown-decoration branch from a3eb5a9 to 223f001 Compare November 15, 2026 17:46
@backnotprop
backnotprop added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 27c28cf Nov 15, 2026
3 checks passed
@backnotprop
backnotprop deleted the feat/markdown-decoration branch November 15, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant