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

Stripping markdown #300

Closed
shwarcu opened this issue Jan 25, 2024 · 6 comments
Closed

Stripping markdown #300

shwarcu opened this issue Jan 25, 2024 · 6 comments

Comments

@shwarcu
Copy link

shwarcu commented Jan 25, 2024

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
Copy link
Contributor

kjk commented Jan 25, 2024

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.

@kjk kjk closed this as completed Jan 25, 2024
@shwarcu
Copy link
Author

shwarcu commented Jan 25, 2024

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
Copy link
Contributor

kjk commented Jan 25, 2024

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
Copy link
Author

shwarcu commented Jan 25, 2024

👋 I've opened a PR related to this discussion #301

@kjk
Copy link
Contributor

kjk commented Jan 26, 2024

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
Copy link
Author

shwarcu commented Jan 26, 2024

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

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

No branches or pull requests

2 participants