-
Notifications
You must be signed in to change notification settings - Fork 10.3k
feat(gatsby-remark-prismjs): Expose Full Line-Length Diff Highlighting #30939
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
base: master
Are you sure you want to change the base?
feat(gatsby-remark-prismjs): Expose Full Line-Length Diff Highlighting #30939
Conversation
Enabled a config param to the remark-prism plugin that allows Diff code blocks to have the entire diff'd line be highlighted
0a1341d
to
374dfbc
Compare
…hlights-configuration
@@ -392,12 +399,28 @@ unless explicitly overridden by the `promptUser` and `promptHost` options in the | |||
|
|||
### Diff code blocks | |||
|
|||
You can specify language for `diff` code blocks by using `diff-[language]` to enable syntax highlighting in diffs: | |||
You can specify language for `diff` code blocks by using `diff-[language]` to enable syntax highlighting in diffs. Canonically, when writing code _diffs_, the code should be indented by two characters. If the code is being changed, the first character should be a `+`, `-`, or `!` otherwise left a space. The second character should always be a space. Git-style file-location coordinates need not be indented. |
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.
TIL!
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.
You and me both! I Knew the + - but Prism implements ! — not sure if that's a Prism specific thing, and depending on your Prism theme it can be pretty subtle (not exactly the 'exclamation mark' kind of effect I'd hope for) but it is there so I figured I should call it out 😀
I don't think I'm qualified to actually review whether this works or not (and unfortunately, it looks like there's a failing test), but I'm so excited for this to land! @jon-sully - 1. thank you! 2. please let me know how I can help with the tests. |
Thanks for the kind words! Happy to help :) It's running great on my blog so I'll be excited to see it go live (hopefully!). I don't think there are actually any failing tests and I did run the test suite locally with no failures; the CircleCI build is unfortunately failing for what seems like completely tangential reasons? Not sure why that would be happening, but may request maintainer support on that. |
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.
Some minor changes needed to the text portion. Thanks for the PR!
```` | ||
|
||
The default rendering style for diff code blocks will be a colored `+` or `-` symbol and _not_ full line-length highlighting. This is depicted in the **first** example here: https://prismjs.com/plugins/diff-highlight/ | ||
|
||
This plugin supports a configuration parameter, `showDiffHighlight`, which will add full line-length highlighting to _all_ Diff code blocks used by your Gatsby site with the format: `+` -> Highlight green, `-` -> highlight red, and `!` -> bolded line. Simply pass the configuration parameter with `true` and add the following to your `gatsby-browser.js` (_after_ the require for your chosen theme): |
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.
This plugin supports a configuration parameter, `showDiffHighlight`, which will add full line-length highlighting to _all_ Diff code blocks used by your Gatsby site with the format: `+` -> Highlight green, `-` -> highlight red, and `!` -> bolded line. Simply pass the configuration parameter with `true` and add the following to your `gatsby-browser.js` (_after_ the require for your chosen theme): | |
This plugin supports a configuration parameter, `showDiffHighlight`, which will add full line-length highlighting to all diff code blocks used by your Gatsby site with the format: | |
- `+` will highlight green | |
- `-` will highlight red | |
- `!` will bolded the line | |
Use `showDiffHighlight: true` inside `gatsby-config.js` and add the following to your `gatsby-browser.js` (after the require for your chosen theme): |
```` | ||
|
||
The default rendering style for diff code blocks will be a colored `+` or `-` symbol and _not_ full line-length highlighting. This is depicted in the **first** example here: https://prismjs.com/plugins/diff-highlight/ |
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.
The default rendering style for diff code blocks will be a colored `+` or `-` symbol and _not_ full line-length highlighting. This is depicted in the **first** example here: https://prismjs.com/plugins/diff-highlight/ | |
The default rendering style for diff code blocks will be a colored `+` or `-` symbol and not full line-length highlighting. This is depicted in the first example here: https://prismjs.com/plugins/diff-highlight/ |
We try to use the formatting sparingly and this seems a bit too much :)
@@ -392,12 +399,28 @@ unless explicitly overridden by the `promptUser` and `promptHost` options in the | |||
|
|||
### Diff code blocks | |||
|
|||
You can specify language for `diff` code blocks by using `diff-[language]` to enable syntax highlighting in diffs: | |||
You can specify language for `diff` code blocks by using `diff-[language]` to enable syntax highlighting in diffs. Canonically, when writing code _diffs_, the code should be indented by two characters. If the code is being changed, the first character should be a `+`, `-`, or `!` otherwise left a space. The second character should always be a space. Git-style file-location coordinates need not be indented. |
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.
You can specify language for `diff` code blocks by using `diff-[language]` to enable syntax highlighting in diffs. Canonically, when writing code _diffs_, the code should be indented by two characters. If the code is being changed, the first character should be a `+`, `-`, or `!` otherwise left a space. The second character should always be a space. Git-style file-location coordinates need not be indented. | |
You can specify language for `diff` code blocks by using `diff-[language]` to enable syntax highlighting in diffs. Canonically, when writing code diffs, the code should be indented by two characters. If the code is being changed, the first character should be a `+`, `-`, or `!` otherwise left a space. The second character should always be a space. Git-style file-location coordinates need not be indented. |
|
||
This plugin supports a configuration parameter, `showDiffHighlight`, which will add full line-length highlighting to _all_ Diff code blocks used by your Gatsby site with the format: `+` -> Highlight green, `-` -> highlight red, and `!` -> bolded line. Simply pass the configuration parameter with `true` and add the following to your `gatsby-browser.js` (_after_ the require for your chosen theme): | ||
|
||
```js |
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.
```js | |
```js:title=gatsby-browser.js | |
require("prismjs/themes/prism-solarizedlight.css") // Place the diff-highlight after your existing theme |
**NOTE:** This is _not_ the same as the Diff code-block full line-length | ||
highlighting for diff'd lines. Those "line highlights" work great beyond |
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.
**NOTE:** This is _not_ the same as the Diff code-block full line-length | |
highlighting for diff'd lines. Those "line highlights" work great beyond | |
**Note:** This is not the same as the `showDiffHighlight` option for diff'd lines. Those "line highlights" work great beyond |
Hi, any news?? |
Hey @iicdii, thanks for the bump! I'd actually forgotten about this one. I'll jump back on it soon 🙂 |
FYI, this PR is still working fine on the latest versions of Gatsby. I wrote a blog post about the patch I'm using to apply it to the latest release of |
Description
@stephencweiss puts the issue fairly succinctly in this comment and the next
This PR aims to fix the issue of not only supporting diff languages but also supporting the last step of adding the
diff-highlight
class to the code blocks which, along with Prisms stylesheet, will take the best-supported diff-viewing-experience currently available:To a cleaner, full line-length highlighted alternative:
Documentation
Updated the README for the newly exposed configuration open. I defaulted it to
false
although I don't think there's any backwards compatibility immediately broken if set to true (without adding the stylesheet togatsby-browser
, the resulting visual is the same as current)Related Issues
Fixes #20630