Skip to content

Commit ab3a795

Browse files
committed
Fix support for spaces in class names
Related-to: 6fc783a.
1 parent efb5312 commit ab3a795

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/handlers/code.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ export function code(state, node) {
1818
const value = node.value ? node.value + '\n' : ''
1919
/** @type {Properties} */
2020
const properties = {}
21+
// Someone can write `js python	ruby`.
22+
const language = node.lang ? node.lang.split(/\s+/) : []
2123

22-
if (node.lang) {
23-
properties.className = ['language-' + node.lang]
24+
// GH/CM still drop the non-first languages.
25+
if (language.length > 0) {
26+
properties.className = ['language-' + language[0]]
2427
}
2528

2629
// Create `<code>`.

test/code.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ test('code', async function (t) {
3434
}
3535
)
3636

37+
await t.test('should transform `lang` w/ spaces', async function () {
38+
assert.deepEqual(
39+
toHast({type: 'code', lang: 'js python\truby', value: 'echo()'}),
40+
h('pre', [h('code', {className: ['language-js']}, 'echo()\n')])
41+
)
42+
})
43+
3744
await t.test('should support `meta`', async function () {
3845
assert.deepEqual(
3946
toHast({type: 'code', lang: 'js', meta: 'echo', value: 'foxtrot()'}),

0 commit comments

Comments
 (0)