jenkins-bot has submitted this change and it was merged. Change subject: T122054: Strip nowiki spans from templated / extension content ......................................................................
T122054: Strip nowiki spans from templated / extension content Change-Id: I06353fafac9c8a6efa063302727df5815842607f --- M lib/wt2html/pp/cleanup.js M tests/parserTests-blacklist.js M tests/parserTests.txt 3 files changed, 21 insertions(+), 6 deletions(-) Approvals: Arlolra: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/wt2html/pp/cleanup.js b/lib/wt2html/pp/cleanup.js index 808b41a..fe82e16 100644 --- a/lib/wt2html/pp/cleanup.js +++ b/lib/wt2html/pp/cleanup.js @@ -50,6 +50,7 @@ if (!atTopLevel || !tplInfo || !DU.isElt(node)) { return true; } + // Cannot delete if: // * it is the first node since that carries the transclusion // information (typeof, data-mw). We could delete and migrate @@ -87,6 +88,7 @@ if (!DU.isElt(node)) { return true; } var dp = DU.getDataParsoid(node); + var next; // Delete empty auto-inserted elements if (dp.autoInsertedStart && dp.autoInsertedEnd && @@ -96,7 +98,7 @@ /^\s*$/.test(node.textContent) ) )) { - var next = node.nextSibling; + next = node.nextSibling; if (node.firstChild) { // migrate the ws out node.parentNode.insertBefore(node.firstChild, node); @@ -105,9 +107,9 @@ return next; } + // Strip invalid data-mw attributes var validDataMW = !!Object.keys(DU.getDataMw(node)).length; if (!validDataMW) { - // Strip it DU.setDataMw(node, undefined); } @@ -139,11 +141,24 @@ // // But, do not zero it out if the node has template encapsulation // information. That will be disastrous (see T54638, T54488). - if (dp.fostered && dp.dsr && !DU.isFirstEncapsulationWrapperNode(node)) { + if (dp.fostered && dp.dsr && !(tplInfo && tplInfo.first === node)) { dp.dsr[0] = dp.dsr[1]; } if (atTopLevel) { + // Strip nowiki spans from templated content + // but leave behind wrappers on root nodes (they have valid about ids) + if (tplInfo && !DU.isTplOrExtToplevelNode(node) && + /^mw:Nowiki$/.test(node.getAttribute('typeof'))) { + next = node.nextSibling; + DU.migrateChildren(node, node.parentNode, next); + + // Replace the span with an empty text node. + // (better for perf instead of deleting the node) + node.parentNode.replaceChild(node.ownerDocument.createTextNode(''), node); + return next; + } + // Strip data-parsoid from templated content, where unnecessary. if (env.discardDataParsoid || (tplInfo diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js index 61c9637..a039543 100644 --- a/tests/parserTests-blacklist.js +++ b/tests/parserTests-blacklist.js @@ -381,7 +381,7 @@ add("wt2wt", "Ref: 5. body should accept generic wikitext", "A <ref>This is a '''[[bolded link]]''' and this is a {{echo|transclusion}}\n</ref>\n\n<references />"); add("wt2wt", "Ref: 6. indent-pres should not be output in ref-body", "A <ref>foo\n bar\n baz\n</ref>\n\n<references />"); add("wt2wt", "Ref: 7. No p-wrapping in ref-body", "A <ref>foo\nbar\nbaz\nbooz\n</ref>\n\n<references />"); -add("wt2wt", "Ref: 8. transclusion wikitext has lower precedence", "A <ref>foo {{echo|</ref> B C}}\n\n<references />"); +add("wt2wt", "Ref: 8. transclusion wikitext has lower precedence", "A <ref>foo <nowiki>{{</nowiki>echo|</ref> B C}}\n\n<references />"); add("wt2wt", "Ref: 9. unclosed comments should not leak out of ref-body", "A <ref>foo <!----></ref> B C\n<references />"); add("wt2wt", "Ref: 10. Unclosed HTML tags should not leak out of ref-body", "A <ref><b> foo </ref> B C\n\n<references />"); add("wt2wt", "Ref: 19. ref-tags with identical name encodings should get identical indexes", "1 <ref name=\"a & b\">foo</ref> 2 <ref name=\"a &amp; b\" />\n\n<references />"); @@ -1306,7 +1306,7 @@ add("html2wt", "Ref: 5. body should accept generic wikitext", "A <ref>This is a '''[[bolded link]]''' and this is a {{echo|transclusion}}\n</ref>\n\n<references />"); add("html2wt", "Ref: 6. indent-pres should not be output in ref-body", "A <ref>foo\n bar\n baz\n</ref>\n\n<references />"); add("html2wt", "Ref: 7. No p-wrapping in ref-body", "A <ref>foo\nbar\nbaz\nbooz\n</ref>\n\n<references />"); -add("html2wt", "Ref: 8. transclusion wikitext has lower precedence", "A <ref>foo {{echo|</ref> B C<nowiki>}}</nowiki>\n<references />"); +add("html2wt", "Ref: 8. transclusion wikitext has lower precedence", "A <ref>foo <nowiki>{{</nowiki>echo|</ref> B C<nowiki>}}</nowiki>\n<references />"); add("html2wt", "Ref: 9. unclosed comments should not leak out of ref-body", "A <ref>foo <!----></ref> B C\n<references />"); add("html2wt", "Ref: 10. Unclosed HTML tags should not leak out of ref-body", "A <ref><b> foo </ref> B C\n\n<references />"); add("html2wt", "Ref: 19. ref-tags with identical name encodings should get identical indexes", "1 <ref name=\"a & b\">foo</ref> 2 <ref name=\"a &amp; b\" />\n\n<references />"); diff --git a/tests/parserTests.txt b/tests/parserTests.txt index adfceae..b710515 100644 --- a/tests/parserTests.txt +++ b/tests/parserTests.txt @@ -21610,7 +21610,7 @@ !! html <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B C<span typeof="mw:Nowiki">}}</span></p> <ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'> -<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo <span typeof="mw:Nowiki" data-parsoid='{"src":"{{","dsr":[12,14,0,0]}'>{{</span>echo|</span></li> +<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo {{echo|</span></li> </ol> !!end -- To view, visit https://gerrit.wikimedia.org/r/260395 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I06353fafac9c8a6efa063302727df5815842607f Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org> Gerrit-Reviewer: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits