From e6f656ca1d23efef4c36b083ed2027fd89fc26a2 Mon Sep 17 00:00:00 2001 From: Matthew Beale Date: Tue, 11 Aug 2015 16:46:32 -0400 Subject: [PATCH] Ensure parsed mobiledocs have a blank marker --- src/js/parsers/mobiledoc.js | 11 +++++++++++ tests/unit/parsers/mobiledoc-test.js | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/js/parsers/mobiledoc.js b/src/js/parsers/mobiledoc.js index 23fa41be7..21ad49d76 100644 --- a/src/js/parsers/mobiledoc.js +++ b/src/js/parsers/mobiledoc.js @@ -21,6 +21,13 @@ export default class MobiledocParser { this.markerTypes = this.parseMarkerTypes(markerTypes); this.parseSections(sections, post); + if (post.sections.isEmpty) { + let section = this.builder.createMarkupSection('p'); + let marker = this.builder.createBlankMarker(); + section.markers.append(marker); + post.sections.append(section); + } + return post; } @@ -67,6 +74,10 @@ export default class MobiledocParser { const section = this.builder.createMarkupSection(tagName); post.sections.append(section); this.parseMarkers(markers, section); + if (section.markers.isEmpty) { + let marker = this.builder.createBlankMarker(); + section.markers.append(marker); + } } parseMarkers(markers, section) { diff --git a/tests/unit/parsers/mobiledoc-test.js b/tests/unit/parsers/mobiledoc-test.js index f398151f3..57ee1855c 100644 --- a/tests/unit/parsers/mobiledoc-test.js +++ b/tests/unit/parsers/mobiledoc-test.js @@ -25,6 +25,27 @@ test('#parse empty doc returns an empty post', (assert) => { version: MOBILEDOC_VERSION, sections: [[], []] }; + + let section = builder.createMarkupSection('P'); + let marker = builder.createBlankMarker(); + section.markers.append(marker); + post.sections.append(section); + assert.deepEqual(parser.parse(mobiledoc), + post); +}); + +test('#parse empty markup section returns an empty post', (assert) => { + let mobiledoc = { + version: MOBILEDOC_VERSION, + sections: [[], [ + [1, 'h2', []] + ]] + }; + + let section = builder.createMarkupSection('h2'); + let marker = builder.createBlankMarker(); + section.markers.append(marker); + post.sections.append(section); assert.deepEqual(parser.parse(mobiledoc), post); });