Support language-specific codefence renderers #534
+33
−1
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.
I was looking for a way to render Pikchr diagrams. I'm porting some code from Go where I used goldmark and the goldmark-pikchr extension which support this through fenced code blocks.
I thought of different ways to support this:
Pikchr could be officially supported either generally or through a named feature. This would solve my particular need but isn't particularly extensible.
Implement
SyntaxHighlighterAdapter
and short-circuit the rendering of a particular language. The problem with this is that you can't opt out of the closing</code>
and</pre>
tags:comrak/src/html.rs
Line 644 in 8d30848
Pre-render certain
CodeBlock
nodes toHtmlBlock
. My one problem with this approach is that it ended up being more code than ideal and it didn't feel right.Allow a way to register language-specific renderers. I liked this the best and there's even some prior art in Add math support #366:
comrak/src/html.rs
Lines 575 to 576 in 8d30848
I would not be opposed to contributing Pikchr as a gated feature if it would be useful to others but I like adding the general capability to allow experimenting with it and other language-specific renderers.
Anyway, I opened this draft pull request so there's something concrete to discuss. If we agree that this is the preferred approach, I'll add tests, improve the documentation and address eventual feedback.