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.
Hello @rexxars. Sorry for this PR a bit heavy but I tried to follow up on the ideas of #5 and updated your code to be able to handle custom renderers for every types.
A rendering function has therefore the following signature:
You can then pass your custom renderers likewise:
This has some collateral benefits: one can now very easily highlight code (without the lib imposing a precise method on him). I will probably, for instance, develop a code renderer using highlight.js on a project when have with @glenjamin.
Plus, node type solving is now
O(1)
, compared to theO(n)
switch statement and while the number of function calls has increased a bit, this should somewhat increase the renderer's performance.What still remains to be discussed with this solution however is what should be passed to the
allowNode
function.Here it is :). If you like it and find it suitable, I can also edit the PR to add some docs about custom rendering.