Skip to content

Commit 15a21f1

Browse files
committed
Fix multiple line endings in text
1 parent 914a6b7 commit 15a21f1

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

lib/handlers/text.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
module.exports = text
44

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

87
function text(h, node) {
9-
return h.augment(node, u('text', trimLines(node.value)))
8+
return h.augment(
9+
node,
10+
u('text', String(node.value).replace(/[ \t]*(\r?\n|\r)[ \t]*/g, '$1'))
11+
)
1012
}

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@types/unist": "^2.0.3",
3636
"mdast-util-definitions": "^3.0.0",
3737
"mdurl": "^1.0.0",
38-
"trim-lines": "^1.0.0",
3938
"unist-builder": "^2.0.0",
4039
"unist-util-generated": "^1.0.0",
4140
"unist-util-position": "^3.0.0",

test/text.js

+6
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@ var to = require('..')
77
test('Nodes', function (t) {
88
t.deepEqual(to(u('text', 'alpha')), u('text', 'alpha'), 'should map `text`s')
99

10+
t.deepEqual(
11+
to(u('text', 'alpha \n \n bravo')),
12+
u('text', 'alpha\n\nbravo'),
13+
'should trim spaces and tabs around eols'
14+
)
15+
1016
t.end()
1117
})

0 commit comments

Comments
 (0)