{
  "title": "Markdown formatting",
  "content": "OpenClaw formats outbound Markdown by converting it into a shared intermediate\nrepresentation (IR) before rendering channel-specific output. The IR keeps the\nsource text intact while carrying style/link spans so chunking and rendering can\nstay consistent across channels.\n\n* **Consistency:** one parse step, multiple renderers.\n* **Safe chunking:** split text before rendering so inline formatting never\n  breaks across chunks.\n* **Channel fit:** map the same IR to Slack mrkdwn, Telegram HTML, and Signal\n  style ranges without re-parsing Markdown.\n\n1. **Parse Markdown -> IR**\n   * IR is plain text plus style spans (bold/italic/strike/code/spoiler) and link spans.\n   * Offsets are UTF-16 code units so Signal style ranges align with its API.\n   * Tables are parsed only when a channel opts into table conversion.\n2. **Chunk IR (format-first)**\n   * Chunking happens on the IR text before rendering.\n   * Inline formatting does not split across chunks; spans are sliced per chunk.\n3. **Render per channel**\n   * **Slack:** mrkdwn tokens (bold/italic/strike/code), links as `<url|label>`.\n   * **Telegram:** HTML tags (`<b>`, `<i>`, `<s>`, `<code>`, `<pre><code>`, `<a href>`).\n   * **Signal:** plain text + `text-style` ranges; links become `label (url)` when label differs.\n\n* Slack, Telegram, and Signal outbound adapters render from the IR.\n* Other channels (WhatsApp, iMessage, MS Teams, Discord) still use plain text or\n  their own formatting rules, with Markdown table conversion applied before\n  chunking when enabled.\n\nMarkdown tables are not consistently supported across chat clients. Use\n`markdown.tables` to control conversion per channel (and per account).\n\n* `code`: render tables as code blocks (default for most channels).\n* `bullets`: convert each row into bullet points (default for Signal + WhatsApp).\n* `off`: disable table parsing and conversion; raw table text passes through.\n\n* Chunk limits come from channel adapters/config and are applied to the IR text.\n* Code fences are preserved as a single block with a trailing newline so channels\n  render them correctly.\n* List prefixes and blockquote prefixes are part of the IR text, so chunking\n  does not split mid-prefix.\n* Inline styles (bold/italic/strike/inline-code/spoiler) are never split across\n  chunks; the renderer reopens styles inside each chunk.\n\nIf you need more on chunking behavior across channels, see\n[Streaming + chunking](/concepts/streaming).\n\n* **Slack:** `[label](url)` -> `<url|label>`; bare URLs remain bare. Autolink\n  is disabled during parse to avoid double-linking.\n* **Telegram:** `[label](url)` -> `<a href=\"url\">label</a>` (HTML parse mode).\n* **Signal:** `[label](url)` -> `label (url)` unless label matches the URL.\n\nSpoiler markers (`||spoiler||`) are parsed only for Signal, where they map to\nSPOILER style ranges. Other channels treat them as plain text.\n\n## How to add or update a channel formatter\n\n1. **Parse once:** use the shared `markdownToIR(...)` helper with channel-appropriate\n   options (autolink, heading style, blockquote prefix).\n2. **Render:** implement a renderer with `renderMarkdownWithMarkers(...)` and a\n   style marker map (or Signal style ranges).\n3. **Chunk:** call `chunkMarkdownIR(...)` before rendering; render each chunk.\n4. **Wire adapter:** update the channel outbound adapter to use the new chunker\n   and renderer.\n5. **Test:** add or update format tests and an outbound delivery test if the\n   channel uses chunking.\n\n* Slack angle-bracket tokens (`<@U123>`, `<#C123>`, `<https://...>`) must be\n  preserved; escape raw HTML safely.\n* Telegram HTML requires escaping text outside tags to avoid broken markup.\n* Signal style ranges depend on UTF-16 offsets; do not use code point offsets.\n* Preserve trailing newlines for fenced code blocks so closing markers land on\n  their own line.",
  "code_samples": [
    {
      "code": "IR (schematic):",
      "language": "unknown"
    },
    {
      "code": "## Where it is used\n\n* Slack, Telegram, and Signal outbound adapters render from the IR.\n* Other channels (WhatsApp, iMessage, MS Teams, Discord) still use plain text or\n  their own formatting rules, with Markdown table conversion applied before\n  chunking when enabled.\n\n## Table handling\n\nMarkdown tables are not consistently supported across chat clients. Use\n`markdown.tables` to control conversion per channel (and per account).\n\n* `code`: render tables as code blocks (default for most channels).\n* `bullets`: convert each row into bullet points (default for Signal + WhatsApp).\n* `off`: disable table parsing and conversion; raw table text passes through.\n\nConfig keys:",
      "language": "unknown"
    }
  ],
  "headings": [
    {
      "level": "h2",
      "text": "Goals",
      "id": "goals"
    },
    {
      "level": "h2",
      "text": "Pipeline",
      "id": "pipeline"
    },
    {
      "level": "h2",
      "text": "IR example",
      "id": "ir-example"
    },
    {
      "level": "h2",
      "text": "Where it is used",
      "id": "where-it-is-used"
    },
    {
      "level": "h2",
      "text": "Table handling",
      "id": "table-handling"
    },
    {
      "level": "h2",
      "text": "Chunking rules",
      "id": "chunking-rules"
    },
    {
      "level": "h2",
      "text": "Link policy",
      "id": "link-policy"
    },
    {
      "level": "h2",
      "text": "Spoilers",
      "id": "spoilers"
    },
    {
      "level": "h2",
      "text": "How to add or update a channel formatter",
      "id": "how-to-add-or-update-a-channel-formatter"
    },
    {
      "level": "h2",
      "text": "Common gotchas",
      "id": "common-gotchas"
    }
  ],
  "url": "llms-txt#markdown-formatting",
  "links": []
}