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 authored and vhf committed Aug 10, 2018
1 parent 5e28adf commit bee1f54
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// 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><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>
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 = ['````latex',
'\\usepackage{inputenc}[utf8]',
'\\begin{document}',
'\\texttt{code}',
'\\end{document}',
'```'].join('\n')
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 @@ -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",
Expand Down

0 comments on commit bee1f54

Please sign in to comment.