Arlolra has uploaded a new change for review.
https://gerrit.wikimedia.org/r/194444
Change subject: Fix serializing LI hack on templates
......................................................................
Fix serializing LI hack on templates
* Push it to the template parts instead of setting it on dp.
* Changes getListBullets in the serializer to emit bullets for li
instead of ul/ol. The ListHandler associates src with them, making it
more consistent this way.
* Fixes roundtripping the two test cases from the bug,
* {{echo|<li>foo</li>}}
* {{bibliografia|foo|bar}}
* We already have a test for this, "Test the li-hack", which fails
because the parsoid output differs from php in that it preserves the
comment and, for an investigated reason, a few autoInsertedEnds are
missing.
Bugs: T89627, T59910
Change-Id: I99f6c142d9a943513f17549da24a801815f52913
---
M lib/dom.t.handleLIHack.js
M lib/wts.TagHandlers.js
M tests/parserTests-blacklist.js
3 files changed, 29 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/44/194444/1
diff --git a/lib/dom.t.handleLIHack.js b/lib/dom.t.handleLIHack.js
index 3de931b..74e4ac3 100644
--- a/lib/dom.t.handleLIHack.js
+++ b/lib/dom.t.handleLIHack.js
@@ -26,11 +26,18 @@
!DU.isLiteralHTMLNode(prevNode) &&
DU.nodeEssentiallyEmpty(prevNode)) {
- var dp = DU.getDataParsoid( node );
+ var dp = DU.getDataParsoid( node ),
+ typeOf = node.getAttribute( 'typeof' ) || '',
+ liHackSrc = DU.getWTSource(env, prevNode);
- // We have to store the extra information in order to
- // reconstruct the original source for roundtripping.
- dp.liHackSrc = DU.getWTSource(env, prevNode);
+ if ( /(?:^|\s)mw:Transclusion(?=$|\s)/.test( typeOf ) ) {
+ var dataMW = DU.getDataMw( node );
+ dataMW.parts.unshift( liHackSrc );
+ } else {
+ // We have to store the extra information in order to
+ // reconstruct the original source for roundtripping.
+ dp.liHackSrc = liHackSrc;
+ }
// Update the dsr. Since we are coalescing the first
// node with the second (or, more precisely, deleting
diff --git a/lib/wts.TagHandlers.js b/lib/wts.TagHandlers.js
index fd3b402..56b7cfc 100644
--- a/lib/wts.TagHandlers.js
+++ b/lib/wts.TagHandlers.js
@@ -144,14 +144,18 @@
* List helper: DOM-based list bullet construction
*/
function getListBullets(node) {
- var listTypes = {
+ var parentTypes = {
ul: '*',
- ol: '#',
+ ol: '#'
+ };
+ var listTypes = {
+ ul: '',
+ ol: '',
dl: '',
li: '',
dt: ';',
dd: ':'
- }, res = '';
+ };
// For new elements, for prettier wikitext serialization,
// emit a space after the last bullet (if required)
@@ -163,12 +167,18 @@
}
}
+ var dp, nodeName, parentName, res = '';
while (node) {
- var nodeName = node.nodeName.toLowerCase(),
- dp = DU.getDataParsoid( node );
+ nodeName = node.nodeName.toLowerCase();
+ dp = DU.getDataParsoid( node );
if (dp.stx !== 'html' && nodeName in listTypes) {
- res = listTypes[nodeName] + res;
+ if ( nodeName === 'li' ) {
+ parentName =
node.parentNode.nodeName.toLowerCase();
+ res = (parentTypes[parentName] || "") + res;
+ } else {
+ res = listTypes[nodeName] + res;
+ }
} else if (dp.stx !== 'html' || !dp.autoInsertedStart ||
!dp.autoInsertedEnd) {
break;
}
diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js
index b3b271d..d52c1b4 100644
--- a/tests/parserTests-blacklist.js
+++ b/tests/parserTests-blacklist.js
@@ -1905,7 +1905,7 @@
add("selser", "Definition Lists: Mixed Lists: Test 8 [[[1,2,1]]]", "*
d18p71r17qkqehfr\n::* d2");
add("selser", "Definition Lists: Mixed Lists: Test 8 [[[1,4,[2]]]]", "*
d1p00sd2ve34ohia4i\n:: waos5kb13d8qto6r\n::* d2");
add("selser", "Definition Lists: Mixed Lists: Test 8 [[[1,2,[[[[4]]]]]]]", "*
d1zrb7mejr5l45z5mi\n::*ll71mwfvepn6zuxr");
-add("selser", "Definition Lists: Mixed Lists: Test 8 [[[[3],2,[1]]]]",
":*2j7qe095hdm42t9\n* d2");
+add("selser", "Definition Lists: Mixed Lists: Test 8 [[[[3],2,[1]]]]",
":2j7qe095hdm42t9\n* d2");
add("selser", "Definition Lists: Mixed Lists: Test 8 [[[0,3,[2]]]]", "* d1\n::
1lcvy03rlwmf5hfr\n::* d2");
add("selser", "Definition Lists: Mixed Lists: Test 8 [[[1,0,3]]]", "* d1\n");
add("selser", "Definition Lists: Mixed Lists: Test 9 [[1]]", ";foo :bar");
@@ -2585,7 +2585,7 @@
add("selser", "Bug 529: Uncovered bullet leaving empty list, normally removed
by tidy [[[2],0]]", "*vkl4nqq6z9kvs4i\n****** Foo {{bullet}}");
add("selser", "Bug 529: Uncovered bullet leaving empty list, normally removed
by tidy [[[1],0]]", "****** Foo {{bullet}}");
add("selser", "Bug 529: Uncovered bullet leaving empty list, normally removed
by tidy [[[[1]],0]]", "***** Foo {{bullet}}");
-add("selser", "Bug 529: Uncovered bullet leaving empty list, normally removed
by tidy [[[[[[3]]]],0]]", "***{{bullet}}");
+add("selser", "Bug 529: Uncovered bullet leaving empty list, normally removed
by tidy [[[[[[3]]]],0]]", "**{{bullet}}");
add("selser", "Bug 529: Uncovered bullet leaving empty list, normally removed
by tidy [[[[2]],0]]", "** y0slrsmmchjxxbt9\n****** Foo {{bullet}}");
add("selser", "Bug 529: Uncovered bullet leaving empty list, normally removed
by tidy [[[[[[[4]]]]],0]]", "***u5i7s9pdlw8w7b9{{bullet}}");
add("selser", "preload: check that it doesn't try to do tricks [[2]]", "*
didei13ahu0afw29\n* <!-- Hello --> ''{{world}}''
{{<includeonly>subst:</includeonly>How are you}}{{ {{{|safesubst:}}}
#if:1|2|3}}");
--
To view, visit https://gerrit.wikimedia.org/r/194444
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I99f6c142d9a943513f17549da24a801815f52913
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits