Skip to content

Commit

Permalink
Ensure parsed mobiledocs have a blank marker
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Aug 12, 2015
1 parent c404d3b commit e6f656c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/js/parsers/mobiledoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/parsers/mobiledoc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit e6f656c

Please sign in to comment.