pub struct MarkdownDocument { /* private fields */ }Expand description
A Markdown document parsed into MarkdownBlocks, which re-parses only what an edit
could have changed.
MarkdownDocument::update finds the first byte that differs from the source it holds,
goes back to the last top-level block boundary before it, and parses from there. For text
that grows at its end (a streamed reply) that is the block being written, whatever the
length of the document above it.
The grammar: paragraphs, ATX headings (# to ######), bullet lists (-, *, +) and
ordered lists (1., 1)) with nesting by indentation, block quotes (>), fenced code
(three or more backticks or tildes, with an optional language), and thematic breaks. A
fence left open runs to the end of the text, so code shows while it is still arriving.
Tables, setext headings, indented code, HTML blocks and reference links are read as
paragraph text.
Implementations§
Source§impl MarkdownDocument
impl MarkdownDocument
Sourcepub fn blocks(&self) -> &[MarkdownBlock]
pub fn blocks(&self) -> &[MarkdownBlock]
The blocks, in document order.
Sourcepub fn update(&mut self, source: &str) -> usize
pub fn update(&mut self, source: &str) -> usize
Replace the source and bring the blocks up to date, parsing only from the last top-level block boundary before the first changed byte.
Returns the index of the first block that differs from before the call: every block below it is untouched, and it equals the new block count when nothing changed.