Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot handle blockquotes (>) #5

Closed
RainEggplant opened this issue Mar 15, 2023 · 6 comments
Closed

Cannot handle blockquotes (>) #5

RainEggplant opened this issue Mar 15, 2023 · 6 comments
Labels

Comments

@RainEggplant
Copy link

Sorry to trouble you again. But first of all, I want to say thank you very much for developing this library! I'm currently using it with my ChatGPT Telegram bot, and most of the time it works very well, but sometimes there are small bugs that cause messages not to be parsed correctly. Really hope this can be fixed.

Describe the bug
Cannot handle blockquotes (>)

To Reproduce
Convert the following text:

> Hello

Current behavior

Did not escape >.

> Hello

Then Telegram will raise an error:

ETELEGRAM: 400 Bad Request: can't parse entities: Character '>' is reserved and must be escaped with the preceding '\'

Expected behavior
It seems that Telegram's Markdown does not support blockquotes. Maybe we can turn it into a code block or something else?

@skoropadas
Copy link
Owner

You are welcome, sorry I missed the last of your tickets.

Yes you are right Telegram's markdown doesn't support blockquotes, so I don't process them because if I start processing them then I need to process other things like tables etc. which are not possible.

Of course, there are several different solutions, for example, removing unsupported content or displaying it as code, but each of these solutions may be suitable for some library users and at the same time not suitable for others. Therefore, I would advise you to take a look at the convert.js file and create your own version in your project, adding your own handlers for elements that are not supported by Telegram's markdown.

@RainEggplant
Copy link
Author

RainEggplant commented Mar 15, 2023

Thank you! That makes sense. But I think we can at least escape those characters so telegram will not raise an error and instead display them as-is?

(From telegram's API doc)

In all other places characters '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!' must be escaped with the preceding character '\'.

@skoropadas
Copy link
Owner

Okay, since you're not the first person who asks this, I'll do the following:
I'll add an additional parameter that will allow you to escape unsupported tags and display them as-is. As a result, you'll be able to use the function like this:

const escapedResult = telegramifyMarkdown(markdown, {}, true);

@skoropadas
Copy link
Owner

Ok I've changed my mind a bit, I've added more options, you can check them here

@github-actions
Copy link

🎉 This issue has been resolved in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@RainEggplant
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants