Skip to content

Commit 843796a

Browse files
committed
Fix html (text) at start of phrasing
Closes GH-16.
1 parent 28d3638 commit 843796a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/util/container-phrasing.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ function phrasing(parent, context, safeOptions) {
3131
// As we can’t escape or so to prevent it from happening, we take a somewhat
3232
// reasonable approach: replace that eol with a space.
3333
// See: <https://github.com/syntax-tree/mdast-util-to-markdown/issues/15>
34-
if ((before === '\r' || before === '\n') && child.type === 'html') {
34+
if (
35+
results.length > 0 &&
36+
(before === '\r' || before === '\n') &&
37+
child.type === 'html'
38+
) {
3539
results[results.length - 1] = results[results.length - 1].replace(
3640
/(\r?\n|\r)$/,
3741
' '

test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,18 @@ test('html', function (t) {
11041104
'should prevent html (text) from becoming html (flow) (3)'
11051105
)
11061106

1107+
t.equal(
1108+
to({
1109+
type: 'paragraph',
1110+
children: [
1111+
{type: 'html', value: '<x>'},
1112+
{type: 'text', value: 'a'}
1113+
]
1114+
}),
1115+
'<x>a\n',
1116+
'should serialize html (text)'
1117+
)
1118+
11071119
t.end()
11081120
})
11091121

0 commit comments

Comments
 (0)