jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/382729 )
Change subject: Useless p-wrapper stripping shouldn't get tripped by tpl meta
tags
......................................................................
Useless p-wrapper stripping shouldn't get tripped by tpl meta tags
* The void tag check was too broad and was trapping tpl-meta-end
tags causing p-wrappers to be left behind around </span> tags
which caused them to get stripped and extended the open <span>
tag's range beyond its original place.
* Added a parser test to capture this expectation
Bug: T177612
Change-Id: I58dd86da1329744f069722204fcefd8e1c8f10df
---
M lib/utils/DOMUtils.js
M lib/utils/Util.js
M lib/wt2html/pp/processors/wrapTemplates.js
M lib/wt2html/tt/ParagraphWrapper.js
M tests/parserTests.txt
5 files changed, 23 insertions(+), 8 deletions(-)
Approvals:
jenkins-bot: Verified
Arlolra: Looks good to me, approved
diff --git a/lib/utils/DOMUtils.js b/lib/utils/DOMUtils.js
index e073bde..d6ff3ef 100644
--- a/lib/utils/DOMUtils.js
+++ b/lib/utils/DOMUtils.js
@@ -666,17 +666,13 @@
return this.isNodeOfType(n, "meta", type);
},
- // Regep for checking marker metas typeofs representing
- // transclusion markup or template param markup.
- TPL_META_TYPE_REGEXP:
/(?:^|\s)(mw:(?:Transclusion|Param)(?:\/End)?)(?=$|\s)/,
-
/**
* Check whether a meta's typeof indicates that it is a template
expansion.
*
* @param {string} nType
*/
isTplMetaType: function(nType) {
- return this.TPL_META_TYPE_REGEXP.test(nType);
+ return Util.TPL_META_TYPE_REGEXP.test(nType);
},
/**
diff --git a/lib/utils/Util.js b/lib/utils/Util.js
index acfa500..95dbd5d 100644
--- a/lib/utils/Util.js
+++ b/lib/utils/Util.js
@@ -472,6 +472,14 @@
return token && token.constructor === pd.SelfclosingTagTk &&
token.name === 'template';
},
+ // Regep for checking marker metas typeofs representing
+ // transclusion markup or template param markup.
+ TPL_META_TYPE_REGEXP:
/(?:^|\s)(mw:(?:Transclusion|Param)(?:\/End)?)(?=$|\s)/,
+
+ isTemplateMeta: function(t) {
+ return t.name === 'meta' &&
Util.TPL_META_TYPE_REGEXP.test(t.getAttribute('typeof'));
+ },
+
isTableTag: function(token) {
var tc = token.constructor;
return (tc === pd.TagTk || tc === pd.EndTagTk) &&
diff --git a/lib/wt2html/pp/processors/wrapTemplates.js
b/lib/wt2html/pp/processors/wrapTemplates.js
index f7938f1..8181605 100644
--- a/lib/wt2html/pp/processors/wrapTemplates.js
+++ b/lib/wt2html/pp/processors/wrapTemplates.js
@@ -903,7 +903,7 @@
if (DU.isElt(elem)) {
var type = elem.getAttribute('typeof');
- var metaMatch = type ?
type.match(DU.TPL_META_TYPE_REGEXP) : null;
+ var metaMatch = type ?
type.match(Util.TPL_META_TYPE_REGEXP) : null;
// Ignore templates without tsr.
//
diff --git a/lib/wt2html/tt/ParagraphWrapper.js
b/lib/wt2html/tt/ParagraphWrapper.js
index 7170cdd..af24c3b 100644
--- a/lib/wt2html/tt/ParagraphWrapper.js
+++ b/lib/wt2html/tt/ParagraphWrapper.js
@@ -108,9 +108,9 @@
// Comments and inline tags by themselves don't need
them.
// NOTE: We don't check for block tags since p-tags
won't wrap block tags.
if (t.constructor === String ||
- Util.isVoidElement(t.name || '') ||
+ (Util.isVoidElement(t.name || '') &&
!Util.isTemplateMeta(t)) ||
// FIXME: do we need a more precise test?
- /\bmw:/.test(t.constructor === TagTk ?
t.getAttribute('typeof') : null)
+ Util.hasParsoidTypeOf(t.constructor === TagTk
&& t.getAttribute('typeof'))
) {
return start;
}
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index df4e9c3..7cff659 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -1928,6 +1928,17 @@
<small><em></em></small><span><s><div>x</div></s></span>
!! end
+# T177612: Parsoid-only test
+!! test
+Transclusion meta tags shouldn't trip Parsoid's useless p-wrapper stripping
code
+!! wikitext
+{{echo|<span><div>x</div></span>}}
+x
+!! html/parsoid
+<span about="#mwt1" typeof="mw:Transclusion"
data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}'
data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<span><div>x</div></span>"}},"i":0}}]}'><div>x</div></span>
+<p>x</p>
+!! end
+
!! test
Block tag on one line (<blockquote>)
!! wikitext
--
To view, visit https://gerrit.wikimedia.org/r/382729
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I58dd86da1329744f069722204fcefd8e1c8f10df
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits