gomarkdown / markdown

markdown parser and HTML renderer for Go
Other
1.36k stars 171 forks source link

Stripping markdown #300

Closed shwarcu closed 7 months ago

shwarcu commented 7 months ago

Hi, is it possible to remove markdown from a text and output plain text without any markdown with this library? Do I have to implement custom renderer for this purpose or there's some other way to achieve this?

Example input:

**this is bold**
*this is italic*

output:

this is bold
this is italic
kjk commented 7 months ago

Your best bet would be a custom renderer based on https://github.com/gomarkdown/markdown/blob/master/md/md_renderer.go

Notice md_renderer.go has a few ast nodes not implemented so you would have to implement those as well. Or at least remove the panic().

Since this is a question and not a bug report, I'm going to close it.

shwarcu commented 7 months ago

How about option DisableTags from https://github.com/gomarkdown/markdown/blob/master/html/renderer.go#L135

I'm checking briefly what it does and it seems to strip html tags? I'm not very proficient with GO yet so I might be misunderstanding

kjk commented 7 months ago

Well, it does what you say and what the comments say. I haven't looked at this code in very long time so after 5 minutes of reading you'll know more than I do at this point.

shwarcu commented 7 months ago

👋 I've opened a PR related to this discussion https://github.com/gomarkdown/markdown/pull/301

kjk commented 7 months ago

Like I commented, that change isn't right.

You can of course fork the library and use it as a simple hack to get what you want. Just be aware that it won't work well for tables, it'll probably html-escape code blocks (i.e. '>' will turn into '>` etc.

shwarcu commented 7 months ago

Sure, thanks for your time and explaining things to me. I will most likely work on a custom renderrer then 👍