Skip to content

Commit

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

module.exports = inlineCode

var collapse = require('collapse-white-space')
var u = require('unist-builder')

function inlineCode(h, node) {
return h(node, 'code', [u('text', collapse(node.value))])
var value = node.value.replace(/\r?\n|\r/g, ' ')
return h(node, 'code', [u('text', value)])
}
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",
"collapse-white-space": "^1.0.0",
"detab": "^2.0.0",
"mdast-util-definitions": "^3.0.0",
"mdurl": "^1.0.0",
Expand Down
12 changes: 12 additions & 0 deletions test/inline-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,17 @@ test('InlineCode', function (t) {
'should transform `inlineCode` to a `code` element'
)

t.deepEqual(
to(u('inlineCode', 'a\tb')),
u('element', {tagName: 'code', properties: {}}, [u('text', 'a\tb')]),
'should support tabs in inline code'
)

t.deepEqual(
to(u('inlineCode', 'a\nb')),
u('element', {tagName: 'code', properties: {}}, [u('text', 'a b')]),
'should change eols to spaces in inline code'
)

t.end()
})

0 comments on commit 96a1161

Please sign in to comment.