1
0
mirror of synced 2025-12-19 18:10:59 -05:00

Add more syntax highlighting tests (#23085)

* Add more syntax highlighting tests

* Add erb highlighting test

* Test JS keyword highlighted
This commit is contained in:
Robert Sese
2021-11-24 11:30:29 -06:00
committed by GitHub
parent 2adb0bc626
commit a0042e40a3

View File

@@ -186,14 +186,70 @@ describe('renderContent', () => {
}) })
test('does syntax highlighting', async () => { test('does syntax highlighting', async () => {
const template = nl(` let template = nl(`
\`\`\`js \`\`\`js
const example = true const example = true
\`\`\`\` \`\`\`\`
`) `)
const html = await renderContent(template) let html = await renderContent(template)
const $ = cheerio.load(html, { xmlMode: true }) let $ = cheerio.load(html, { xmlMode: true })
expect($.html().includes('<pre><code class="hljs language-js">')).toBeTruthy() expect($.html().includes('<pre><code class="hljs language-js">')).toBeTruthy()
expect($.html().includes('<span class="hljs-keyword">const</span>')).toBeTruthy()
template = nl(`
\`\`\`erb
<% @articles.each do |article| %>
\`\`\`\`
`)
html = await renderContent(template)
$ = cheerio.load(html, { xmlMode: true })
expect($.html().includes('<pre><code class="hljs language-erb">')).toBeTruthy()
expect($.html().includes('<span class="hljs-variable">@articles</span>')).toBeTruthy()
template = nl(`
\`\`\`http
POST / HTTP/2
\`\`\`\`
`)
html = await renderContent(template)
$ = cheerio.load(html, { xmlMode: true })
expect($.html().includes('<pre><code class="hljs language-http">')).toBeTruthy()
expect($.html().includes('<span class="hljs-keyword">POST</span>')).toBeTruthy()
template = nl(`
\`\`\`groovy
plugins {
...
id 'maven-publish'
}
\`\`\`\`
`)
html = await renderContent(template)
$ = cheerio.load(html, { xmlMode: true })
expect($.html().includes('<pre><code class="hljs language-groovy">')).toBeTruthy()
expect(
$.html().includes('<span class="hljs-string">&apos;maven-publish&apos;</span>')
).toBeTruthy()
template = nl(`
\`\`\`Dockerfile
FROM alpine:3.10
\`\`\`\`
`)
html = await renderContent(template)
$ = cheerio.load(html, { xmlMode: true })
expect($.html().includes('<pre><code class="hljs language-Dockerfile">')).toBeTruthy()
expect($.html().includes('<span class="hljs-keyword">FROM</span>')).toBeTruthy()
template = nl(`
\`\`\`Powershell
$resourceGroupName = "octocat-testgroup"
\`\`\`\`
`)
html = await renderContent(template)
$ = cheerio.load(html, { xmlMode: true })
expect($.html().includes('<pre><code class="hljs language-Powershell">')).toBeTruthy()
expect($.html().includes('<span class="hljs-variable">$resourceGroupName</span>')).toBeTruthy()
}) })
test('does not autoguess code block language', async () => { test('does not autoguess code block language', async () => {