Expand description
CommonMark and GitHub Flavored Markdown highlighter and interactive hook.
Lives at src/batteries/markdown/; this shim keeps the public path
twrite_core::markdown stable regardless of file layout.
CommonMark and GitHub Flavored Markdown battery: highlighter and interactive hook.
The battery is split into focused modules (promoted from a single
batteries/markdown.rs once it outgrew one file, per the registry
contract in crate::batteries):
- [
config]:MarkdownConfig/ConcealModeshared settings. - [
table]: GFM pipe-table detection (blocks, pipes, delimiter rows). - [
highlight]:MarkdownHighlighter(SyntaxHighlighterimpl). hook:MarkdownHook(EditorHookimpl: shortcuts, lists, tables).- [
links]: single-line hyperlink extraction shared by highlighting and click handling.
Everything here is built only on the public core API (SyntaxHighlighter,
EditorHook, HighlightTag, ConcealedLine, …) and emits only existing
HighlightTag variants plus Custom("markdown.table.*") names, so no
twrite-gpui-side code is required.
Structs§
- Markdown
Config - Configuration settings for Markdown editing, highlighting, and WYSIWYG rendering.
- Markdown
Highlighter - A syntax highlighter for CommonMark and GFM Markdown documents using
pulldown-cmark. - Markdown
Hook - An editor hook providing Markdown shortcuts (Ctrl+B, Ctrl+I, Ctrl+K), smart list continuation, and task list toggles.
- Table
Block - A contiguous GFM pipe-table block: header + delimiter + 0..N body rows.
- Table
Layout - Display-column widths for one
TableBlock, measured on unconcealed source cell content so widths stay stable as the cursor moves (inactive rows conceal markers; per-row padding absorbs the difference and pipes still align everywhere).
Enums§
- Conceal
Mode - Display mode for markdown syntax delimiters (like
#,**,*,~~,`) on inactive lines. - Table
Alignment - Column alignment parsed from a GFM delimiter cell (
---,:--,--:,:-:). - Table
RowKind - Which row of a
TableBlocka buffer row is.
Constants§
- TABLE_
CELL_ TAG - Custom tag for GFM table body cell content.
- TABLE_
DELIMITER_ TAG - Custom tag for GFM table delimiter rows (
| --- | :-: |). - TABLE_
HEADER_ TAG - Custom highlight tag names emitted for GFM tables.
Functions§
- extract_
markdown_ links - Extracts all markdown hyperlink destinations and their label character ranges from a single line.
- fence_
rows - Collects every fence-marker row in a single linear pass.
- find_
unescaped_ pipes - Byte offsets of cell-separator pipes in
line. - is_
fenced_ row - Returns whether
rowsits inside a fenced code block. - parse_
delimiter_ row - Parses a GFM delimiter row into per-column alignments.
- split_
table_ cells - Splits
lineinto cell-content byte ranges plus separator pipe offsets. - table_
block_ at - Locates the GFM pipe-table block containing
row, if any. - table_
block_ at_ with_ fences table_block_atwith a caller-provided fence index.- table_
layouts - Finds every table block in the buffer with its measured
TableLayout. - table_
layouts_ with_ fences table_layoutswith a caller-provided fence index.