Repository: zestedesavoir/zmarkdown
Pull request #265 (2018-08-10 12:36:21)

PR/264
#264 

FYI @artragis 


Patch:
diff --git a/packages/zmarkdown/config/remark.js b/packages/zmarkdown/config/remark.js
index da567fdd..c3489748 100644
--- a/packages/zmarkdown/config/remark.js
+++ b/packages/zmarkdown/config/remark.js
@@ -67,6 +67,8 @@ const remarkConfig = {
 
   rehypeHighlight: {
     ignoreMissing: true,
+    plainText: ['console'],
+    aliases: {tex: ['latex']},
   },
 
   footnotesTitles: 'Retourner au texte de la note $id',
diff --git a/packages/zmarkdown/package.json b/packages/zmarkdown/package.json
index f914ea6c..0ed0cf36 100644
--- a/packages/zmarkdown/package.json
+++ b/packages/zmarkdown/package.json
@@ -26,7 +26,7 @@
     "rebber-plugins": "^1.4.6",
     "rehype-autolink-headings": "^2.0.1",
     "rehype-footnotes-title": "^0.0.26",
-    "rehype-highlight": "^2.0.1",
+    "rehype-highlight": "^2.2.0",
     "rehype-html-blocks": "^0.0.27",
     "rehype-katex": "^1.0.2",
     "rehype-postfix-footnote-anchors": "^1.0.2",


Test patch:
diff --git a/packages/zmarkdown/__tests__/__snapshots__/new-html-suite.test.js.snap b/packages/zmarkdown/__tests__/__snapshots__/new-html-suite.test.js.snap
index face73a9..bf4f0675 100644
--- a/packages/zmarkdown/__tests__/__snapshots__/new-html-suite.test.js.snap
+++ b/packages/zmarkdown/__tests__/__snapshots__/new-html-suite.test.js.snap
@@ -1,5 +1,18 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
+exports[`code highlight special cases does not highlight console 1`] = `
+"<div class=\\"hljs-code-div\\"><div class=\\"hljs-line-numbers\\"><span></span></div><pre><code class=\\"language-console\\">echo \\"Hello world\\"
+</code></pre></div>"
+`;
+
+exports[`code highlight special cases highlights latex 1`] = `
+"<div class=\\"hljs-code-div\\"><div class=\\"hljs-line-numbers\\"><span></span><span></span><span></span><span></span></div><pre><code class=\\"hljs language-latex\\"><span class=\\"hljs-tag\\">\\\\<span class=\\"hljs-name\\">usepackage</span><span class=\\"hljs-string\\">{inputenc}</span><span class=\\"hljs-string\\">[utf8]</span></span>
+<span class=\\"hljs-tag\\">\\\\<span class=\\"hljs-name\\">begin</span><span class=\\"hljs-string\\">{document}</span></span>
+<span class=\\"hljs-tag\\">\\\\<span class=\\"hljs-name\\">texttt</span><span class=\\"hljs-string\\">{code}</span></span>
+<span class=\\"hljs-tag\\">\\\\<span class=\\"hljs-name\\">end</span><span class=\\"hljs-string\\">{document}</span></span>
+</code></pre></div>"
+`;
+
 exports[`images become figures: does not apply when a caption is present 1`] = `
 "<figure><img src=\\"http://example.com\\" alt=\\"foo\\"><figcaption>foo</figcaption></figure>
 <figure><img src=\\"http://example.com\\"><figcaption>Caption</figcaption></figure>
diff --git a/packages/zmarkdown/__tests__/new-html-suite.test.js b/packages/zmarkdown/__tests__/new-html-suite.test.js
index 19956503..d0cb26e0 100644
--- a/packages/zmarkdown/__tests__/new-html-suite.test.js
+++ b/packages/zmarkdown/__tests__/new-html-suite.test.js
@@ -279,3 +279,55 @@ describe('pedantic mode disabled', () => {
     return expect(renderString(input)).resolves.not.toContain('<em>')
   })
 })
+
+
+describe('code highlight special cases', () => {
+  beforeEach(() => {
+    remarkConfig._test = false
+  })
+
+  it('does not highlight console', () => {
+    const input = dedent `
+      \`\`\`console
+      echo "Hello world"
+      \`\`\`
+    `
+    expect(renderString(input)).resolves.toMatchSnapshot()
+  })
+
+  it('highlights latex', async () => {
+    const input = [
+      '```latex',
+      '\\usepackage{inputenc}[utf8]',
+      '\\begin{document}',
+      '\\texttt{code}',
+      '\\end{document}',
+      '```',
+    ]
+
+    const result1 = await renderString(input.join('\n'))
+    expect(result1).toMatchSnapshot()
+  })
+
+  it('highlights latex as tex', async () => {
+    const input = [
+      '```latex',
+      '\\usepackage{inputenc}[utf8]',
+      '\\begin{document}',
+      '\\texttt{code}',
+      '\\end{document}',
+      '```',
+    ]
+
+    const result1 = (await renderString(input.join('\n'))).replace('language-latex', '')
+
+    input[0] = '```tex'
+    const result2 = (await renderString(input.join('\n'))).replace('language-tex', '')
+
+    expect(result2).toBe(result1)
+  })
+
+  afterEach(() => {
+    remarkConfig._test = true
+  })
+})