-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
Roundtrip implementation #481
Conversation
Indeed, Markdig was not built with that requirement but we have seen many cases where users would have loved to do roundtrip modifications to a Markdown document, so thanks for starting to work on this! So far, the changes make senses. I will just add a couple of remarks and requirements:
I'm gonna add a few comments on the current PR. Ping me in the PR whenever you have made enough progress and you want another checkpoint. Good luck with the work! |
Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
Update:
🎉🥳 DONE! As far as I can see, all items are done and this PR is ready to merge. |
I'll do a once-over tomorrow. |
RoundTrip(value, expected); | ||
} | ||
|
||
// this method is copied intentionally to ensure all other tests | ||
// do not unintentionally use the expected parameter | ||
private static void RoundTrip(string markdown, string expected) | ||
{ | ||
var pipelineBuilder = new MarkdownPipelineBuilder(); | ||
pipelineBuilder.EnableTrackTrivia(); | ||
MarkdownPipeline pipeline = pipelineBuilder.Build(); | ||
MarkdownDocument markdownDocument = Markdown.Parse(markdown, pipeline); | ||
var sw = new StringWriter(); | ||
var rr = new RoundtripRenderer(sw); | ||
|
||
rr.Write(markdownDocument); | ||
|
||
Assert.AreEqual(expected, sw.ToString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use TestRoundtrip.TestSpec
instead?
/// </summary> | ||
/// <param name="pipeline">The pipeline.</param> | ||
/// <returns>he modified pipeline</returns> | ||
public static MarkdownPipelineBuilder EnableTrackTrivia(this MarkdownPipelineBuilder pipeline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static MarkdownPipelineBuilder EnableTrackTrivia(this MarkdownPipelineBuilder pipeline) | |
public static MarkdownPipelineBuilder TrackTrivia(this MarkdownPipelineBuilder pipeline) |
/// <summary> | ||
/// True to parse trivia such as whitespace, extra heading characters and unescaped | ||
/// string values. | ||
/// </summary> | ||
public bool TrackTrivia { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <summary> | |
/// True to parse trivia such as whitespace, extra heading characters and unescaped | |
/// string values. | |
/// </summary> | |
public bool TrackTrivia { get; set; } | |
internal bool TrackTrivia { get; } |
MarkdownPipeline
should have no way of changing after creation.
/// string values. | ||
/// </summary> | ||
public bool TrackTrivia { get; set; } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being used at all? I assume it can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments.
There's a few outstanding comments that should also be resolved
#481 (comment)
#481 (comment) (missing Or
)
#481 (comment)
#481 (comment)
Newline.cs
should be renamed to NewLine.cs
, NoBlocksFoundBlock.cs
to EmptyBlock.cs
src/Markdig/Renderers/Roundtrip/Inlines/LineBreakInlineRenderer.cs
Outdated
Show resolved
Hide resolved
Thanks for taking a look again, MihaZupan! There were quite some small things I could fix for the better. Let's merge this one :) |
It's merged! Thanks for all the massive work @generateui that you put on this PR, really appreciated. 👍 |
w00t! It was a fun and lengthy challenge. Thanks for your collab, @xoofx and @MihaZupan! |
Implements a CST aka LST (Complete Syntax Tree aka Lossless Syntax Tree).
Please keep the following in mind:
As such, this is a very modest first attempt to learn if a CST can be implemented in markdig while keeping the current focus on performance. I'd be happy to hear feedback about
Any feedback is highly appreciated.
For context, the usecase for this is creating bots that automatically enhance and fix markdown documentation. Think creating links automatically, fixing links automatically, inserting generated blocks of markdown code, et cetera. This requires a markdown renderer that does not change any input markdown as much as possible in the output markdown.