-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace class=language-* with data-language=* to avoid potential Prism bug * Remark Prism plugin now accepts useDataAttribute option Default behavior remains as before, to use a class='language-*' prefix. New behavior allows for a data-language=* alternate. Snapshot tests added. * Alternate, custom-class-prefix approach to fixing Prism+ReactLive bug * Added README note about new plugin option * Provided more context for the remark prism docs comment
- Loading branch information
1 parent
f79aa5c
commit d1b72df
Showing
5 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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
89 changes: 89 additions & 0 deletions
89
packages/gatsby-remark-prismjs/src/__tests__/__snapshots__/index.js.snap
This file contains 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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`remark prism plugin generates a <pre> tag with a custom class prefix if configured 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"lang": "js", | ||
"position": Position { | ||
"end": Object { | ||
"column": 4, | ||
"line": 3, | ||
"offset": 17, | ||
}, | ||
"indent": Array [ | ||
1, | ||
1, | ||
], | ||
"start": Object { | ||
"column": 1, | ||
"line": 1, | ||
"offset": 0, | ||
}, | ||
}, | ||
"type": "html", | ||
"value": "<div class=\\"gatsby-highlight\\"> | ||
<pre class=\\"custom-js\\"><code><span class=\\"token comment\\" spellcheck=\\"true\\">// Fake</span> | ||
</code></pre> | ||
</div>", | ||
}, | ||
], | ||
"position": Object { | ||
"end": Object { | ||
"column": 4, | ||
"line": 3, | ||
"offset": 17, | ||
}, | ||
"start": Object { | ||
"column": 1, | ||
"line": 1, | ||
"offset": 0, | ||
}, | ||
}, | ||
"type": "root", | ||
} | ||
`; | ||
exports[`remark prism plugin generates a <pre> tag with class="language-*" prefix by default 1`] = ` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"lang": "js", | ||
"position": Position { | ||
"end": Object { | ||
"column": 4, | ||
"line": 3, | ||
"offset": 17, | ||
}, | ||
"indent": Array [ | ||
1, | ||
1, | ||
], | ||
"start": Object { | ||
"column": 1, | ||
"line": 1, | ||
"offset": 0, | ||
}, | ||
}, | ||
"type": "html", | ||
"value": "<div class=\\"gatsby-highlight\\"> | ||
<pre class=\\"language-js\\"><code><span class=\\"token comment\\" spellcheck=\\"true\\">// Fake</span> | ||
</code></pre> | ||
</div>", | ||
}, | ||
], | ||
"position": Object { | ||
"end": Object { | ||
"column": 4, | ||
"line": 3, | ||
"offset": 17, | ||
}, | ||
"start": Object { | ||
"column": 1, | ||
"line": 1, | ||
"offset": 0, | ||
}, | ||
}, | ||
"type": "root", | ||
} | ||
`; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const remark = require(`remark`) | ||
const plugin = require(`../index`) | ||
|
||
describe(`remark prism plugin`, () => { | ||
it(`generates a <pre> tag with class="language-*" prefix by default`, () => { | ||
const code = '```js\n// Fake\n```' | ||
const markdownAST = remark.parse(code) | ||
plugin({ markdownAST }) | ||
expect(markdownAST).toMatchSnapshot() | ||
}) | ||
|
||
it(`generates a <pre> tag with a custom class prefix if configured`, () => { | ||
const code = '```js\n// Fake\n```' | ||
const markdownAST = remark.parse(code) | ||
plugin({ markdownAST }, { classPrefix: 'custom-' }) | ||
expect(markdownAST).toMatchSnapshot() | ||
}) | ||
}) |
This file contains 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