How to get clean text without markdown markup?

Hello. For my bot I need to retrieve text after it is rendered with markdown. The problem is that I need to take into account character escaping and etc. How can I do this?
25 Replies
d.js toolkit
d.js toolkit•8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
ErickSkrauch
ErickSkrauchOP•8mo ago
I have already explained all the necessary details.
-Carlos👑
-Carlos👑•8mo ago
string manipulation is not djs, you can ask in #other-js-ts
ErickSkrauch
ErickSkrauchOP•8mo ago
Yea, I know. But since Discord has a pretty powerful markdown formatting system, it seems like there should be a way in the Discord.js library itself to get the plain text, since nobody but the library would know exactly how to render that markdown to get the final text.
-Carlos👑
-Carlos👑•8mo ago
what do you exactly mean by markdown? this?
ErickSkrauch
ErickSkrauchOP•8mo ago
Yep. When you send a message with such formatting, bot receives plain markdown: **this?**. But I need to strip somehow all those asterisks, underlines, etc., and obtain the plain text. I saw some libraries that utilize marked library in order to format text and extract plain from built HTML, but they doesn't support the whole markdown, available on Discord.
d.js docs
d.js docs•8mo ago
:property: Message#cleanContent The message contents with all mentions replaced by the equivalent text. If mentions cannot be resolved to a name, the relevant mention in the message content will not be converted.
monbrey
monbrey•8mo ago
This would be one part towards that There's isnt really a way to strip all of it otherwise, its part of the content
-Carlos👑
-Carlos👑•8mo ago
found this, haven't tried it but you can give it a try https://discord.js.org/docs/packages/formatters/0.3.3/escapeMarkdown:Function
discord.js
discord.js
discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
monbrey
monbrey•8mo ago
That doesn't remove it
ErickSkrauch
ErickSkrauchOP•8mo ago
Unfortunatelly, it doesn't remove markup.
monbrey
monbrey•8mo ago
Though if you look at the source code regex used to identify it, could be a good way to implement your own
ErickSkrauch
ErickSkrauchOP•8mo ago
It will escape markup, but do not remove it.
monbrey
monbrey•8mo ago
Take the source code and instead of doing replacements/joins with escaped markdown, do it with nothing removed
ErickSkrauch
ErickSkrauchOP•8mo ago
As I mentioned, it's way more complex than simple "find double asterisk and remove it". That is the problem (
monbrey
monbrey•8mo ago
But you have source code right there escaping it So take that, but instead of the final step being to add escaped markdown Add nothing And then its removed
ErickSkrauch
ErickSkrauchOP•8mo ago
It escapes it quite straightforward.
monbrey
monbrey•8mo ago
I'm not sure if you're not listening or not understanding what I'm suggesting I know what the function does
ErickSkrauch
ErickSkrauchOP•8mo ago
x**x is still contains those asterisks and they doesn't rendered as bold text. So they should be treated as part of the input and doesn't stripped.
monbrey
monbrey•8mo ago
Oh, thats almost impossible to do
ErickSkrauch
ErickSkrauchOP•8mo ago
But Discord does that. So there should be a way :)
monbrey
monbrey•8mo ago
We do not have Discord's markdown processor
ErickSkrauch
ErickSkrauchOP•8mo ago
Thats why I created this topic, because for me it seems like this library (@discordjs/formatters to be precise) must provide a way to extract plain text from the message.
monbrey
monbrey•8mo ago
It does not
ErickSkrauch
ErickSkrauchOP•8mo ago
I thought maybe there is some already existing solution that I'm missing, but it seems that there is no such solution :(
Want results from more Discord servers?
Add your server