# @mtcute/html-parser > HTML entities parser for MTCute This package implements formatting syntax based on HTML, similar to the one available in the Bot API ([documented here](https://core.telegram.org/bots/api#html-style)) > **NOTE**: The syntax implemented here is **incompatible** with Bot API _HTML_. > > Please read [Syntax](#syntax) below for a detailed explanation ## Usage ```typescript import { TelegramClient } from '@mtcute/client' import { HtmlMessageEntityParser, html } from '@mtcute/html-parser' const tg = new TelegramClient({ ... }) tg.registerParseMode(new HtmlMessageEntityParser()) tg.sendText( 'me', html`Hello, me! Updates from the feed:
${await getUpdatesFromFeed()}` ) ``` ## Syntax `@mtcute/html-parser` uses [`htmlparser2`](https://www.npmjs.com/package/htmlparser2) under the hood, so the parser supports nearly any HTML. However, since the text is still processed in a custom way for Telegram, the supported subset of features is documented below: ## Line breaks and spaces Line breaks are **not** preserved, `
` is used instead, making the syntax very close to the one used when building web pages. Multiple spaces and indents are collapsed, when you do need multiple spaces use ` ` instead. ## Inline entities Inline entities are entities that are in-line with other text. We support these entities: | Name | Code | Result (visual) | |------------------|-------------------------------------------|------------------------------| | Bold | `text` | **text** | | Italic | `text` | _text_ | | Underline | `text` | text | | Strikethrough | `text` | ~~text~~ | | Spoiler | `text` | N/A | | Monospace (code) | `text` | `text` | | Text link | `Google` | [Google](https://google.com) | | Text mention | `Name` | N/A | | Custom emoji | `😄` | N/A | > **Note**: ``, ``, ``, ``, `` are not supported because they are redundant > **Note**: It is up to the client to look up user's input entity by ID for text mentions. > In most cases, you can only use IDs of users that were seen by the client while using given storage. > > Alternatively, you can explicitly provide access hash like this: > `Name`, where `abc` is user's access hash > written as a base-16 *unsigned* integer. Order of the parameters does matter, i.e. > `tg://user?hash=abc&id=1234567` will not be processed as expected. ## Block entities The only block entity that Telegram supports is `
`, therefore it is the only tag we support too.

Optionally, language for `
` block can be specified like this:

```html
export type Foo = 42
``` > However, since syntax highlighting hasn't been implemented in > official Telegram clients, this doesn't really matter 🤷‍♀️ | Code | Result (visual) | |-------------------------------------------------------------------------------------|------------------------------| |
<pre>multiline\ntext</pre>
|
multiline
text
| |
<pre language="javascript">
export default 42
</pre>
|
export default 42
| ## Nested and overlapped entities HTML is a nested language, and so is this parser. It does support nested entities, but overlapped entities will not work as expected! Overlapping entities are supported in `unparse()`, though. | Code | Result (visual) | |---------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------| | `Welcome back, User!` | **Welcome back, _User_!** | | `bold and italic` | **bold _and_** italic
⚠️ word "italic" is not actually italic! | | `bold and italic`
⚠️ this is how unparse() handles overlapping entities | **bold _and_** _italic_ | ## Escaping Escaping in this parser works exactly the same as in `htmlparser2`. This means that you can keep `<>&` symbols as-is in some cases. However, when dealing with user input, it is always better to use [`HtmlMessageEntityParser.escape`](./classes/htmlmessageentityparser.html#escape) or, even better, `html` helper: ```typescript import { html } from '@mtcute/html-parser' const username = 'Boris <&>' const text = html`Hi, ${username}!` console.log(text) // Hi, Boris &lt;&amp;&gt;! ```