Skip to content

Commit

Permalink
Don't handle line highlights unless there's actually line highlights f…
Browse files Browse the repository at this point in the history
…ixes #4802
  • Loading branch information
KyleAMathews committed Apr 3, 2018
1 parent fd7676e commit 055c1de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Object {
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"custom-js\\"><code class=\\"custom-js\\"><span class=\\"token comment\\">// Fake</span>
</code></pre>
<pre class=\\"custom-js\\"><code class=\\"custom-js\\"><span class=\\"token comment\\">// Fake</span></code></pre>
</div>",
},
],
Expand Down Expand Up @@ -110,8 +109,7 @@ Object {
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"language-js\\"><code class=\\"language-js\\"><span class=\\"token comment\\">// Fake</span>
</code></pre>
<pre class=\\"language-js\\"><code class=\\"language-js\\"><span class=\\"token comment\\">// Fake</span></code></pre>
</div>",
},
],
Expand Down Expand Up @@ -151,8 +149,7 @@ Object {
},
},
"type": "html",
"value": "<code class=\\"language-css\\"><span class=\\"token selector\\">.foo</span> <span class=\\"token punctuation\\">{</span> <span class=\\"token property\\">color</span><span class=\\"token punctuation\\">:</span> red <span class=\\"token punctuation\\">}</span>
</code>",
"value": "<code class=\\"language-css\\"><span class=\\"token selector\\">.foo</span> <span class=\\"token punctuation\\">{</span> <span class=\\"token property\\">color</span><span class=\\"token punctuation\\">:</span> red <span class=\\"token punctuation\\">}</span></code>",
},
],
"position": Position {
Expand Down Expand Up @@ -262,8 +259,7 @@ Object {
},
},
"type": "html",
"value": "<code class=\\"language-javascript\\">Fake
</code>",
"value": "<code class=\\"language-javascript\\">Fake</code>",
},
],
"position": Position {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-remark-prismjs/src/highlight-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (language, code, lineNumbersHighlight = []) => {
const lang = Prism.languages[language]

let highlightedCode = Prism.highlight(code, lang)
if (lineNumbersHighlight) {
if (lineNumbersHighlight.length > 0) {
const codeSplits = highlightedCode.split(`\n`).map((split, i) => {
if (_.includes(lineNumbersHighlight, i + 1)) {
return {
Expand Down

0 comments on commit 055c1de

Please sign in to comment.