fix(gatsby-remark-prismjs): Handle diff-language styling issue #27659
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
PR #26525 provides the awesome functionality of handling syntax highlighting during diff highlighting. However, it does not handle all cases of, the language not been loaded yet. I fixed a test and snapshot for diff-highlighting to reproduce the bug.
When you applied the commit a2ecf98, it fails the test.
We can see the syntax highlighting is not applying to the newer test. Now, try the test after apply the following change.
Now the test passes. We can figure out it only is styled when the diff-language is already loaded because "highlightCode" doesn't load the diff-language.
Therefore, I added the statements calling load diff-language if it is possible. Also, I removed the duplication-checking statement (
if (!Prism.languages[language])
because theloadPrismLanguage
function already does itself.