Skip to content

Commit

Permalink
Add hljs class to inline code (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriangalliat committed Apr 11, 2022
1 parent e9b05d0 commit 799213d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default function core (md: MarkdownIt, opts?: HighlightOptions): void {

if (optsWithDefaults.inline) {
md.core.ruler.before('linkify', 'inline_code_language', inlineCodeLanguageRule)
md.renderer.rules.code_inline = inlineCodeRenderer
md.renderer.rules.code_inline = wrapCodeRenderer(inlineCodeRenderer)
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ describe('markdown-it-highlightjs', () => {
it('inline with Pandoc format', () => {
assert.equal(
md().use(highlightjs, { inline: true }).renderInline('`console.log(42)`{.js}'),
'<code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-number">42</span>)</code>'
'<code class="hljs language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-number">42</span>)</code>'
)
})

it('inline with kramdown format', () => {
assert.equal(
md().use(highlightjs, { inline: true }).renderInline('`console.log(42)`{:.js}'),
'<code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-number">42</span>)</code>'
'<code class="hljs language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-number">42</span>)</code>'
)
})

it('inline escape language class', () => {
assert.equal(
md().use(highlightjs, { inline: true }).renderInline('`console.log(42)`{:."><img onerror=alert(1) src=.>js}'),
'<code class="language-&quot;&gt;&lt;img onerror=alert(1) src=.&gt;js"></code>'
'<code class="hljs language-&quot;&gt;&lt;img onerror=alert(1) src=.&gt;js"></code>'
)
})

Expand All @@ -114,14 +114,14 @@ describe('markdown-it-highlightjs', () => {
it('inline auto', () => {
assert.equal(
md().use(highlightjs, { inline: true }).renderInline('`console.log(42)`'),
'<code>console.<span class="hljs-built_in">log</span>(<span class="hljs-number">42</span>)</code>'
'<code class="hljs">console.<span class="hljs-built_in">log</span>(<span class="hljs-number">42</span>)</code>'
)
})

it('inline no auto', () => {
assert.equal(
md().use(highlightjs, { inline: true, auto: false }).renderInline('`console.log(42)`'),
'<code>console.log(42)</code>'
'<code class="hljs">console.log(42)</code>'
)
})
})

0 comments on commit 799213d

Please sign in to comment.