From 2517e9dc656cf9c3004644c03c5e6d364d4b256a Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Mon, 18 Mar 2019 20:06:53 +0800 Subject: [PATCH] Added consistent handling to empty mobiledoc closes #10612 - Added handling for 'blank' mobiledoc structure which should be converted to '""' instead of '

' --- .../converters/mobiledoc-converter.js | 3 +- .../converters/mobiledoc-converter_spec.js | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/server/lib/mobiledoc/converters/mobiledoc-converter.js b/core/server/lib/mobiledoc/converters/mobiledoc-converter.js index cb642dedb5..d362857ff9 100644 --- a/core/server/lib/mobiledoc/converters/mobiledoc-converter.js +++ b/core/server/lib/mobiledoc/converters/mobiledoc-converter.js @@ -108,7 +108,8 @@ module.exports = { // Koenig keeps a blank paragraph at the end of a doc but we want to // make sure it doesn't get rendered let lastChild = rendered.result.lastChild; - if (lastChild && lastChild.tagName === 'P' && !lastChild.firstChild) { + if (lastChild && lastChild.tagName === 'P' + && !(lastChild.firstChild && lastChild.firstChild.nodeValue)) { rendered.result.removeChild(lastChild); } diff --git a/core/test/unit/lib/mobiledoc/converters/mobiledoc-converter_spec.js b/core/test/unit/lib/mobiledoc/converters/mobiledoc-converter_spec.js index e452d18d49..641b5190a7 100644 --- a/core/test/unit/lib/mobiledoc/converters/mobiledoc-converter_spec.js +++ b/core/test/unit/lib/mobiledoc/converters/mobiledoc-converter_spec.js @@ -77,6 +77,36 @@ describe('Mobiledoc converter', function () { converter.render(mobiledoc, 2).should.eql('

Test

'); }); + it('removes single blank paragraph', function () { + let mobiledoc = { + version: '0.3.1', + atoms: [], + cards: [], + markups: [], + sections: [ + [1, 'p', []] + ] + }; + + converter.render(mobiledoc, 2).should.eql(''); + }); + + it('removes single blank paragraph with empty content', function () { + let mobiledoc = { + version: '0.3.1', + markups: [], + atoms: [], + cards: [], + sections: [ + [1, 'p', [ + [0, [], 0, ''] + ]] + ] + }; + + converter.render(mobiledoc, 2).should.eql(''); + }); + it('adds id attributes to headings', function () { let mobiledoc = { version: '0.3.1',