-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Diff: Added support for syntax highlighting inside diffs #1889
Diff: Added support for syntax highlighting inside diffs #1889
Conversation
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, '&'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, after #1844, Prism.util.encode(…)
will only know how to deal with strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in #1898.
This PR adds support for syntax highlighting inside diffs.
Instead of using
language-diff
, it is now possible to uselanguage-diff-xxxx
highlight 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-check
andbefore-tokenize
hooks.)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.