Node-red-contrib-turndown - Escaping characters

Hi,

I would use node-red to create a bot able to grab specific info online through cheerio and send using telegram.

To do that, I would convert html to markdownV2, in order to maintain links and some formatting.

I tried to use node-red-contrib-turndown node, but - as the node effectively transforms formatting - I noticed that markdown special characters are not escaped:
Asterisk *
Underscore _
Curly braces { }
Square brackets
Brackets ( )
Hash #
Plus +
Minus -
Period .
Exclamation point !

So, if I try to send them to telegram, it crash because of errors in parsing.

Node has no configuration, so I don't know what to do... someone else had experienced this? Did I something wrong?

Telegram's interpretation of Markdown is extremely simplistic anyway and it fails with odd characters as I found out the hard way. I'm working at the moment but I'll see if I can find the details later. Just note that their v1 implementation is more forgiving than their v2. But v1 supports even less markup (which is why it is more forgiving)

I wrote a regex function that escapes special chars... Seems working for now

replace(/(\[[^\[\]]+\]\((http[^\[\]\(\)]+)\))|[_[\\\]()~>#+=|{}.!-]/gi, (x,y) => y ? y : '\\' + x);
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.