Skip to content

Commit a0042e4

Browse files
authored
Add more syntax highlighting tests (#23085)
* Add more syntax highlighting tests * Add erb highlighting test * Test JS keyword highlighted
1 parent 2adb0bc commit a0042e4

1 file changed

Lines changed: 59 additions & 3 deletions

File tree

tests/unit/render-content.js

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,70 @@ describe('renderContent', () => {
186186
})
187187

188188
test('does syntax highlighting', async () => {
189-
const template = nl(`
189+
let template = nl(`
190190
\`\`\`js
191191
const example = true
192192
\`\`\`\`
193193
`)
194-
const html = await renderContent(template)
195-
const $ = cheerio.load(html, { xmlMode: true })
194+
let html = await renderContent(template)
195+
let $ = cheerio.load(html, { xmlMode: true })
196196
expect($.html().includes('<pre><code class="hljs language-js">')).toBeTruthy()
197+
expect($.html().includes('<span class="hljs-keyword">const</span>')).toBeTruthy()
198+
199+
template = nl(`
200+
\`\`\`erb
201+
<% @articles.each do |article| %>
202+
\`\`\`\`
203+
`)
204+
html = await renderContent(template)
205+
$ = cheerio.load(html, { xmlMode: true })
206+
expect($.html().includes('<pre><code class="hljs language-erb">')).toBeTruthy()
207+
expect($.html().includes('<span class="hljs-variable">@articles</span>')).toBeTruthy()
208+
209+
template = nl(`
210+
\`\`\`http
211+
POST / HTTP/2
212+
\`\`\`\`
213+
`)
214+
html = await renderContent(template)
215+
$ = cheerio.load(html, { xmlMode: true })
216+
expect($.html().includes('<pre><code class="hljs language-http">')).toBeTruthy()
217+
expect($.html().includes('<span class="hljs-keyword">POST</span>')).toBeTruthy()
218+
219+
template = nl(`
220+
\`\`\`groovy
221+
plugins {
222+
...
223+
id 'maven-publish'
224+
}
225+
\`\`\`\`
226+
`)
227+
html = await renderContent(template)
228+
$ = cheerio.load(html, { xmlMode: true })
229+
expect($.html().includes('<pre><code class="hljs language-groovy">')).toBeTruthy()
230+
expect(
231+
$.html().includes('<span class="hljs-string">&apos;maven-publish&apos;</span>')
232+
).toBeTruthy()
233+
234+
template = nl(`
235+
\`\`\`Dockerfile
236+
FROM alpine:3.10
237+
\`\`\`\`
238+
`)
239+
html = await renderContent(template)
240+
$ = cheerio.load(html, { xmlMode: true })
241+
expect($.html().includes('<pre><code class="hljs language-Dockerfile">')).toBeTruthy()
242+
expect($.html().includes('<span class="hljs-keyword">FROM</span>')).toBeTruthy()
243+
244+
template = nl(`
245+
\`\`\`Powershell
246+
$resourceGroupName = "octocat-testgroup"
247+
\`\`\`\`
248+
`)
249+
html = await renderContent(template)
250+
$ = cheerio.load(html, { xmlMode: true })
251+
expect($.html().includes('<pre><code class="hljs language-Powershell">')).toBeTruthy()
252+
expect($.html().includes('<span class="hljs-variable">$resourceGroupName</span>')).toBeTruthy()
197253
})
198254

199255
test('does not autoguess code block language', async () => {

0 commit comments

Comments
 (0)