Skip to content

Commit

Permalink
Fix multiple line endings in text
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 2, 2020
1 parent 914a6b7 commit 15a21f1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/handlers/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
module.exports = text

var u = require('unist-builder')
var trimLines = require('trim-lines')

function text(h, node) {
return h.augment(node, u('text', trimLines(node.value)))
return h.augment(
node,
u('text', String(node.value).replace(/[ \t]*(\r?\n|\r)[ \t]*/g, '$1'))
)
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@types/unist": "^2.0.3",
"mdast-util-definitions": "^3.0.0",
"mdurl": "^1.0.0",
"trim-lines": "^1.0.0",
"unist-builder": "^2.0.0",
"unist-util-generated": "^1.0.0",
"unist-util-position": "^3.0.0",
Expand Down
6 changes: 6 additions & 0 deletions test/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ var to = require('..')
test('Nodes', function (t) {
t.deepEqual(to(u('text', 'alpha')), u('text', 'alpha'), 'should map `text`s')

t.deepEqual(
to(u('text', 'alpha \n \n bravo')),
u('text', 'alpha\n\nbravo'),
'should trim spaces and tabs around eols'
)

t.end()
})

0 comments on commit 15a21f1

Please sign in to comment.