A library that converts telegram message entities into html and markdown formats. (Intented to use alongside with TelegrafJS)
This library is intented to use alongside with telegraf. But you still can test it with other frameworks or your own codebase - all you need are text and array of entity objects in that text.
To use the example below you can have telegraf installed in your project.
$ npm install telegraf
or
$ yarn add telegraf
See offical guide for more info. Once you have installed telegraf in your project, you can use telegraf-pagination.
Run one of these commands depending on what package manager you're using:
$ npm install telegraf-entity
or
$ yarn add telegraf-entity
Here is an example:
const { EntityMessage } = require("telegraf-entity");
bot.on("message", (ctx) => {
if (!ctx.message.text || !ctx.message.entities) return;
const formatter = new EntityMessage(ctx.message.text, ctx.message.entities);
let htmlContent = formatter.html;
let markdownContent = formatter.markdown;
console.log("HTML: ", htlmContent);
console.log("Markdown: ", markdownContent);
});
- Default formatters:
- mention
- hashtag
- cashtag
- bot_command
- url
- phone_number
- bold
- italic
- underline
- strikethrough
- spoiler
- code
- pre
- text_link
- text_mention
- custom_emoji
- Options for custom formatters for specific entities like spoiler, custom_emoji... (maybe for all)
Please read CODE_OF_CONDUCT.md for details on our code of conduct. Feel free to submit any pull request.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Alisher Ortiqov - Initial work - mcpeblocker
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details