# ferogram-parsers
Telegram HTML and Markdown entity parsers for ferogram.
[](https://crates.io/crates/ferogram-parsers)
[](https://t.me/FerogramChat) [](https://t.me/Ferogram)
[](https://docs.rs/ferogram-parsers)
[](#license)
Converts Telegram-flavoured Markdown and HTML to and from `MessageEntity` vectors. Extracted in v0.3.7 and `ferogram` re-exports everything via `ferogram::parsers`.
You can also use it on its own if you're working with Telegram formatted text outside of the full client.
---
## Installation
```toml
[dependencies]
ferogram-parsers = "0.3.8"
```
---
## Usage
### Markdown
```rust
use ferogram_parsers::{parse_markdown, generate_markdown};
let (text, entities) = parse_markdown("**bold** and _italic_");
// text = "bold and italic"
// entities = [Bold(0..4), Italic(9..15)]
let md = generate_markdown(&text, &entities);
// md = "**bold** and __italic__"
```
Supported syntax:
| `**bold**` or `*bold*` | Bold |
| `__italic__` or `_italic_` | Italic |
| `~~strike~~` | Strikethrough |
| `\|\|spoiler\|\|` | Spoiler |
| `` `code` `` | Code |
| ` ```lang\npre\n``` ` | Pre (code block) |
| `[text](url)` | TextUrl |
| `[text](tg://user?id=123)` | MentionName |
| `` | CustomEmoji |
| `\*`, `\_`, `\~` ... | Escaped literal char |
### HTML
```rust
use ferogram_parsers::{parse_html, generate_html};
let (text, entities) = parse_html("<b>Hello</b> <i>world</i>");
// text = "Hello world"
// entities = [Bold(0..5), Italic(6..11)]
let html = generate_html(&text, &entities);
// html = "<b>Hello</b> <i>world</i>"
```
Supported tags: `<b>`, `<strong>`, `<i>`, `<em>`, `<u>`, `<s>`, `<del>`, `<code>`, `<pre>`, `<tg-spoiler>`, `<a href="url">`, `<tg-emoji emoji-id="id">`
---
## Feature flags
| `html5ever` | Replaces `parse_html` with a spec-compliant html5ever tokenizer |
By default `parse_html` uses the built-in hand-rolled parser (zero extra dependencies). Enable `html5ever` for strict HTML5 conformance.
```toml
ferogram-parsers = { version = "0.3.8", features = ["html5ever"] }
```
---
## Stack position
```
ferogram
└ ferogram-parsers <-- here
└ ferogram-tl-types (tl-api feature)
```
---
## License
MIT or Apache-2.0, at your option. See [LICENSE-MIT](../LICENSE-MIT) and [LICENSE-APACHE](../LICENSE-APACHE).
**Ankit Chaubey** - [github.com/ankit-chaubey](https://github.com/ankit-chaubey)