-
Notifications
You must be signed in to change notification settings - Fork 27
v3 #108
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
Merged
Merged
v3 #108
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e8712bd
Add concept of gutter cells
andrewbranch 00abb5a
Adjust rendering and styling
andrewbranch a926410
Finish layout, add test, make it work with line highlighting
andrewbranch d1f1e29
Fix copy and paste
andrewbranch 0bf5f92
Merge pull request #95 from andrewbranch/gutters
andrewbranch ab2c700
Update alpha publishing to point to v3 branch
andrewbranch 2d94be7
Update other v2 reference
andrewbranch cb774a2
Another 2
andrewbranch ffbfe2c
Add diff highlighting line transformer (#88)
janosh adb1ecd
Add GraphQL testing infrastructure
andrewbranch 6e77d7b
Update workflows and CONTRIBUTING.md
andrewbranch 326e278
Add missing proc.kill
andrewbranch b991180
Ignore tty message?
andrewbranch d9d7757
Remove meta from test query because apparently languageId isn’t stable
andrewbranch d954ccd
Totally ignore tty error
andrewbranch 71b79db
Update snapshot
andrewbranch d22f6db
Shallow checkout vscode
andrewbranch 844f98c
Merge pull request #98 from andrewbranch/graphql-testing
andrewbranch 315ced0
Merge branch 'master' into v3
andrewbranch 37eeb47
Pick a reasonable default for line highlight color based on theme bac…
andrewbranch 2436e75
Officially deprecate `codeFenceNode`
andrewbranch 482a929
Add line number docs
andrewbranch 9feb604
Add diff highlighting docs
andrewbranch 6aa753b
Remove old `colorTheme` option
andrewbranch 952eba7
Update baselines
andrewbranch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
# Migration Guide | ||
|
||
## v2 → v3 | ||
|
||
### Line highlighting is visible without custom CSS. | ||
|
||
Previously, the default line highlight background color was `transparent`, which meant a color had to be set with a CSS variable by the user. The reason for this limitation was that there is no sensible default that works for both light themes and dark themes, as a light highlight would be invisible on white, and a dark highlight would be invisible on black. As of v3, the plugin the luminance of each theme’s background color and selects a translucent white or translucent black highlight color as a default. | ||
|
||
This is unlikely to break existing sites, as the CSS variables continue to work as a customization. However, as part of upgrading to v3, you may be able to remove the variables you set if you’re happy with the new defaults. If, for some reason, you were relying on the old behavior of an invisible default, sorry, don’t do that 🤷🏻♂️ | ||
|
||
### The `codeFenceNode` property of option callback arguments is deprecated. | ||
|
||
The `theme` and `wrapperClassName` plugin options accept a callback function that receives an object with a `codeFenceNode` containing the original Remark MDAST node for the code block currently being highlighted. That property has been renamed `node`. I’m like a million percent sure nobody uses this, but if I don’t say it here, someone will complain when I remove it in 4.0. | ||
|
||
## v1 → v2 | ||
|
||
### Extensions are no longer downloaded automatically. | ||
|
@@ -49,4 +61,4 @@ The new `theme` option also supports some options that `colorTheme` did not; you | |
|
||
### Known issues | ||
|
||
- Usage with [gatsby-plugin-mdx](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-mdx) requires [email protected] or later. | ||
- Usage with [gatsby-plugin-mdx](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-mdx) requires [email protected] or later. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ If you’re updating from v1.x.x to v2.x.x, see [MIGRATING.md](./MIGRATING.md). | |
- [Extra stuff](#extra-stuff) | ||
- [Inline code highlighting](#inline-code-highlighting) | ||
- [Line highlighting](#line-highlighting) | ||
- [Line numbers](#line-numbers) | ||
- [Diff highlighting](#diff-highlighting) | ||
- [Using different themes for different code fences](#using-different-themes-for-different-code-fences) | ||
- [Arbitrary code fence options](#arbitrary-code-fence-options) | ||
- [Options reference](#options-reference) | ||
|
@@ -199,7 +201,7 @@ The following languages and themes can be used without [installing third-party e | |
|
||
</details> | ||
|
||
Language names are resolve case-insensitively by any aliases and file extensions listed in the grammar’s metadata. For example, a code fence with C++ code in it can use [any of these language codes](https://github.com/Microsoft/vscode/blob/da3c97f3668393ebfcb9f8208d7616018d6d1859/extensions/cpp/package.json#L20-L21). You could also check the [built-in grammar manifest](https://unpkg.com/[email protected]/lib/grammars/manifest.json) for an exact list of mappings. | ||
Language names are resolved case-insensitively by any aliases and file extensions listed in the grammar’s metadata. For example, a code fence with C++ code in it can use [any of these language codes](https://github.com/Microsoft/vscode/blob/da3c97f3668393ebfcb9f8208d7616018d6d1859/extensions/cpp/package.json#L20-L21). You could also check the [built-in grammar manifest](https://unpkg.com/[email protected]/lib/grammars/manifest.json) for an exact list of mappings. | ||
|
||
### Themes | ||
|
||
|
@@ -357,6 +359,12 @@ See [`inlineCode`](#inlinecode) in the options reference for more API details. | |
|
||
`gatsby-remark-vscode` offers the same line-range-after-language-name strategy of highlighting or emphasizing lines as [gatsby-remark-prismjs](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-remark-prismjs): | ||
|
||
<table> | ||
<thead><tr><th>Markdown</th><th>Rendered result</th></thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
|
||
````md | ||
```js{1,3-5} | ||
this.isLine(1); // highlighted | ||
|
@@ -367,8 +375,24 @@ this.isLine(5); // highlighted | |
``` | ||
```` | ||
|
||
</td> | ||
<td> | ||
|
||
![][line-highlighting-meta] | ||
|
||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
Comment directives are also supported: | ||
|
||
<table> | ||
<thead><tr><th>Markdown</th><th>Rendered result</th></thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
|
||
````md | ||
```js | ||
function constant(value) { | ||
|
@@ -387,24 +411,114 @@ const zero = [0, 1, 2, 3, 4, 5] | |
``` | ||
```` | ||
|
||
You need to pick your own background color, and optionally a left border width and color, for the highlighted lines. This can be done by setting CSS variables: | ||
</td> | ||
<td> | ||
|
||
![][line-highlighting-comment] | ||
|
||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
You can customize the default background color and left border width and color for the highlighted lines by setting CSS variables: | ||
|
||
```css | ||
:root { | ||
--grvsc-line-highlighted-background-color: rgba(255, 255, 255, 0.2); /* default: transparent */ | ||
--grvsc-line-highlighted-border-color: rgba(255, 255, 255, 0.5); /* default: transparent */ | ||
--grvsc-line-highlighted-border-width: 2px; /* default: 4px */ | ||
--grvsc-line-highlighted-background-color: rgba(255, 255, 255, 0.2); | ||
--grvsc-line-highlighted-border-color: rgba(255, 255, 255, 0.5); | ||
--grvsc-line-highlighted-border-width: 2px; | ||
} | ||
``` | ||
|
||
or by setting custom styles on the lines: | ||
### Line numbers | ||
|
||
```css | ||
.grvsc-container .grvsc-line-highlighted { | ||
background-color: rgba(255, 255, 255, 0.2); | ||
box-shadow: inset 2px 0 0 0 rgba(255, 255, 255, 0.5); | ||
With code fence info: | ||
|
||
````md | ||
```js {numberLines} | ||
import * as React from 'react'; | ||
|
||
React.createElement('span', {}); | ||
``` | ||
```` | ||
|
||
![Rendered result of the example code above][line-numbering-with-code-fence-info] | ||
|
||
With code fence info specifying a starting line: | ||
|
||
````md | ||
```js {numberLines: 21} | ||
return 'blah'; | ||
``` | ||
```` | ||
|
||
![Rendered result of the example code above][line-numbering-starting-line] | ||
|
||
With a comment: | ||
|
||
````md | ||
```ts | ||
function getDefaultLineTransformers(pluginOptions, cache) { | ||
return [ | ||
one, // L4 | ||
two, | ||
three | ||
]; | ||
} | ||
``` | ||
```` | ||
|
||
![Rendered result of the example code above][line-numbering-with-a-comment] | ||
|
||
With both: | ||
|
||
````md | ||
```ts {numberLines} | ||
import * as React from 'react'; | ||
|
||
// ... | ||
|
||
function SomeComponent(props) { // L29 | ||
return <div />; | ||
} | ||
``` | ||
```` | ||
|
||
![Rendered result of the example code above][line-numbering-with-both] | ||
|
||
The line number cell’s styling can be overridden on the `.grvsc-line-number` class. | ||
|
||
### Diff highlighting | ||
|
||
You can combine syntax highlighting with diff highlighting: | ||
|
||
<table> | ||
<thead><tr><th>Markdown</th><th>Rendered result</th></thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
|
||
````md | ||
```ts {diff} | ||
function add(x, y) { | ||
- return x + x; | ||
+ return x + y; | ||
} | ||
``` | ||
```` | ||
|
||
</td> | ||
<td> | ||
|
||
![][diff-highlighting] | ||
|
||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
The highlight color can be customized with the CSS variables `--grvsc-line-diff-add-background-color` and `--grvsc-line-diff-del-background-color`. The default color is static and might not be accessible with all syntax themes. Consider contrast ratios and choose appropriate colors when using this feature. | ||
|
||
### Using different themes for different code fences | ||
|
||
|
@@ -424,10 +538,10 @@ Line numbers and ranges aren’t the only things you can pass as options on your | |
|
||
```js | ||
{ | ||
theme: ({ parsedOptions, language, markdownNode, codeFenceNode }) => { | ||
theme: ({ parsedOptions, language, markdownNode, node }) => { | ||
// 'language' is 'jsx', in this case | ||
// 'markdownNode' is the gatsby-transformer-remark GraphQL node | ||
// 'codeFenceNode' is the Markdown AST node of the current code fence | ||
// 'node' is the Markdown AST node of the current code fence | ||
// 'parsedOptions' is your parsed object that looks like this: | ||
// { | ||
// theme: 'Monokai', | ||
|
@@ -436,7 +550,7 @@ Line numbers and ranges aren’t the only things you can pass as options on your | |
// } | ||
return parsedOptions.theme || 'Dark+ (default dark)'; | ||
}, | ||
wrapperClassName: ({ parsedOptions, language, markdownNode, codeFenceNode }) => ''; | ||
wrapperClassName: ({ parsedOptions, language, markdownNode, node }) => ''; | ||
} | ||
``` | ||
|
||
|
@@ -550,3 +664,10 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for development instructions. | |
[templates-own]: https://user-images.githubusercontent.com/3277153/56853802-5e847e00-68c8-11e9-8468-dedcd8bcab78.png | ||
[solidity-others]: https://user-images.githubusercontent.com/3277153/56853799-5e847e00-68c8-11e9-8895-535d9e0d555c.png | ||
[solidity-own]: https://user-images.githubusercontent.com/3277153/56853800-5e847e00-68c8-11e9-9c83-5e76146d5e46.png | ||
[line-highlighting-meta]: https://user-images.githubusercontent.com/3277153/86545712-6fc21500-bee5-11ea-8a83-71d04f595ef4.png | ||
[line-highlighting-comment]: https://user-images.githubusercontent.com/3277153/86545710-6e90e800-bee5-11ea-9f4d-33278d9312d7.png | ||
[line-numbering-with-a-comment]: https://user-images.githubusercontent.com/3277153/87123264-3ff37400-c23b-11ea-8ae6-80cbfcf6b6a0.png | ||
[line-numbering-with-code-fence-info]: https://user-images.githubusercontent.com/3277153/87122757-5ea53b00-c23a-11ea-8fbc-c85917433345.png | ||
[line-numbering-with-both]: https://user-images.githubusercontent.com/3277153/87122755-5ea53b00-c23a-11ea-8fe8-144aea7aa952.png | ||
[line-numbering-starting-line]: https://user-images.githubusercontent.com/3277153/87122747-5c42e100-c23a-11ea-9a06-923c699c0a0b.png | ||
[diff-highlighting]: https://user-images.githubusercontent.com/3277153/87123984-aa58e400-c23c-11ea-87b3-3f66afcd795d.png |
Oops, something went wrong.
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.
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.
Missing verb here: "...the plugin the luminance of ..."