Pipeline
- Parse Markdown into IR (
markdownToIR) - plain text plus style spans (bold, italic, strikethrough, code, code block, spoiler, blockquote, heading 1-6) and link spans. Offsets are UTF-16 code units so Signal style ranges align with its API directly. Tables parse only when the channel opts into a table mode. - Chunk the IR (
chunkMarkdownIR/renderMarkdownIRChunksWithinLimit)- style and link spans are sliced with the text. The rendered-size chunker measures each candidate after channel escaping and link rewriting, and returns the accepted source slice together with its rendered payload.
- Render per channel (
renderMarkdownWithMarkers) - a style-marker map turns spans into the channel’s native markup.
IR example
Input Markdown:Table handling
markdown.tables controls how a channel converts Markdown tables, per
channel and optionally per account:
Inline code in table cells keeps its parsed content, including leading and
trailing spaces, in every enabled table mode.
Per-channel plugin defaults: Matrix defaults to
block (native tables);
Mattermost defaults to off; Signal and WhatsApp default to bullets;
Telegram defaults to block (which resolves to code unless the account
has richMessages enabled). Any
channel without an explicit plugin default falls back to code.
Chunking rules
- Chunk limits come from channel adapters/config.
chunkMarkdownIRlimits IR text;renderMarkdownIRChunksWithinLimitmeasures the final payload in the transport’s size unit, including escaping and rewritten links. - Fenced code blocks are kept as one block with a trailing newline so channels render the closing fence correctly.
- List and blockquote prefixes are part of the IR text, so chunking never splits mid-prefix.
- Inline styles never split across chunks; the renderer reopens an open style at the start of the next chunk.
Link policy
- Slack:
[label](url)-><url|label>; bare URLs stay bare. - Telegram:
[label](url)-><a href="url">label</a>(HTML parse mode). - Signal:
[label](url)->label (url)unless the label already matches the URL.
Spoilers
Spoiler markers (||spoiler||) are parsed for Signal (mapped to SPOILER
style ranges) and Telegram (mapped to <tg-spoiler>). Other channels treat
||...|| as plain text.
Collapsible details
The Control UI and Telegram accounts withrichMessages: true render
<details><summary>Label</summary> disclosures as native collapsible sections.
OpenClaw tells the model about this option only when the current reply surface
supports it. Other channels, including Telegram accounts without rich messages,
flatten each disclosure to **Summary** followed by the visible body so no
content is hidden or lost.
Adding or updating a channel formatter
- Parse once with
markdownToIR(...), passing channel-appropriate options (autolink,headingStyle,blockquotePrefix,tableMode). - Render with
renderMarkdownWithMarkers(...)and a style-marker map (or custom style-range logic for transports like Signal). - Chunk with
chunkMarkdownIR(...)orrenderMarkdownIRChunksWithinLimit(...). The latter returns the measuredrenderedpayload; use it directly instead of rendering the source again. - Wire the adapter to call the new chunker and renderer from the outbound send path.
- Test with format tests plus an outbound delivery test if the channel chunks.
Common gotchas
- Slack angle-bracket tokens (
<@U123>,<#C123>,<https://...>) must survive escaping; raw HTML still needs to be escaped safely. - Telegram HTML requires escaping text outside tags to avoid broken markup.
- Signal style ranges use UTF-16 offsets, not code-point offsets.
- Preserve trailing newlines on fenced code blocks so the closing marker lands on its own line.
- Code-span parsing preserves all-space content. It removes one surrounding space from each end only when both are present and the content is not all spaces.
Related
Streaming and chunking
Outbound streaming behavior, chunk boundaries, and channel-specific delivery.
System prompt
What the model sees before the conversation, including injected workspace files.