IncrementalMarkdownParser class

Parses Markdown incrementally, as it is streamed in chunks.

Feed text with append in chunks of any size (even one character, or splitting a code fence, a \r\n or a surrogate pair) and read the current document at any time. Each append does work proportional to the new text plus the single still-open block; blocks that have been closed are never parsed again and keep their object identity across snapshots.

The parser is independent of Flutter, so it can be used from plain Dart.

final parser = IncrementalMarkdownParser();
parser.append('# Hi\n\nSome **bo');
print(parser.document.blocks); // [Heading1, Paragraph(open)]
parser.complete();

The guarantee tested for this class: for every way of splitting an input into chunks, document after the last chunk equals the document produced by appending the whole input at once.

Constructors

IncrementalMarkdownParser({MarkdownParserOptions options = const MarkdownParserOptions()})
Creates a parser with the given options.

Properties

debugInlineParseCount → int
How many times inline content has been parsed so far.
no setter
document → MarkdownDocument
The current snapshot of the document.
no setter
hashCode → int
The hash code for this object.
no setterinherited
isComplete → bool
Whether complete has been called.
no setter
options → MarkdownParserOptions
The parser options in effect.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

append(String chunk) → void
Appends chunk of Markdown.
complete() → void
Marks the input as finished: the last line is processed and every open block is closed (an unterminated code fence simply ends).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Discards all state so the parser can be reused for a new document.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

parse(String markdown, {MarkdownParserOptions options = const MarkdownParserOptions()}) → MarkdownDocument
Parses a complete markdown string in one go.