Skip to content

Commit

Permalink
Fix tabs in code
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 2, 2020
1 parent 96a1161 commit 914a6b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/handlers/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

module.exports = code

var detab = require('detab')
var u = require('unist-builder')

function code(h, node) {
var value = node.value ? detab(node.value + '\n') : ''
var value = node.value ? node.value + '\n' : ''
var lang = node.lang && node.lang.match(/^[^ \t]+(?=[ \t]|$)/)
var props = {}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"@types/mdast": "^3.0.0",
"@types/unist": "^2.0.3",
"detab": "^2.0.0",
"mdast-util-definitions": "^3.0.0",
"mdurl": "^1.0.0",
"trim-lines": "^1.0.0",
Expand Down
8 changes: 8 additions & 0 deletions test/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ test('Code', function (t) {
'should transform `code` to a `pre` element with language class'
)

t.deepEqual(
to(u('code', '\ta')),
u('element', {tagName: 'pre', properties: {}}, [
u('element', {tagName: 'code', properties: {}}, [u('text', '\ta\n')])
]),
'should support tabs in code'
)

t.end()
})

0 comments on commit 914a6b7

Please sign in to comment.