Strip markdown #104

Closed
opened 2026-01-29 14:26:51 +00:00 by claunia · 8 comments
Owner

Originally created by @ProsperoTheBun on GitHub (Mar 24, 2017).

Feature Request:
It would be useful to be able to remove all markdown without converting to HTML. E.g, for a preview of a blog's body text.

So an input like ...

__Reasons to be happy__
- Sunshine
- Meerkats
- Football

Would produce

Reasons to be happy
Sunshine
Meerkats
Football
Originally created by @ProsperoTheBun on GitHub (Mar 24, 2017). Feature Request: It would be useful to be able to remove all markdown without converting to HTML. E.g, for a preview of a blog's body text. So an input like ... ``` __Reasons to be happy__ - Sunshine - Meerkats - Football ``` Would produce ``` Reasons to be happy Sunshine Meerkats Football ```
claunia added the enhancementPR Welcome! labels 2026-01-29 14:26:51 +00:00
Author
Owner

@ProsperoTheBun commented on GitHub (Mar 24, 2017):

FYI, I workaround this on webpages by using jQuery to read the "text" of the element then write it back in.

var text = $("#body-snippet").text();
$("#body-snippet").text(text);

But for my app feed API, I'd rather do this server-side.

@ProsperoTheBun commented on GitHub (Mar 24, 2017): FYI, I workaround this on webpages by using jQuery to read the "text" of the element then write it back in. ``` var text = $("#body-snippet").text(); $("#body-snippet").text(text); ``` But for my app feed API, I'd rather do this server-side.
Author
Owner

@leotsarev commented on GitHub (May 14, 2017):

Note that's a good practice to sanitize HTML anyway (as markdown parsers do not sanitize). Most of HTML sanitizers could remove all html anyway

@leotsarev commented on GitHub (May 14, 2017): Note that's a good practice to sanitize HTML anyway (as markdown parsers do not sanitize). Most of HTML sanitizers could remove all html anyway
Author
Owner

@xoofx commented on GitHub (May 18, 2017):

It would be useful to be able to remove all markdown without converting to HTML. E.g, for a preview of a blog's body text.

Markdown at its first origin is text oriented, so that even a simple bullet point list would be readable in plain text. So in your examples above, removing the - for the list even for displaying as text is quite an opinionated "preview"... For other markdown elements, I can also see quite different ways to output a text preview (emphasis could remove, but links? still displaying the link or not?...etc.)

Personally don't have time nor special interest in this feature, but a PR is welcome.

Note that HtmlRenderer has already a property EnableHtmlForInline, that is currently working only for inlines. If someone wants to work on this PR, you can still use the HtmlRenderer, but add a EnableHtmlForBlock, and revisit all html block renderers (like the HeadingRenderer) and enclose with if/else the portions that are outputing HTML (but keep at least the WriteLine to keep a reasonable structure of the text)

@xoofx commented on GitHub (May 18, 2017): > It would be useful to be able to remove all markdown without converting to HTML. E.g, for a preview of a blog's body text. Markdown at its first origin is text oriented, so that even a simple bullet point list would be readable in plain text. So in your examples above, removing the `-` for the list even for displaying as text is quite an opinionated "preview"... For other markdown elements, I can also see quite different ways to output a text preview (emphasis could remove, but links? still displaying the link or not?...etc.) Personally don't have time nor special interest in this feature, but a PR is welcome. Note that `HtmlRenderer` has already a property `EnableHtmlForInline`, that is currently working only for inlines. If someone wants to work on this PR, you can still use the HtmlRenderer, but add a `EnableHtmlForBlock`, and revisit all html block renderers (like the `HeadingRenderer`) and enclose with if/else the portions that are outputing HTML (but keep at least the `WriteLine` to keep a reasonable structure of the text)
Author
Owner

@xoofx commented on GitHub (Sep 12, 2017):

Errata about my previous comment: If someone wants to provide such feature, I would much prefer that we do this work as part of #32, as it covers broader use cases.

@xoofx commented on GitHub (Sep 12, 2017): Errata about my previous comment: If someone wants to provide such feature, I would much prefer that we do this work as part of #32, as it covers broader use cases.
Author
Owner

@xoofx commented on GitHub (Sep 12, 2017):

Actually, scratch that... #32 is probably not ideal either if we want to keep only text... Let me think about this...

@xoofx commented on GitHub (Sep 12, 2017): Actually, scratch that... #32 is probably not ideal either if we want to keep only text... Let me think about this...
Author
Owner

@xoofx commented on GitHub (Oct 24, 2017):

So this should be fixed by PR #140 that was just merged to master

@xoofx commented on GitHub (Oct 24, 2017): So this should be fixed by PR #140 that was just merged to master
Author
Owner

@xoofx commented on GitHub (Oct 24, 2017):

So the workaround for this issue is to use a HtmlRenderer and setting both EnableHtmlForInline and EnableHtmlForBlock to false

@xoofx commented on GitHub (Oct 24, 2017): So the workaround for this issue is to use a `HtmlRenderer` and setting both `EnableHtmlForInline` and `EnableHtmlForBlock` to `false`
Author
Owner

@leotsarev commented on GitHub (Oct 27, 2017):

I submitted public API facade for this. I wonder if you are open to change like that, I'm happy to expand if required.

@leotsarev commented on GitHub (Oct 27, 2017): I submitted public API facade for this. I wonder if you are open to change like that, I'm happy to expand if required.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#104