mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
Avoiding double escape of html #602
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 @magom001 on GitHub (May 2, 2023).
I am having trouble figuring out how to disable escaping of certain characters.
Example: https://dotnetfiddle.net/Jx9koN
It is being replaced in WriteEscapeSlow with no way to turn if off.
What would be the correct approach to fix it?
@xoofx commented on GitHub (May 3, 2023):
It is by design (and afaik, a requirement for HTML) and can't be turned off. If there is an entity like
', even within backsticks, it will have to escape the&in the resulting HTML. All (CommonMark) Markdown implementations are respecting this as you can see here@magom001 commented on GitHub (May 4, 2023):
For anyone who might face this issue, I solved it by creating an extension which replaces certain rerenders with my owns.
By default Markdig html renderers will use HtmlRenderer.WriteEscape method, which will escape & and some other characters. I simply copied the implementation of those renerers and replaces WriteEscape with Write.
You should not normally do any of that, but for some technical reasons, in our code the markdown string has to be escaped before it is fed into the Markdown.ToHtml method.