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 have tried for a while to use the line numbers plugin provided by Prism in Eleventy. But it's to heavily dependent on the browser so it's not possible.
Next I tried to create a plugin that could be used in plugin options for this one. But that also was unsuccessful because of the limited Prism hooks that are used by node.js.
So then I looked at original line numbers plugin and came up with this solution to add support in Eleventy.
The function
LineNumbers
tries to do the same as the original Prism plugin, it creates a<span>
with a span per line as children.Then I tweaked
markdownSyntaxHighlight.js
to use it and append the spans to the code.This works really good with the CSS from Prism:
Example:
I'm not sure if this is the best approach, and I'm not sure what the best way to make it optional is. But I figured it was easier to create this PR to show my solution. It would fix #10.