GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add renderer producing Markdown (CommonMark) by robinst · Pull Request #306 · commonmark/commonmark-java

Conversation

@robinst

@robinst robinst commented Feb 9, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Adds a MarkdownRenderer that renders a Node 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.:

  • Parse some input Markdown, modify the nodes (AST), then render back to Markdown
  • Create a Node tree via code and then render that to Markdown

The 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).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
robinst added 30 commits January 17, 2024 16:54
@robinst
Beginnings of a MarkdownRenderer
9ec3935
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.
@robinst
Code spans
b25b7ea
@robinst
Add test that renders the spec examples through Markdown
aa7ac8b
@robinst
Count how many examples pass/fail
bd8fa6a
@robinst
Emphasis and strong emphasis
25abdad
@robinst
Line breaks
3e99b48
@robinst
Links and images
43006b2
@robinst
HTML blocks and inlines
88c767a
@robinst
Block quotes
e4ced9b
@robinst
Indented code blocks
f640e94
@robinst
Fenced code blocks
31e3664
@robinst
Lists (not tight lists yet)
bbde769
@robinst
Percent encode URLs in spec test (like in other spec tests)
b82d7ce
@robinst
Fix code spans with spaces
d0e89f4
@robinst
Escape special characters in normal text
a4eecb5
@robinst
Fix empty fenced code blocks
9f7d949
@robinst
Tight lists
29145aa
@robinst
Preserve indent and content indent for lists
8171519
Makes use of #303 which was split out.
@robinst
Fix empty list items
41eeede
@robinst
Fix tight list with nested loose list
12ce6bc
@robinst
Print failing cases
6417d01
@robinst
Don't discard trailing empty lines in code blocks
26ac7e1
@robinst
Use Setext heading if necessary
724619b
@robinst
Test tabs properly
02670c9
@robinst
Write HTML block in lines to make use of prefix
4918d64
@robinst
Escape special characters at beginning of line
db5f055
@robinst
Escape # in headings too
64d163d
@robinst
Disregard prefixes for line start logic
f5b04ef
@robinst
Escape whitespace too (weird)
59d5c03
@robinst
Reorder methods in spec order
37e507a
robinst added 13 commits January 29, 2024 17:30
@robinst
Some more comments
edfc3d0
@robinst
Reorder methods in writer, add comments
08a60f1
@robinst
Tables extension markdown renderer
e6c82d5
@robinst
Change isTight/setTight to use push/pop pattern like other settings
d726f72
@robinst
Use tight blocks to render tables
aaf18a2
@robinst
Rename file
01a52bc
@robinst
Strikethrough markdown renderer
a490fae
@robinst
Add getSpecialCharacters for escaping of extension characters
981d236
@robinst
Use getSpecialCharacters for table extension too
64eafc4
@robinst
Ins extensions markdown renderer
2966df1
@robinst
Use parsed delimiter for emphasis if available
0c5ad6e
@robinst
Add integration test for multiple extensions
5a0960f
@robinst
Fix thematic break and list items
114956a
@codecov-commenter

codecov-commenter commented Feb 9, 2024 •
edited by codecov Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 97.97571% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 94.81%. Comparing base (85f043e) to head (94eb5ff).
Report is 5 commits behind head on main.

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     
Files Coverage Δ
...ommonmark/ext/gfm/strikethrough/Strikethrough.java 100.00% <100.00%> (ø)
.../ext/gfm/strikethrough/StrikethroughExtension.java 100.00% <100.00%> (ø)
...ough/internal/StrikethroughDelimiterProcessor.java 91.30% <100.00%> (+0.39%) ⬆️
...gh/internal/StrikethroughMarkdownNodeRenderer.java 100.00% <100.00%> (ø)
.../java/org/commonmark/ext/gfm/tables/TableCell.java 100.00% <ø> (ø)
...org/commonmark/ext/gfm/tables/TablesExtension.java 100.00% <100.00%> (ø)
...main/java/org/commonmark/ext/ins/InsExtension.java 100.00% <100.00%> (ø)
...mark/ext/ins/internal/InsMarkdownNodeRenderer.java 100.00% <100.00%> (ø)
...ava/org/commonmark/internal/util/AsciiMatcher.java 92.00% <100.00%> (+3.76%) ⬆️
...commonmark/renderer/markdown/MarkdownRenderer.java 100.00% <100.00%> (ø)
... and 3 more

... and 3 files with indirect coverage changes

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

robinst added 2 commits February 15, 2024 18:19
@robinst
Documentation
979d2f6
@robinst
Add test for hard line break in heading
94eb5ff
@robinst
robinst marked this pull request as ready for review February 24, 2024 00:24
@robinst
robinst merged commit 870be81 into main Feb 24, 2024
@robinst
robinst deleted the markdown-renderer branch February 24, 2024 00:27
@robinst robinst mentioned this pull request Mar 12, 2024
Add literals holding original text to ThematicBreak and HardLineBreak #295
Closed
@robinst

robinst commented Mar 15, 2024

Copy link
Copy Markdown
Collaborator Author

Released in 0.22.0 now: https://github.com/commonmark/commonmark-java/blob/main/CHANGELOG.md#0220---2024-03-15

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@robinst robinst mentioned this pull request Mar 16, 2024
Add roundtrip parsing/rendering #212
Closed
@robinst robinst mentioned this pull request Apr 6, 2024
Add more information to Link nodes (for round-trip rendering) #98
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@robinst @codecov-commenter
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.