mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-08 13:54:54 +00:00
Code block for Blazor syntax as string #468
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @stsrki on GitHub (May 28, 2021).
I'm trying to find a solution where code blocks are converted to a string instead of an HTML kind of structure.
Let say I have the following code surrounded by three backticks
With Markdig it is converted to this
Whereas I want it to behave the same as GitHub comments. To render code blocks as strings.
Is this possible?
@xoofx commented on GitHub (May 28, 2021):
You need to plug your own
CodeBlockRenderer(original) through theHtmlRendererthat you setup through theMarkdownPipelineBuilder@MihaZupan do you have any other ideas?
@MihaZupan commented on GitHub (May 28, 2021):
I'm not sure I understand the question
If you pass html surrounded by ``` to Markdig, the HTML tags will be escaped - which is then interpreted as just a string literal by the browser since there are no tags
Example
@stsrki commented on GitHub (May 28, 2021):
When I debug and inspect the value in Visual Studio I get no escape characters
and source string has ``` defined
@MihaZupan commented on GitHub (May 28, 2021):
Can you share the code you are using (specifically how you're converting the markdown)?
@stsrki commented on GitHub (May 28, 2021):
It's pretty basic
and for pipeline
@MihaZupan commented on GitHub (May 28, 2021):
My guess would be it's exactly how you're rendering the string (BodyHtml) to the document that is affecting how it's represented.
The result of
Markdown.ToHtmlshould be html with an escaped string in the code block.@stsrki commented on GitHub (May 28, 2021):
I found out what is causing the issue. It is the
.UsePrism(). If I remove it, the string will escape correctly and render code block. But now I've lost syntax highlighting...@xoofx commented on GitHub (May 28, 2021):
I don't know why the code of this Prism is requiring a Markdig extension (the renderer is here https://github.com/ilich/Markdig.Prism/blob/main/src/Markdig.Prism/PrismCodeBlockRenderer.cs)
I have used prism coloring with markdig rendering on my blog post without the need for such extension.