vibe_chat_markdown
A safe Markdown reader for chat and AI replies. It returns plain data (blocks and spans), not widgets, so you can draw it with Flutter, turn it into HTML, or print plain text. It never shows raw Markdown markers.
It also has small helpers for text that mixes Arabic and English in one sentence.
Extracted from the Kayan assistant in the VIBE music player.
Install
dependencies:
vibe_chat_markdown: ^0.1.0
or dart pub add vibe_chat_markdown. It has no dependencies.
Platform support
Pure Dart. Works everywhere Dart runs, including the web.
Markdown
import 'package:vibe_chat_markdown/vibe_chat_markdown.dart';
final blocks = parseMarkdown('## Hi\n**Song** is *great*\n\n- one\n- two');
for (final block in blocks) {
switch (block) {
case MdHeading(:final level, :final spans): // draw a heading
case MdParagraph(:final spans): // spans carry bold, italic, code
case MdBulletList(:final items):
case MdNumberedList(:final items):
case MdTable(:final header, :final rows):
case MdCodeBlock(:final code):
case MdKeyValues(:final rows): // a reply that was only JSON
}
}
print(toPlainText(blocks)); // plain text, no markers
MdBlock is a sealed class, so the compiler tells you if a switch forgets a kind.
What it understands: headings (# to ######), paragraphs, **bold** / __bold__, *italic* / _italic_, `code`, bullet lists (-, *, +, •), numbered lists (1. or 1)), pipe tables, fenced code, and backslash escapes.
How it handles messy input:
- A malformed table becomes plain lines, never raw pipes.
- A reply that is only JSON becomes key and value rows, never raw braces.
- Unclosed markers stay as text.
snake_case_nameand2 * 3 * 4are left alone. - It never throws on odd input.
Mixed Arabic and English
import 'package:vibe_chat_markdown/bidi.dart';
isRtl('شغّل Shape of You'); // true: first strong letter is Arabic
isolateOppositeRuns('شغّل أغنية Shape of You الآن'); // keeps the English title in order
stripBidiMarks(text); // remove the marks again, for copying
isolateOppositeRuns wraps the runs that read the other way (titles, numbers, times, percentages) in Unicode isolates. Call it on one paragraph at a time.
What it does not do
- It is not full CommonMark. No links, images, block quotes, nested lists, HTML or horizontal rules.
- Only Arabic and Latin letters count as strong for
isRtl. Hebrew, Persian-only and other scripts are not detected. - Numbered lists drop the original numbers. Number the items yourself.
- Tested with unit tests and by comparing output with VIBE's own reader on 16 sample messages. Not tested on a large corpus of real model output.
License
MIT.
Libraries
- bidi
- Helpers for text that mixes Arabic and English (or digits) in one sentence.
- vibe_chat_markdown
- A safe Markdown reader for chat and AI replies. It returns plain data (blocks and spans), not widgets, so you can render it with Flutter, HTML, or plain text. It never shows raw Markdown markers.