# Markdown Formatting

OpenClaw processes Markdown through an intermediate representation (IR) system that maintains consistent formatting across multiple chat platforms including Slack, Telegram, and Signal.

## Core Architecture

The system operates in three stages:
1. Parsing Markdown into an IR format
2. Chunking the IR text before rendering
3. Converting to channel-specific output

The IR preserves plain text plus style spans (bold/italic/strike/code/spoiler) and link spans, using UTF-16 code units for offset compatibility.

## Key Design Principles

The approach aims to achieve:
- **Consistency**: Single parsing step with multiple renderers
- **Safe chunking**: Avoid splitting inline formatting
- **Adaptability**: Same IR works across different platform requirements without re-parsing

## Channel-Specific Rendering

Each platform receives tailored output:

| Platform | Formatting |
|----------|------------|
| **Slack** | Uses mrkdwn formatting with `<url\|label>` link syntax |
| **Telegram** | Applies HTML tags for styling and links |
| **Signal** | Employs plain text with style ranges; links display as "label (url)" |

## Table Handling

Tables support three modes:
- Code blocks (default)
- Bullet-point conversion
- Disabled parsing

Configuration allows per-channel and per-account customization.

## Implementation Guidance

Adding formatters requires:
1. Parsing with appropriate options
2. Implementing channel-specific renderers
3. Calling the chunking function before rendering
4. Updating the adapter
5. Adding test coverage for both formatting and delivery
