diff --git a/lib/util/container-phrasing.js b/lib/util/container-phrasing.js index 3b4dc46..21a039c 100644 --- a/lib/util/container-phrasing.js +++ b/lib/util/container-phrasing.js @@ -104,7 +104,9 @@ export function containerPhrasing(parent, state, info) { if ( results.length > 0 && encodingInfo.before && - before === results[results.length - 1].slice(-1) + before === results[results.length - 1].slice(-1) && + before !== '\n' && + before !== '\r' ) { results[results.length - 1] = results[results.length - 1].slice(0, -1) + diff --git a/test/index.js b/test/index.js index e47facd..24a75d9 100644 --- a/test/index.js +++ b/test/index.js @@ -746,6 +746,22 @@ test('break', async function (t) { assert.equal(to({type: 'break'}), '\\\n') }) + await t.test( + 'should not character-reference a break before an attention run', + async function () { + assert.equal( + to({ + type: 'paragraph', + children: [ + {type: 'break'}, + {type: 'strong', children: [{type: 'text', value: ' x'}]} + ] + }), + '\\\n** x**\n' + ) + } + ) + await t.test( 'should serialize breaks in heading (atx) as a space', async function () {