mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
Turning on TrackTrivia prevents EmphasisInline elements being created #472
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 @nikkilocke on GitHub (Jul 9, 2021).
I am trying to create a converter which will convert Markdown to a form suitable for posting Telegram messages. I have got quite far, to the extent that I can parse some markdown, and turn it into a text string, with MessageEntity objects which show the offset, length and attributes (e.g. a Url for a link) - which is how Telegram does formatting.
Unfortunately the text string has the "insignificant" white space removed - for instance, my first test markdown is:
I ran this through the Roundtrip renderer, and it came out as
Test stuff-bold text-italic text-~~strikethrough text~~-https://google.com?search=autolink-Full link-Bold full link-Bold full linkMy telegram renderer (which removes the markdown furniture) shows the same.
My renderer is a subclass of RoundtripRenderer, which extracts the bold, italic and url elements, and finds these Entities:
I need to preserve the white space, so I tried setting EnableTrackTrivia in the parser.
Unfortunately the document then has no EmphasisInline elements in it. The roundtrip output is (correctly):
My Telegram renderer (which removes the markdown furniture for items it recognises) shows:
but most of the inline emphasis entities are missing:
Should TrackTrivia turn off recognising inline emphasis? If so, is there another way to retain the newlines and spaces in the original markdown?
@nikkilocke commented on GitHub (Jul 9, 2021):
Just FYI, I have looked carefully at the code from NormalizeRenderer, and modified all my renderers to do what that does, and the output is now acceptable, although I would prefer it to match the input more exactly if possible.
So the problem is no longer serious for me, but you might find it intriguing, and worth investigating, as it may be a bug in the parser.
@xoofx commented on GitHub (Aug 27, 2021):
Note that
NormalizeRenderershould not be used with TrackTrivia but insteadRoundtripRenderer.NormalizeRenderermight be deprecated at some point, as the normalize part should be better done as a modification of the AST that can be feed into theRountripRenderer@generateui commented on GitHub (Nov 10, 2021):
Can you provide a minimally viable test that fails on your input and include assertion? That's go a long way in fixing this.
@jo3w4rd commented on GitHub (Mar 9, 2022):
I notice this as well, just using
Markdown.ToHtml().The code:
produces output:
If you remove the
EnableTrackTrivia()call, the output is correct:@xoofx commented on GitHub (Mar 9, 2022):
Yeah, if
EnableTrackTrivia()is making such changes, than it's definitely a serious bug.@xoofx commented on GitHub (Mar 11, 2022):
I believe this should be fixed by
983187eand available in 0.28.0Please note that I have opened a new issue #604
I would really highly suggest to not use
EnableTrackTrivia()for rendering to HTML.EnableTrackTrivia()was mainly introduced for roundtrip. I have seen other rendering issues with it.Otherwise I'm curious about the use case for using
EnableTrackTrivia()with rendering to HTML?