# @deltachat/message_parser_wasm

> Parsing of Links, Email adresses, simple text formatting (markdown subset), user mentions, hashtags and more in DeltaChat messages.

Latest version **0.14.1** (published 2025-05-26) · MPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install @deltachat/message_parser_wasm
pnpm add @deltachat/message_parser_wasm
yarn add @deltachat/message_parser_wasm
bun add @deltachat/message_parser_wasm
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.14.1 |
| Published | 2025-05-26 |
| First published | 2021-11-10 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 175.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Maintainers | missytake, simon-laux, jikstra, link2xt |

## Links

- npm: https://www.npmjs.com/package/@deltachat/message_parser_wasm
- Repository: https://github.com/deltachat/message-parser
- Homepage: https://github.com/deltachat/message-parser#readme
- Issues: https://github.com/deltachat/message-parser/issues
- npm.io page: https://npm.io/package/@deltachat/message_parser_wasm

## Recent versions

- 0.14.1 (latest) — 2025-05-26
- 0.14.0 — 2025-05-26
- 0.13.0 — 2025-03-27
- 0.12.0 — 2025-01-11
- 0.11.0 — 2024-06-04
- 0.10.0 — 2024-05-10
- 0.9.0 — 2023-11-16
- 0.8.0 — 2023-10-09
- 0.7.0 — 2023-09-04
- 0.6.0 — 2023-08-13
- 0.5.1 — 2023-02-27
- 0.4.0 — 2022-05-09
- 0.3.0 — 2022-03-04
- 0.1.0 — 2021-11-10

## README

# DeltaChat Message Parser WASM

Parsing of Links, email addresses, simple text formatting (markdown subset), user mentions, hashtags and more in DeltaChat messages.

The specification can be found in [spec.md](https://github.com/deltachat/message-parser/blob/main/message_parser_wasm/spec.md).

The parser is written in rust with the [nom crate](https://github.com/Geal/nom) and compiled to web assembly for this package.

## The Idea behind it

Have the same rich message parsing on all platforms.

The basic idea is that core can use this library to convert messages to an AST format,
that can then be displayed by the UIs how they see fit, for desktop it will be converted to react elements.

> Desktop already uses this package (minus the markdown, because it does not make sense to only have markdown on desktop and not also on iOS and android) as wasm module (see `./message_parser_wasm`), later this will probably be integrated into deltachat core.

Read more about the project on github: https://github.com/deltachat/message-parser

## 🚴 Usage

```ts
function parse_text(s: string, enable_markdown: boolean): ParsedElement[];
```

```js
import init, { parse_text } from "./pkg/message_parser_wasm.js";

init().then(() => {
    let parsed = parse_text("hello **world**", true)

    let result = parsed.map(element => {
        switch element.t {
            case "Bold":
                return `<b>${element.c}</b>`
                break;
            case "Text"
                return element.c
            // ...
            default
                console.error(`type ${element.t} not known/implemented yet`, element);
                return JSON.stringify(element)
        }
    }).join("")

    console.log(result) // "hello <b>world</b>"
})
```

> DO **NOT** actually write html with user input like that, this is for demonstration purposes ONLY!
> It let's you and your users open to **XSS attacks**, the examples bellow are much better suitable for reference or copy+pasting.

also see [example.js](./example.js) and test it live on <https://deltachat.github.io/message-parser/>

For usage in react you can look at how we integrated this package in deltachat-desktop: [deltachat-desktop/src/renderer/components/message/MessageMarkdown.tsx](https://github.com/deltachat/deltachat-desktop/blob/7493f898bc3dff06b20565a48e93564f5996b855/src/renderer/components/message/MessageMarkdown.tsx)

If you want to see it in action in deltachat-desktop, feel free to download it on <https://get.delta.chat>.


### Emoji Helper functions

```js
/** returns first emoji from text if text begins with an emoji */
export function get_first_emoji(input: string): string | undefined;
/** If string contains only emojis count the emojis otherwise retuns null */
export function count_emojis_if_only_contains_emoji(input: string): number | undefined;
```

### For Devs

#### 🛠️ Build with `wasm-pack build`

```
wasm-pack build --scope deltachat --target web
```

#### 🔬 Test in Headless Browsers with `wasm-pack test`

```
wasm-pack test --headless --firefox
```

#### 🎁 Publish to NPM with `wasm-pack publish`

```
wasm-pack publish --target web
```

---
_Source: https://npm.io/package/@deltachat/message_parser_wasm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
