Expand description
mdwire — safely deliver agent-generated Markdown to chat channels.
It does three things in one pipeline. The order is the design.
- Normalize — LLM output is not valid CommonMark. Unbalanced emphasis, emphasis that spans lines, and unclosed code fences are routine. Repair them first.
- Render for the channel — translate into the syntax the target accepts. Syntax the
target cannot accept is not worth parsing in the first place (see the
Channeldocs below). - Split safely — at channel limits and streaming boundaries, never cut through markup.
§Why no dependencies
Existing parsers are all batch parsers — they take the whole document, build an AST, then render. That does not fit a problem where output must go out as tokens stream in. And the CJK-adjacent emphasis policy is baked into the parser, so with someone else’s parser you cannot change it. That is exactly the problem this library sets out to fix.
Modules§
- width
- Display width — the number of cells a character takes in a monospace font.
Structs§
- Html
Options - The browser channel’s policy. The defaults are the most conservative —
<br>line breaks, images as links only, and onlyhttp,https, andmailtolinks. - Options
- Conversion options — the part limit and the browser channel’s policy.
- Rendered
- The result of
render_with— the parts and the repairs. - Repairs
- Counts of what normalization repaired and what was changed to fit the channel. The first four
(repairs) measure how often the model breaks formatting; the last six (changes) measure
what a channel changes, before adopting it — to ask about each separately, use
Repairs::anyandRepairs::changed. - Streamer
- Streaming converter.
Enums§
- Channel
- Target channel. Each channel accepts a different syntax, and the narrower output decides the parsing scope.
- Images
- How to emit an image
. - Line
Breaks - How to emit line breaks inside a block.
Constants§
- MIN_
LIMIT - The smallest part limit a caller can set.
Functions§
- render
- Converts a finished document in one go. Splits at safe points when it exceeds the limit.
- render_
with renderwith options; also returns what normalization repaired.