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
- 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!I have already explained all the necessary details.
string manipulation is not djs, you can ask in #other-js-ts
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.
what do you exactly mean by markdown?
this?
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.: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.
This would be one part towards that
There's isnt really a way to strip all of it otherwise, its part of the content
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.
That doesn't remove it
Unfortunatelly, it doesn't remove markup.
Though if you look at the source code regex used to identify it, could be a good way to implement your own
It will escape markup, but do not remove it.
Take the source code and instead of doing replacements/joins with escaped markdown, do it with nothing
removed
As I mentioned, it's way more complex than simple "find double asterisk and remove it". That is the problem (
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
It escapes it quite straightforward.
I'm not sure if you're not listening or not understanding what I'm suggesting
I know what the function does
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.
Oh, thats almost impossible to do
But Discord does that.
So there should be a way :)
We do not have Discord's markdown processor
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.It does not
I thought maybe there is some already existing solution that I'm missing, but it seems that there is no such solution :(