Marcoil has uploaded a new change for review. https://gerrit.wikimedia.org/r/157700
Change subject: Remove data-parsoid from transcluded template content ...................................................................... Remove data-parsoid from transcluded template content This reduces document size and also fixes the crash when round-trip testing ruwiki Валия. Elements with stx information don't get their data-parsoid removed as the information is necessary in some cases, for now. Change-Id: Ibb8272648bf93a24b16d0871e24633bf35f1ccbc --- M lib/dom.cleanup.js M lib/dom.markFosteredContent.js M lib/dom.wrapTemplates.js M lib/mediawiki.DOMUtils.js M lib/mediawiki.HTML5TreeBuilder.node.js 5 files changed, 24 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/00/157700/1 diff --git a/lib/dom.cleanup.js b/lib/dom.cleanup.js index 66c02e9..25f8127 100644 --- a/lib/dom.cleanup.js +++ b/lib/dom.cleanup.js @@ -39,7 +39,12 @@ function cleanupAndSaveDataParsoid( env, node ) { if ( DU.isElt(node) ) { var dp = DU.getDataParsoid( node ); - if (dp) { + if (dp && dp.inTransclusion && !dp.stx) { + // We don't keep data-parsoid for nodes resulting from template + // expansion. + // TODO: Elements with stx information need to keep it? + DU.removeDataParsoid(node); + } else if (dp) { // Delete empty auto-inserted elements var next = node.nextSibling; if (dp.autoInsertedStart && dp.autoInsertedEnd && diff --git a/lib/dom.markFosteredContent.js b/lib/dom.markFosteredContent.js index 903df5c..bcc7598 100644 --- a/lib/dom.markFosteredContent.js +++ b/lib/dom.markFosteredContent.js @@ -137,7 +137,6 @@ DU.deleteNode( c ); } else if ( DU.isElt( c ) ) { dp = DU.getDataParsoid( c ); - dp.inTransclusion = undefined; if ( c.childNodes.length > 0 ) { markFosteredContent( c, env ); } diff --git a/lib/dom.wrapTemplates.js b/lib/dom.wrapTemplates.js index a3980ef..33ffebb 100644 --- a/lib/dom.wrapTemplates.js +++ b/lib/dom.wrapTemplates.js @@ -762,6 +762,13 @@ encapInfo.dp.src = env.page.src.substring( encapInfo.dp.dsr[0], encapInfo.dp.dsr[1] ); } + if (encapInfo.dp.inTransclusion) { + // The first element of the transclusion should never have its + // data-parsoid removed, we make sure by marking it not in the + // transclusion content. + encapInfo.dp.inTransclusion = undefined; + } + // Remove startElem (=range.startElem) if a meta. If a meta, // it is guaranteed to be a marker meta added to mark the start // of the template. diff --git a/lib/mediawiki.DOMUtils.js b/lib/mediawiki.DOMUtils.js index e4b1325..226ac1d 100644 --- a/lib/mediawiki.DOMUtils.js +++ b/lib/mediawiki.DOMUtils.js @@ -304,6 +304,16 @@ return this.setJSONAttribute( node, "data-parsoid", dpObj ); }, + /** + * Remove the data-parsoid attribute on a node. + * + * @returns {Node} `node`, without data-parsoid + */ + removeDataParsoid: function(node) { + delete this.getNodeData(node).parsoid; + return node; + }, + getNodeData: function ( node ) { if ( !node.dataobject ) { node.dataobject = {}; diff --git a/lib/mediawiki.HTML5TreeBuilder.node.js b/lib/mediawiki.HTML5TreeBuilder.node.js index 86e01ac..46d9e22 100644 --- a/lib/mediawiki.HTML5TreeBuilder.node.js +++ b/lib/mediawiki.HTML5TreeBuilder.node.js @@ -58,7 +58,7 @@ this.parser = new HTML5.DOMParser( domino ); this.parser._tokenizer = this; this.addListener('token', - this.parser._treeBuilder.processToken.bind(this.parser._treeBuilder)); + this.parser._treeBuilder.processToken.bind(this.parser._treeBuilder)); } // Reset the parser -- To view, visit https://gerrit.wikimedia.org/r/157700 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibb8272648bf93a24b16d0871e24633bf35f1ccbc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Marcoil <marc...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits