feat(gatsby-remark-prismjs): syntax highlighting inside diffs #26525
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.
Description
This feature provides support for syntax highlighting inside diffs. In the last example shown on the Diff Highlight page of the Prism documentation, it demonstrates that within a diff code block, Prism is capable of highlighting the syntax in a specific language. See below snapshot to quickly preview what this feature does:
Currently, this is not supported by the
gatsby-remark-prismjs
plugin. There was an issue about this missing feature, but it eventually closed due to inactivity.To support this feature, the modifications were minor:
diff-xxxx
pattern (xxxx
is a language such asjs
orjavascript
).className
to allowlanguage-diff-xxxx
ifdiff-xxxx
is specified as the language identifier of the code block.prism-diff-highlight.js
plugin. It only adds hooks (the same hooks ran byPrism.highlight
) to Prism. Unlike theprism-line-highlight
andprism-line-numbers
plugins, there is no reference to thewindow
object within the scope of the plugin's IIFE, etc. Using thePrism.highlight
method, it highlights the syntax inside diffs if the grammar is specified asdiff
and the language is specified asdiff-xxxx
:Prism.highlight(code, Prism.languages.diff, 'diff-' + diffLanguage)
.highlightCode()
to accept an argument (diffLanguage
) for the syntax highlighting language ifdiff-xxxx
is specified as the language identifier of the code block.Documentation
Based on how issue #20630 was raised, other developers might also assume that this feature is automatically supported out-of-the-box by the plugin.
If documentation for this feature is needed, then feel free to let me know and I'll add it. I think it can be written in the Usage in Markdown section, but I'm not 100% certain if it belongs there or if a new section should be devoted to this.
Related Issues
Fixes #20630