Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jon-sully
Copy link

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:

image

To a cleaner, full line-length highlighted alternative:

image

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 to gatsby-browser, the resulting visual is the same as current)

Related Issues

Fixes #20630

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 19, 2021
Enabled a config param to the remark-prism plugin that allows Diff code blocks
to have the entire diff'd line be highlighted
@jon-sully jon-sully force-pushed the add-show-diff-highlights-configuration branch from 0a1341d to 374dfbc Compare April 19, 2021 18:40
@vladar vladar added topic: remark/mdx Related to Markdown, remark & MDX ecosystem and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Apr 19, 2021
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL!

Copy link
Author

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 😀

@stephencweiss
Copy link
Contributor

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.

@jon-sully
Copy link
Author

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.

image

@LekoArts LekoArts changed the title Expose Full Line-Length Diff Highlighting feat(gatsby-remark-prismjs): Expose Full Line-Length Diff Highlighting May 7, 2021
Copy link
Contributor

@LekoArts LekoArts left a 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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```js
```js:title=gatsby-browser.js
require("prismjs/themes/prism-solarizedlight.css") // Place the diff-highlight after your existing theme

Comment on lines +546 to +547
**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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**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

@iicdii
Copy link

iicdii commented Mar 2, 2022

Hi, any news??

@jon-sully
Copy link
Author

Hey @iicdii, thanks for the bump! I'd actually forgotten about this one. I'll jump back on it soon 🙂

@mmazzarolo
Copy link

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 gatsby-remark-prismjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: remark/mdx Related to Markdown, remark & MDX ecosystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[gatsby-remark-prismjs] diff with language / highlight
6 participants