Skip to content

Commit

Permalink
fixed SectionParser handling of paragraph following single-marker mar…
Browse files Browse the repository at this point in the history
…kup section

no issue
- adjust empty-markup-section detecting conditional to not throw away a section if it has markers
  • Loading branch information
kevinansfield committed Feb 13, 2019
1 parent 892b66a commit c6ad8cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/parsers/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class SectionParser {

// avoid creating empty paragraphs due to wrapper elements around
// section-creating elements
if (this.state.section.isMarkerable && !this.state.text) {
if (this.state.section.isMarkerable && !this.state.text && this.state.section.markers.length === 0) {
this.state.section = null;
} else {
this._closeCurrentSection();
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/parsers/section-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,28 @@ test('#parse handles p following list', (assert) => {
assert.equal(p.text, 'para');
});

test('#parse handles link in a heading followed by paragraph', (assert) => {
let container = buildDOM(`
<div><h4><a href="https://example.com">Linked header</a></h4><p>test</p></div>
`);

let element = container.firstChild;
parser = new SectionParser(builder);
let sections = parser.parse(element);

assert.equal(sections.length, 2, '2 sections');
assert.equal(sections[0].text, 'Linked header');

let markers = sections[0].markers.toArray();
assert.equal(markers.length, 1, '1 marker');
let [marker] = markers;
assert.equal(marker.value, 'Linked header');
assert.ok(marker.hasMarkup('a'), 'has A markup');

let markup = marker.markups[0];
assert.equal(markup.getAttribute('href'), 'https://example.com');
});

test('#parse skips STYLE nodes', (assert) => {
let element = buildDOM(`
<style>.rule { font-color: red; }</style>
Expand Down

0 comments on commit c6ad8cd

Please sign in to comment.