-
-
Notifications
You must be signed in to change notification settings - Fork 464
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
How to remove things like CodeBlocks from ToPlainText rendering #789
Comments
Not that I'm aware, but you can just take the Markdown AST, search/remove the code blocks, and call PlainText later. In my own blog post engine, I do it differently, convert to HTML, and extract the text from there with NUglify here |
I don't see an equivalent ToText as an extension markdig/src/Markdig/Markdown.cs Line 136 in 8e22754
So based on markdig/src/Markdig/Markdown.cs Line 240 in 8e22754
I think I need to do something like this StringWriter writer = new StringWriter();
MarkdownDocument document = Markdown.Parse(source, pipeline);
// todo remove codeblocks from Document.Decendants
HtmlRenderer renderer = new HtmlRenderer(writer)
{
EnableHtmlForBlock = false,
EnableHtmlForInline = false,
EnableHtmlEscape = false,
};
pipeline.Setup(renderer);
renderer.Render(document);
writer.Flush();
string result = writer.ToString();
return result; |
You can iterate through your MarkdownDocument and remove blocks like this.
|
Hi Xoofx,
The repo does not have discussions enabled so I am submitting it here. I apologise in advance if there is a better place to put these kind of questions.
For my blog I am looking into a clean way to count the number of words present in a specific article.
I came across the
ToPlainText
method for my Markdown. That appears to make it mostly clean text.However, it leaves in things like the code blocks (my blog is technical, so lots of code snippets).
Is there an extension point I missed, in which I can remove code blocks from the PlainText view?
Any pointers would be appreciated
Thanks for the awesome work you did on both Markdig and Scriban
Max
The text was updated successfully, but these errors were encountered: