parser library
The text side of llm_markdown, without widgets: incremental parsing,
healing of unfinished Markdown, plain text and <think> splitting.
This is package:llm_markdown_parser, which is pure Dart. Depend on
that package directly on a server or in a CLI; from a Flutter app this
import gives the same thing.
Classes
- AlertSyntax
- CitationSyntax
- DetailsBlockSyntax
- FrozenBlock
- A finished block: its text no longer changes, so it is parsed once.
- HighlightSyntax
- IncrementalMarkdownParser
- Parses Markdown that grows at the end, such as a streamed AI reply.
- InlineMathSyntax
- MarkdownSyntax
- Which Markdown extensions are recognized, beyond GitHub-flavored Markdown.
- MathBlockSyntax
- SafeHtmlSyntax
- SchemeAutolinkSyntax
- ServerSentEvent
- One event of a server-sent events (SSE) stream.
- SpoilerSyntax
- ThinkingSplit
- The thinking part and the answer of a reply.
Constants
- blockMathTag → const String
- citationTag → const String
- detailsTag → const String
- inlineMathTag → const String
- spoilerTag → const String
Properties
- detailsCloser → RegExp
-
final
- detailsOpener → RegExp
-
final
Functions
-
findBlockBoundaries(
String text, int start, {required bool complete, bool dollarMath = true}) → List< int> -
healIncompleteMarkdown(
String source, {bool dollarMath = true}) → String -
Returns
sourcechanged so that its unfinished end renders cleanly. -
isBlank(
String text) → bool -
markdownToPlainText(
String markdown) → String -
Returns
markdownas plain text, for example to copy a reply into an app that doesn't understand Markdown. -
mathOpenerFor(
{required bool dollar}) → RegExp -
newMarkdownDocument(
[MarkdownSyntax syntax = const MarkdownSyntax()]) → Document -
A
package:markdowndocument with GitHub-flavored Markdown and the extensions turned on insyntax, asStreamingMarkdownparses it. -
serverSentEvents(
Stream< List< bytes) → Stream<int> >ServerSentEvent> - Splits the raw bytes of an HTTP response body into server-sent events.
-
splitThinking(
String text, {required bool complete}) → ThinkingSplit -
Splits the
<think>...</think>part that models such as DeepSeek R1 and Qwen put at the start of a reply off the answer. -
texToUnicode(
String tex) → String -
A readable plain-text version of simple TeX, for when no math renderer
is plugged in:
\alphabecomes α,x^2x² and\frac{a}{b}a/b.
Exceptions / Errors
- ModelStreamError
- Error from a model API, sent inside its event stream.