jenkins-bot has submitted this change and it was merged.

Change subject: Improvements to fostered transclusion wrapping
......................................................................


Improvements to fostered transclusion wrapping

 * If a transclusion that starts in a table produced fostered content
   and siblings, we were inserting the wrapping metas in between,
   resulting in interweaved markers.

 * A complication is that sometimes newlines show up in between so we
   take care to backtrack when we don't find any more siblings.

Bug: 63790

Change-Id: I732167697a59465cbee4e14a0d493883556c0833
---
M lib/dom.markFosteredContent.js
M tests/parserTests.txt
2 files changed, 33 insertions(+), 10 deletions(-)

Approvals:
  Subramanya Sastry: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/dom.markFosteredContent.js b/lib/dom.markFosteredContent.js
index 6230ef7..386c94b 100644
--- a/lib/dom.markFosteredContent.js
+++ b/lib/dom.markFosteredContent.js
@@ -59,19 +59,31 @@
                "typeof": "mw:Transclusion/End"
        });
 
-       var sibling = table.nextSibling;
+       var sibling = table.nextSibling,
+               beforeText;
 
-       // skip table end mw:shadow
-       if ( sibling && DU.isMarkerMeta( sibling, "mw:EndTag" ) ) {
-               sibling = sibling.nextSibling;
+       // skip pass the table end mw:shadow and any transclusions that
+       // start inside the table. there may be newlines and comments in
+       // between so keep track of that, and backtrack when necessary.
+       while ( sibling ) {
+               if ( !DU.isTplStartMarkerMeta( sibling ) && (
+                        DU.isTplElementNode( env, sibling ) ||
+                        DU.isMarkerMeta( sibling, "mw:EndTag" ) ||
+                        DU.isMarkerMeta( sibling, "mw:TransclusionShadow" )
+               )) {
+                       sibling = sibling.nextSibling;
+                       beforeText = null;
+               } else if ( DU.isComment( sibling ) || DU.isText( sibling ) ) {
+                       if ( !beforeText ) {
+                               beforeText = sibling;
+                       }
+                       sibling = sibling.nextSibling;
+               } else {
+                       break;
+               }
        }
 
-       // special case where the table end and inner transclusion coincide
-       if ( sibling && DU.isMarkerMeta( sibling, "mw:Transclusion/End" ) ) {
-               sibling = sibling.nextSibling;
-       }
-
-       table.parentNode.insertBefore( e, sibling );
+       table.parentNode.insertBefore( e, beforeText ? beforeText : sibling );
 
 }
 
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 415641e..3c85a2b 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -19829,6 +19829,17 @@
 !!end
 
 !!test
+9. Encapsulate foster-parented transclusion content
+!!options
+parsoid=wt2wt,wt2html
+!! wikitext
+<table>{{echo|hi</table>hello}}
+!! html
+<span about="#mwt2" typeof="mw:Transclusion" 
data-mw='{"parts":["&lt;table>",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi&lt;/table>hello"}},"i":0}}]}'
 
data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"pi":[[{"k":"1","spc":["","","",""]}]]}'>hi</span>
+<table about="#mwt2" data-parsoid='{"stx":"html"}'></table><span about="#mwt2" 
data-parsoid="{}">hello</span>
+!!end
+
+!!test
 Table in fosterable position
 !!options
 parsoid=wt2html,wt2wt

-- 
To view, visit https://gerrit.wikimedia.org/r/125514
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I732167697a59465cbee4e14a0d493883556c0833
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to