Expand description
A lean, line-level markdown styler shared by surfaces that want to style markdown without editing it (currently the Ask workspace’s answer body).
Design constraints that shape it:
- Emphasis sigils are hidden; structural markers stay. Balanced
**/__(bold) and*/_(italic) delimiters are dropped from the rendered text (the run between them is styled instead), matching what a reader expects. Everything else stays visible:#headings,>quotes, fences, list markers, and citation[n]markers. Because hiding breaks the old 1:1 byte↔column identity,style_slice_mappedemits, alongside the styled line, a column map (rendered char index → source byte offset) so callers can still hit-test a click back to the right source byte. (This is why we don’t reuse the editor’sParsedBuffer, which fully re-lays-out the visual line.) - Only same-line, balanced pairs are hidden. A sigil is hidden only when
an opener and a closer of the same kind appear in the same wrapped slice
(the per-slice approximation — we never look across the wrap boundary). A
lone
*(an unmatched sigil, a bullet, arithmetic) stays visible and does not emphasize anything. Sigils inside inline code are literal. - Intraword
_is not emphasis. Following CommonMark, a_/__run may open only when the char before it is absent/non-alphanumeric and close only when the char after it is — sosnake_caseandfoo_bar_bazidentifiers render verbatim.*/**keep the laxer rule (intraword*is legal). - Citations are the citations module’s job.
[n]markers are found only throughcrate::ask::citations::scan; we merely style the ranges it reports. Code (fenced blocks and inline spans) is never citation-styled.
The unit of work is one logical source line, split across two layers:
- Block identity is not ours to decide.
classify_block_kindshands the whole answer to the editor’s buffer-aware markdown model (crate::components::text_editor::markdown::ParsedBuffer, the real pulldown-cmark classifier) and maps each row’s result onto aLineKind. There is exactly one opinion about what a line is, and it is the editor’s — so answers and the note editor never disagree, and cross-line constructs the model resolves natively (unclosed fences, setext underlines, lazily-continued blockquotes) come along for free. - Inline styling stays here.
style_slice_mappedstyles one wrapped visual slice of a line (given itsLineKind) and returns its column map — this is the answer-domain layer (emphasis hiding, citation styling,col_map) the editor’s fully-relaidParsedBufferrender can’t provide.
Structs§
- MdStyles
- The semantic styles the answer body renders with, resolved from the theme once per render and reused across every line.
Enums§
- Line
Kind - The block role of one logical source line.
Functions§
- classify_
block_ kinds - Classify the block role of every logical (newline-free) source
lineinlines, in order, by delegating wholesale to the editor’s markdown model (ParsedBuffer::parse) — so there is a single, buffer-aware opinion about block identity shared with the note editor. - style_
slice_ mapped - Style one wrapped visual
sliceof a logical line whose block role iskind, returning the styledLineand its column map:map[k]is the source byte offset (intoslice) of thek-th rendered character.