Skip to content

Commit 4a4c149

Browse files
committed
Fix sole blank line in fenced code
Closes GH-24.
1 parent a2ef519 commit 4a4c149

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/util/format-code-as-indented.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ function formatCodeAsIndented(node, context) {
99
// And there’s a non-whitespace character…
1010
/[^ \r\n]/.test(node.value) &&
1111
// And the value doesn’t start or end in a blank…
12-
!/^[\t ]*[\r\n]|[\r\n][\t ]*$/.test(node.value)
12+
!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(node.value)
1313
)
1414
}

test.js

+8
Original file line numberDiff line numberDiff line change
@@ -2882,5 +2882,13 @@ test('roundtrip', function (t) {
28822882
'should not collapse escapes (2)'
28832883
)
28842884

2885+
doc = '```\n \n```\n'
2886+
2887+
t.equal(
2888+
to(from(doc)),
2889+
doc,
2890+
'should roundtrip a sole blank line in fenced code'
2891+
)
2892+
28852893
t.end()
28862894
})

0 commit comments

Comments
 (0)