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

Change subject: Generalize foster parented content detection
......................................................................


Generalize foster parented content detection

Fostered content is boxed with an inserted meta tag.

Bug: 53110
Change-Id: I04f3751660caf37964fb4a1d79e8d16fc9464055
---
M js/lib/dom.markFosteredContent.js
M js/lib/mediawiki.DOMPostProcessor.js
M js/lib/mediawiki.HTML5TreeBuilder.node.js
3 files changed, 41 insertions(+), 68 deletions(-)

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



diff --git a/js/lib/dom.markFosteredContent.js 
b/js/lib/dom.markFosteredContent.js
index 0fcacd3..55676ad 100644
--- a/js/lib/dom.markFosteredContent.js
+++ b/js/lib/dom.markFosteredContent.js
@@ -2,85 +2,48 @@
 
 var DU = require('./mediawiki.DOMUtils.js').DOMUtils;
 
-/* 
------------------------------------------------------------------------------------
- * Non-IEW (inter-element-whitespace) can only be found in <td> <th> and 
<caption> tags
- * in a table.  If found elsewhere within a table, such content will be moved 
out of
- * the table and be "adopted" by the table's sibling ("foster parent").  The 
content
- * that gets adopted is "fostered content".
+/* ------------------------------------------------------------------------
+ * Non-IEW (inter-element-whitespace) can only be found in <td> <th> and
+ * <caption> tags in a table.  If found elsewhere within a table, such
+ * content will be moved out of the table and be "adopted" by the table's
+ * sibling ("foster parent"). The content that gets adopted is "fostered
+ * content".
  *
- * See http://dev.w3.org/html5/spec-LC/tree-construction.html#foster-parenting
- * 
------------------------------------------------------------------------------------
 */
-function markFosteredContent(node, env) {
-       function findFosteredContent(table) {
-               var tableTagId = table.data.parsoid.tagId,
-                       n = table.previousSibling,
-                       initPos = table.data.parsoid.tsr ? 
table.data.parsoid.tsr[0] : null,
-                       fosteredText = "",
-                       nodeBuf = [],
-                       tsrGap = 0;
+ * http://dev.w3.org/html5/spec-LC/tree-construction.html#foster-parenting
+ * ------------------------------------------------------------------------ */
 
-               while (n) {
-                       if (DU.isElt(n)) {
-                               if (typeof(n.data.parsoid.tagId) !== 'number' 
|| n.data.parsoid.tagId < tableTagId) {
-                                       if (initPos && n.data.parsoid.tsr && 
DU.tsrSpansTagDOM(n, n.data.parsoid)) {
-                                               var expectedGap = initPos - 
n.data.parsoid.tsr[1];
-                                               if (tsrGap !== expectedGap) {
-                                                       /*
-                                                       console.log("Fostered 
text/comments: " +
-                                                               
JSON.stringify(fosteredText.substring(expectedGap)));
-                                                       */
-                                                       while (nodeBuf.length > 
0) {
-                                                               // Wrap each 
node in a span wrapper
-                                                               var x = 
nodeBuf.pop();
-                                                               var span = 
table.ownerDocument.createElement('span');
-                                                               span.data = { 
parsoid: { fostered: true } };
-                                                               
x.parentNode.insertBefore(span, x);
-                                                               
span.appendChild(x);
-                                                       }
-                                               }
-                                       } else {
-                                               /* jshint noempty: false */
+function markFosteredContent( node, env ) {
+       var span, sibling, c = node.firstChild;
 
-                                               // No clue if the text in 
fosteredText is really fostered content.
-                                               // If we ran this pass 
post-dsr-computation, we might be able to
-                                               // detect this in more 
scenarios. Something to consider.
+       while ( c ) {
+               sibling = c.nextSibling;
 
-                                               /*
-                                               console.warn("initPos: " + 
initPos);
-                                               console.warn("have tsr: " + 
n.data.parsoid.tsr);
-                                               console.warn("spans tsr: " + 
(n.data.parsoid.tsr && DU.tsrSpansTagDOM(n, n.data.parsoid)));
-                                               */
-                                       }
-                                       // All good at this point
-                                       break;
+               if ( DU.isMarkerMeta( c, "mw:FosterBox" ) ) {
+                       while ( sibling && (
+                               !DU.isElt( sibling ) || !DU.hasNodeName( 
sibling, "table" )
+                       ) ) {
+                               if ( DU.isElt( sibling ) ) {
+                                       sibling.data.parsoid.fostered = true;
                                } else {
-                                       n.data.parsoid.fostered = true;
+                                       span = 
sibling.ownerDocument.createElement( "span" );
+                                       span.data = { parsoid: { fostered: true 
} };
+                                       sibling.parentNode.insertBefore( span, 
sibling );
+                                       span.appendChild( sibling );
                                }
-                       } else {
-                               var str = DU.isText(n) ? n.nodeValue : "<!--" + 
n.nodeValue + "-->";
-                               tsrGap += str.length;
-                               fosteredText = str + fosteredText;
-                               nodeBuf.push(n);
+                               sibling = sibling.nextSibling;
                        }
-                       n = n.previousSibling;
-               }
-       }
-
-       var c = node.firstChild;
-       while (c) {
-               var sibling = c.nextSibling;
-
-               if (DU.isElt(c) && c.nodeName === 'TABLE') {
-                       findFosteredContent(c);
+                       DU.deleteNode( c );
                }
 
-               if (c.childNodes.length > 0) {
-                       markFosteredContent(c, env);
+               if ( c.childNodes.length > 0 ) {
+                       markFosteredContent( c, env );
                }
+
                c = sibling;
        }
+
 }
 
-if (typeof module === "object") {
+if ( typeof module === "object" ) {
        module.exports.markFosteredContent = markFosteredContent;
-}
+}
\ No newline at end of file
diff --git a/js/lib/mediawiki.DOMPostProcessor.js 
b/js/lib/mediawiki.DOMPostProcessor.js
index da2fb3e..b190c8b 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -110,8 +110,8 @@
        // Common post processing
        this.processors = [
                dataParsoidLoader.traverse.bind( dataParsoidLoader ),
-               handleUnbalancedTables,
                markFosteredContent,
+               handleUnbalancedTables,
                migrateStartMetas,
                markTreeBuilderFixups,
                handlePres,
diff --git a/js/lib/mediawiki.HTML5TreeBuilder.node.js 
b/js/lib/mediawiki.HTML5TreeBuilder.node.js
index 185c31a..67c99cf 100644
--- a/js/lib/mediawiki.HTML5TreeBuilder.node.js
+++ b/js/lib/mediawiki.HTML5TreeBuilder.node.js
@@ -173,6 +173,16 @@
                        break;
                case TagTk:
                        tName = token.name;
+                       if ( tName === "table" ) {
+                               if ( this.trace ) {
+                                       console.warn('inserting foster box 
meta');
+                               }
+                               this.emit('token', {
+                                       type: 'StartTag',
+                                       name: 'meta',
+                                       data: [ { nodeName: "typeof", 
nodeValue: "mw:FosterBox" } ]
+                               });
+                       }
                        this.emit('token', {type: 'StartTag', name: tName, 
data: this._att(attribs)});
                        attrs = [];
                        if ( this.trace ) { console.warn('inserting shadow meta 
for ' + tName); }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I04f3751660caf37964fb4a1d79e8d16fc9464055
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: GWicke <[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