Skip to content

Commit 90700b1

Browse files
committed
Fix non-empty blank lines in indented code
1 parent ff331c2 commit 90700b1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/util/indent-lines.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module.exports = indentLines
22

3-
var blank = /^[\t ]*$/
43
var eol = /\r?\n|\r/g
54

65
function indentLines(value, map) {
@@ -21,6 +20,6 @@ function indentLines(value, map) {
2120
return result.join('')
2221

2322
function one(value) {
24-
result.push(map(value, line, blank.test(value)))
23+
result.push(map(value, line, !value))
2524
}
2625
}

test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,5 +2522,22 @@ test('roundtrip', function (t) {
25222522

25232523
t.equal(to(from(doc)), doc, 'should roundtrip lists with break comments')
25242524

2525+
// The first one could have (up to) four spaces, but it doesn’t add anything,
2526+
// so we don’t roundtrip it.
2527+
doc = [
2528+
' <h3>Header 3</h3>',
2529+
'',
2530+
' <blockquote>',
2531+
' <p>This is a blockquote.</p>',
2532+
' ',
2533+
' <p>This is the second paragraph in the blockquote.</p>',
2534+
' ',
2535+
' <h2>This is an H2 in a blockquote</h2>',
2536+
' </blockquote>',
2537+
''
2538+
].join('\n')
2539+
2540+
t.equal(to(from(doc)), doc, 'should roundtrip indented blank lines in code')
2541+
25252542
t.end()
25262543
})

0 commit comments

Comments
 (0)