Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix `gatsby-remark-prismjs` highlight bug #1921

Merged
merged 2 commits into from Aug 29, 2017

Conversation

@VincentBel
Copy link
Member

VincentBel commented Aug 26, 2017

Resolves #1917.

I use gatsby-dev-cli to test it in the demo repo, and it works now.

image

At first I forgot to clear the cache, and it drove me crazy. 馃樄

it(`also load the required language`, () => {
const language = `cpp`
const requiredLanguage = `c`
const Prism = require(`prismjs`)

This comment has been minimized.

Copy link
@VincentBel

VincentBel Aug 26, 2017

Author Member

I'd like to isolate the prismjs module for each test so that tests won't affect each other. But it seems no easy way. any ideas? @KyleAMathews

This comment has been minimized.

Copy link
@KyleAMathews

KyleAMathews Aug 28, 2017

Contributor

Eh, dunno. Not enough of a Jest expert to know how to do this.

This comment has been minimized.

Copy link
@KyleAMathews

This comment has been minimized.

Copy link
@KyleAMathews

KyleAMathews Aug 28, 2017

Contributor

jest.resetModules()

This comment has been minimized.

Copy link
@VincentBel

VincentBel Aug 29, 2017

Author Member

@KyleAMathews Works great! and it's ready to review now.

@gatsbybot

This comment has been minimized.

Copy link
Contributor

gatsbybot commented Aug 26, 2017

Deploy preview ready!

Built with commit 67be0b6

https://deploy-preview-1921--using-drupal.netlify.com

@gatsbybot

This comment has been minimized.

Copy link
Contributor

gatsbybot commented Aug 26, 2017

Deploy preview ready!

Built with commit 67be0b6

https://deploy-preview-1921--gatsbygram.netlify.com

@gatsbybot

This comment has been minimized.

Copy link
Contributor

gatsbybot commented Aug 26, 2017

Deploy preview ready!

Built with commit f1b02d0

https://deploy-preview-1921--gatsbygram.netlify.com

@gatsbybot

This comment has been minimized.

Copy link
Contributor

gatsbybot commented Aug 26, 2017

Deploy preview ready!

Built with commit 1f8240f

https://deploy-preview-1921--using-drupal.netlify.com

VincentBel added 2 commits Aug 26, 2017
If language has dependencies, should load dependencies first.
e.g. cpp depends on c, should load c first.
@VincentBel VincentBel force-pushed the VincentBel:prismjs-highlight-bug branch from 1f8240f to f1b02d0 Aug 29, 2017
@@ -1,5 +1,4 @@
const parseLineNumberRange = require(`../parse-line-number-range`)
const highlightCode = require(`../highlight-code`)

describe(`highlight code and lines with PrismJS`, () => {
it(`parses numeric ranges from the languages variable`, () => {

This comment has been minimized.

Copy link
@VincentBel

VincentBel Aug 29, 2017

Author Member

@KyleAMathews Besides, I think these tests are some as:

it(`parses numeric ranges from the languages variable`, () => {
expect(parseLineNumberRange(`jsx{1,5,7-8}`).highlightLines).toEqual([
1,
5,
7,
8,
])
expect(parseLineNumberRange(`javascript{7-8}`).highlightLines).toEqual([
7,
8,
])
expect(parseLineNumberRange(`javascript{7..8}`).highlightLines).toEqual([
7,
8,
])
expect(parseLineNumberRange(`javascript{2}`).highlightLines).toEqual([2])
expect(parseLineNumberRange(`javascript{2,4-5}`).highlightLines).toEqual([
2,
4,
5,
])
})
it(`ignores negative numbers`, () => {
expect(parseLineNumberRange(`jsx{-1,1,5,7-8}`).highlightLines).toEqual([
1,
5,
7,
8,
])
expect(parseLineNumberRange(`jsx{-1..4}`).highlightLines).toEqual([
1,
2,
3,
4,
])
})
it(`handles bad inputs`, () => {
expect(parseLineNumberRange(`jsx{-1`).highlightLines).toEqual([])
expect(parseLineNumberRange(`jsx{-1....`).highlightLines).toEqual([])
})

Why duplicate here?

This comment has been minimized.

Copy link
@KyleAMathews

KyleAMathews Aug 29, 2017

Contributor

If there's duplicates, feel free to PR them away!

@KyleAMathews

This comment has been minimized.

Copy link
Contributor

KyleAMathews commented Aug 29, 2017

Thanks! Merging!

@KyleAMathews KyleAMathews merged commit ae18f24 into gatsbyjs:master Aug 29, 2017
0 of 3 checks passed
0 of 3 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
deploy/netlify Deploy preview failed.
Details
@VincentBel VincentBel deleted the VincentBel:prismjs-highlight-bug branch Aug 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can鈥檛 perform that action at this time.