Repository navigation
feat(render): bullets, task boxes, quote bars and hanging indents from the parse - #152
Merged
Merged
Conversation
…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
force-pushed
the
feat/markdown-decoration
branch
from
November 15, 2026 17:46
a3eb5a9 to
223f001
Compare
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-markdownwrites its own-,1.,[x]and>into the output. For list and quote blocks only:decorate/syntax.rswalks 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).tui-markdownwrites it (*/+→-,1)→1.,[X]→[x], lazy1.→2.). Bytes are swapped in place, so offsets are unchanged.decorate.rsdecides, 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 thattui-markdownwrites 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.wrap/hang.rsrepeats 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.main. Nothing tracks fence state, so a```line inside a 4-backtick fence is just code.tui-markdownrendered it. This happens with lazy numbering that changes digit count, such as8.rendered as10..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 checkswidth_cjk() == 1for 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.
originalTextacross a decorated bullet is nowlogin page writeinstead oflogin 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:--annotatewith a quote across two items, one spanning a hanging-indent wrap, and a task item. For each,source[start..end]must equal the quote, andoriginalTextmust 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 againstmain)samples/big.md(2.5 MB, 516 list lines)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) andpython3 herdr/test-manifest.py, on macOS. I also compared--snapshotofsamples/, a slice ofbig.md, #135's CJK sample and an edge-case file withmain.Known limits, unchanged from
maintui-markdownjoins lines of a fenced block nested in a list item when the block contains a shorter fence.originalText(line second).Co-authored-by: Manho [email protected]