Skip to content

Commit 6229b88

Browse files
committed
Improved section parser handling of blockquote>p
closes #715 - when the section parser encountered `blockquote>p` structure it was ignoring the blockquote and creating plain markup sections - adds special handling for `blockquote>p` so that the intention of blockquote semantics is not lost when a blockquote contains one or more paragraphs of quoted content
1 parent 2797394 commit 6229b88

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/js/parsers/section.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,24 @@ class SectionParser {
373373
let sectionType,
374374
tagName,
375375
inferredTagName = false;
376+
376377
if (isTextNode(element)) {
377378
tagName = DEFAULT_TAG_NAME;
378379
sectionType = MARKUP_SECTION_TYPE;
379380
inferredTagName = true;
380381
} else {
381382
tagName = normalizeTagName(element.tagName);
382383

384+
// blockquote>p is valid html and should be treated as a blockquote section
385+
// rather than a plain markup section
386+
if (
387+
tagName === 'p' &&
388+
element.parentElement &&
389+
normalizeTagName(element.parentElement.tagName) === 'blockquote'
390+
) {
391+
tagName = 'blockquote';
392+
}
393+
383394
if (contains(VALID_LIST_SECTION_TAGNAMES, tagName)) {
384395
sectionType = LIST_SECTION_TYPE;
385396
} else if (contains(VALID_LIST_ITEM_TAGNAMES, tagName)) {

tests/unit/parsers/section-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,22 @@ test('#parse handles card-creating element after plain text', (assert) => {
589589
assert.equal(sections[2].text.trim(), 'After');
590590
});
591591

592+
test('#parse handles <p> inside <blockquote>', (assert) => {
593+
let container = buildDOM(`
594+
<blockquote>
595+
<p>One</p>
596+
<p>Two</p>
597+
</blockquote>
598+
`);
599+
600+
parser = new SectionParser(builder);
601+
let sections = parser.parse(container.firstChild);
602+
603+
assert.equal(sections.length, 2, '2 sections');
604+
assert.equal(sections[0].type, 'markup-section');
605+
assert.equal(sections[0].tagName, 'blockquote');
606+
assert.equal(sections[0].text.trim(), 'One');
607+
assert.equal(sections[1].type, 'markup-section');
608+
assert.equal(sections[1].tagName, 'blockquote');
609+
assert.equal(sections[1].text.trim(), 'Two');
610+
});

0 commit comments

Comments
 (0)