Make HTML rendering for nodes extensible (#35)#49
Merged
Conversation
We had `CustomHtmlRenderer` for custom nodes before. That was ok for that, but didn't allow clients to override rendering for core nodes. This introduces a new concept `NodeRenderer` (including factories, who doesn't like those?) that is also used for the core nodes. That allows overriding the rendering and allows to define the rendering for custom nodes at the same time. NodeRenderers have access to rendering configuration and functionality, such as extending attributes. That fixes the problem that the renderer for table nodes wasn't extensible via `AttributeProvider` (#31).
Now that there's an extra level of indirection, the stack requirements are higher. The test was failing on Java 7 but not on 8 because its default stack size is smaller.
| * @param nodeRendererFactory the factory for creating a node renderer | ||
| * @return {@code this} | ||
| */ | ||
| public Builder nodeRendererFactory(NodeRendererFactory nodeRendererFactory) { |
Collaborator
Author
There was a problem hiding this comment.
This is the new extension point. See also NodeRenderer and associated interfaces.
There was a problem hiding this comment.
Looks great! Overriding is simple and intuitive.
Collaborator
Author
There was a problem hiding this comment.
Cool, thanks for reviewing!
|
Could a new version be released with this change included? |
Collaborator
Author
|
@koesie10 I released 0.5.0 today with these and other changes included, see release notes: https://github.com/atlassian/commonmark-java/releases/tag/commonmark-parent-0.5.0 |
|
Great, thanks! |
This file contains hidden or 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
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.
We had
CustomHtmlRendererfor custom nodes before. That was ok forthat, but didn't allow clients to override rendering for core nodes.
This introduces a new concept
NodeRenderer(including factories, whodoesn't like those?) that is also used for the core nodes. That allows
overriding the rendering and allows to define the rendering for custom
nodes at the same time.
NodeRenderers have access to rendering configuration and functionality,
such as extending attributes. That fixes the problem that the renderer
for table nodes wasn't extensible via
AttributeProvider(#31).