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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zmarkdown: highlight latex and keep console as plainText #264

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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