-
Notifications
You must be signed in to change notification settings - Fork 289
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
Add renderer producing Markdown (CommonMark) #306
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Structure mostly copied from TextContentRenderer (for extension related bits). Started with leaf blocks (in spec order), but probably good to do some inlines too before going too far down all the blocks. Also, container blocks might be the most interesting.
Makes use of #303 which was split out.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #306 +/- ##
============================================
+ Coverage 94.30% 94.81% +0.50%
- Complexity 227 252 +25
============================================
Files 124 130 +6
Lines 3633 4124 +491
Branches 549 606 +57
============================================
+ Hits 3426 3910 +484
- Misses 104 106 +2
- Partials 103 108 +5
|
Released in 0.22.0 now: https://github.com/commonmark/commonmark-java/blob/main/CHANGELOG.md#0220---2024-03-15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a
MarkdownRenderer
that renders aNode
tree to CommonMark Markdown. Supports all core nodes as well as "gfm-strikethrough", "gfm-tables" and "ins" extensions. This is very useful for applications that want to produce Markdown, e.g.:Node
tree via code and then render that to MarkdownThe goal is that
Node tree -> render to Markdown -> parse to Node tree
results in an equivalent Node tree. That is verified with all the examples from the spec and some manual test cases.However it does not mean that a
Markdown -> parse to Node tree -> render to Markdown
round-trip produces the same Markdown as the original. The parse step does not preserve enough detail for that yet, e.g. things like insignificant whitespace or what characters were escaped.See #12.
In the future, we can make changes that preserve more details when parsing and make use of that to bring the rendered Markdown closer to the original. But the Markdown renderer can't rely on those extra details to work correctly, as that would break the use case where there is no parsing (when creating
Node
tree via code).