# Markdown and HTML to WhatsApp formatting

> WhatsApp has its own small formatting: bold, italic, strikethrough, monospace, lists and quotes. Convert Markdown or HTML (from an AI model, a CMS or an e-mail) into it, and cut long texts into messages of 4096 characters.

Text from an AI model, a CMS or an e-mail is often Markdown or HTML. WhatsApp does not read either: `**bold**` arrives with its stars, a link arrives as `[text](url)`, and HTML tags arrive as text. app2email converts it into WhatsApp's own formatting.

<a id="rules"></a>

## What WhatsApp shows

| Write | WhatsApp shows |
| --- | --- |
| `*bold*` | **bold** |
| `_italic_` | *italic* |
| `~strikethrough~` | ~~strikethrough~~ |
| ` ```monospace``` ` | a monospace block |
| `` `inline code` `` | inline code |
| `- item` or `* item` | a bulleted list |
| `1. item` | a numbered list |
| `> quote` | a quote |

<a id="conversion"></a>

## What the conversion does

| Markdown | Becomes |
| --- | --- |
| `**bold**`, `__bold__` | `*bold*` |
| `*italic*` | `_italic_` |
| `~~strike~~` | `~strike~` |
| `# Heading` | `*Heading*` on its own line |
| `- `, `* `, `+ `, `1. ` lists, `> ` quotes | kept, in WhatsApp's form |
| `` `code` ``, ```` ``` ```` blocks | kept (a block's language tag is dropped) |
| `[text](https://...)` | `text: https://...` (just the address when both are the same) |
| `![alt](https://...)` | `alt: https://...` |
| a table | one line per row: `a \| b` |
| `---` | removed |

From HTML: `b` / `strong`, `i` / `em`, `s` / `del`, `br`, `p`, `ul` / `ol` / `li`, `a`, `code` and `pre` are converted the same way; every other tag is dropped, entities such as `&amp;` are decoded, and `script` and `style` contents are removed. Nothing in the text is ever fetched.

<a id="api"></a>

## Try it: POST /format

```bash
curl -X POST "https://api.app2email.com/v1/YOUR_NUMBER/format" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "**Order 1234** is on its way. Track it [here](https://shop.example.com/t/1234).", "from": "markdown"}'
```

```json
{
  "success": true,
  "request_id": "f0rm1",
  "text": "*Order 1234* is on its way. Track it here: https://shop.example.com/t/1234.",
  "length": 75,
  "parts": ["*Order 1234* is on its way. Track it here: https://shop.example.com/t/1234."],
  "changes": ["1 bold text converted", "1 link written out"]
}
```

It sends nothing (a key with `messages:read` is enough). `from` is `markdown` (the default) or `html`. With `"split": true`, `parts` holds the text cut into messages of at most 4,096 characters (WhatsApp's limit): at a paragraph end, else a sentence end, and never inside a code block when there is another place to cut. The text may be up to 100,000 characters. AI agents use the MCP tool `format_text`.

<a id="send"></a>

## Convert while sending

Add `format` to a text message, and `split` for long texts:

```bash
curl -X POST "https://api.app2email.com/v1/YOUR_NUMBER/messages" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to": "61412345678", "type": "text", "text": {"body": "## Your order\n\n**1234** ships today.", "format": "markdown", "split": true}}'
```

With `split`, a text longer than 4,096 characters goes as several messages, in order; the answer lists their `message_ids`. Each one counts as a message of your plan.

<a id="errors"></a>

## Errors

| Code | Status | Meaning |
| --- | --- | --- |
| `invalid_format_request` | 400 | `text` is missing, `from` is not `markdown` or `html`, or `split` is not true or false. |
| `text_too_long_to_format` | 413 | The text is longer than 100,000 characters. |

The complete list is on [the errors page](/api/errors).
