Diff: Added support for syntax highlighting inside diffs#1889
Merged
RunDevelopment merged 14 commits intoPrismJS:masterfrom Jul 21, 2019
Merged
Diff: Added support for syntax highlighting inside diffs#1889RunDevelopment merged 14 commits intoPrismJS:masterfrom
RunDevelopment merged 14 commits intoPrismJS:masterfrom
Conversation
ExE-Boss
reviewed
May 25, 2019
RunDevelopment
commented
May 25, 2019
components/prism-diff.js
Outdated
| var content = env.content.replace(HTML_TAG, ''); // remove all HTML tags | ||
|
|
||
| /** @type {string} */ | ||
| var decoded = content.replace(/</g, '<').replace(/&/g, '&'); |
Member
Author
There was a problem hiding this comment.
I wrote the same code in another PR (can't remember which one), so maybe we should move this line to something like Prism.util.decode as an inverse function to encode (ignoring that encode can deal with more than only strings).
Contributor
There was a problem hiding this comment.
Well, after #1844, Prism.util.encode(…) will only know how to deal with strings.
mAAdhaTTah
reviewed
Jul 18, 2019
RunDevelopment
commented
Jul 21, 2019
RunDevelopment
commented
Jul 21, 2019
mAAdhaTTah
reviewed
Jul 21, 2019
mAAdhaTTah
approved these changes
Jul 21, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds support for syntax highlighting inside diffs.
Instead of using
language-diff, it is now possible to uselanguage-diff-xxxxhighlight in a specific language. If you call the highlighting function directly usePrism.highlight(code, Prism.languages.diff, 'diff-' + diffLanguage).To be compatible with other plugins that need access to the language-specific diff grammar, a new alias for every diff-variant will be created during run-time. (See the
before-sanity-checkandbefore-tokenizehooks.)Before
After
Slightly tweaked CSS
Known issues
If the attributes of the highlighted embedded code contain line breaks, incorrect HTML code is generated.FixedE.g. a multiline comment spanning multiple lines, one of which has been modified.
If other plugins add tags to the HTML of a block, that block won't be highlighted. I.e. the show Invisibles plugin adds nested tokens which generate tokens (and later tags) inside the blocks.Fixeddiff-xxxx-pattern is incompatible with auto loader.This PR resolves #1878.