Skip to content

Commit

Permalink
zmarkdown: highlight latex and keep console as plainText
Browse files Browse the repository at this point in the history
  • Loading branch information
artragis committed Aug 9, 2018
1 parent 72e5965 commit 18d6d82
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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 as tex 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\\">\\\\</span></span>usepackage{inputenc}[utf8]
<span class=\\"hljs-tag\\">\\\\<span class=\\"hljs-name\\">\\\\</span></span>begin{document}
<span class=\\"hljs-tag\\">\\\\<span class=\\"hljs-name\\">\\\\</span></span>texttt{code}
<span class=\\"hljs-tag\\">\\\\<span class=\\"hljs-name\\">\\\\</span></span>end{document}
</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>
Expand Down
24 changes: 24 additions & 0 deletions packages/zmarkdown/__tests__/new-html-suite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,30 @@ describe('ping', () => {
})
})

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 as tex', () => {
const input = dedent `\`\`\`latex
\\usepackage{inputenc}[utf8]
\\begin{document}
\\texttt{code}
\\end{document}
\`\`\``
expect(renderString(input)).resolves.toMatchSnapshot()
})
afterEach(() => {
remarkConfig._test = true
})
})

describe('smileys', () => {
it(`translates >_<`, () => {
const input = 'This is funny >_<'
Expand Down
2 changes: 2 additions & 0 deletions packages/zmarkdown/config/remark.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const remarkConfig = {

rehypeHighlight: {
ignoreMissing: true,
plainText: ['console'],
aliases: {tex: ['latex']},
},

footnotesTitles: 'Retourner au texte de la note $id',
Expand Down
2 changes: 1 addition & 1 deletion packages/zmarkdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"rebber-plugins": "^1.4.5",
"rehype-autolink-headings": "^2.0.1",
"rehype-footnotes-title": "^0.0.25",
"rehype-highlight": "^2.0.1",
"rehype-highlight": "^2.2.0",
"rehype-html-blocks": "^0.0.26",
"rehype-katex": "^1.0.2",
"rehype-postfix-footnote-anchors": "^1.0.1",
Expand Down

0 comments on commit 18d6d82

Please sign in to comment.