Subramanya Sastry has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/398077 )
Change subject: WIP: T182793: Handle extension <-> section boundary conflicts
......................................................................
WIP: T182793: Handle extension <-> section boundary conflicts
This seems to eliminate crashers on a number of pages
but, wt2wt will not be clean if section tags are preserved.
Right now, this is not a concern since we are stripping
section tags in our html2wt code paths.
Both the tpl and ext expansion feels ugly but in the presence of
unbalanced content, unclear what other solutions exist.
Change-Id: Idb1f793a315fb5e068a0f520d0f3297f3b3ff9ef
---
M lib/wt2html/pp/processors/wrapSections.js
1 file changed, 27 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/77/398077/1
diff --git a/lib/wt2html/pp/processors/wrapSections.js
b/lib/wt2html/pp/processors/wrapSections.js
index 73f9b89..7108784 100644
--- a/lib/wt2html/pp/processors/wrapSections.js
+++ b/lib/wt2html/pp/processors/wrapSections.js
@@ -155,7 +155,7 @@
// are in different sections! This might require
resolution.
if (currSection !== tplInfo.firstSection) {
tplInfo.lastSection = currSection;
- state.templatesToExamine.push(tplInfo);
+ state.tplsAndExtsToExamine.push(tplInfo);
}
tplInfo = null;
@@ -196,8 +196,8 @@
return -1;
}
-function resolveTemplateSectionConflicts(state) {
- state.templatesToExamine.forEach(function(tplInfo) {
+function resolveTplExtSectionConflicts(state) {
+ state.tplsAndExtsToExamine.forEach(function(tplInfo) {
var s1 = tplInfo.firstSection &&
tplInfo.firstSection.container; // could be undefined
var s2 = tplInfo.lastSection.container; // guaranteed to be
non-null
@@ -227,7 +227,11 @@
tplDsr = DU.getDataParsoid(tplInfo.first).dsr;
var tplEndOffset = tplDsr[1];
dmw = DU.getDataMw(tplInfo.first);
- dmw.parts.push(state.getSrc(tplEndOffset,
newTplEndOffset));
+ if
(/mw:Transclusion/.test(tplInfo.first.getAttribute('typeof'))) {
+
dmw.parts.push(state.getSrc(tplEndOffset, newTplEndOffset));
+ } else { /* extension */
+ dmw.body.extsrc = dmw.body.extsrc +
state.getSrc(tplEndOffset, newTplEndOffset);
+ }
// Update DSR
tplDsr[1] = newTplEndOffset;
@@ -267,14 +271,21 @@
var tplDP = DU.getDataParsoid(tplInfo.first);
tplDsr = tplDP.dsr;
dmw = Util.clone(DU.getDataMw(tplInfo.first));
- dmw.parts.unshift(state.getSrc(dsr1, tplDsr[0]));
- dmw.parts.push(state.getSrc(tplDsr[1], dsr2));
- DU.setDataMw(newS1, dmw);
- newS1.setAttribute('typeof', 'mw:Transclusion');
- // Copy the template's parts-information object
- // which has white-space information for formatting
- // the transclusion and eliminates dirty-diffs.
- DU.setDataParsoid(newS1, { pi: tplDP.pi, dsr: [ dsr1,
dsr2 ] });
+ if
(/mw:Transclusion/.test(tplInfo.first.getAttribute('typeof'))) {
+ dmw.parts.unshift(state.getSrc(dsr1,
tplDsr[0]));
+ dmw.parts.push(state.getSrc(tplDsr[1], dsr2));
+ DU.setDataMw(newS1, dmw);
+ newS1.setAttribute('typeof', 'mw:Transclusion');
+ // Copy the template's parts-information object
+ // which has white-space information for
formatting
+ // the transclusion and eliminates dirty-diffs.
+ DU.setDataParsoid(newS1, { pi: tplDP.pi, dsr: [
dsr1, dsr2 ] });
+ } else { /* extension */
+ dmw.body.extsrc = state.getSrc(dsr1, tplDsr[0])
+ dmw.body.extsrc + state.getSrc(tplDsr[1], dsr2);
+ DU.setDataMw(newS1, dmw);
+ newS1.setAttribute('typeof',
tplInfo.first.getAttribute('typeof'));
+ DU.setDataParsoid(newS1, { dsr: [ dsr1, dsr2 ]
});
+ }
}
});
}
@@ -283,6 +294,8 @@
if (!atTopLevel || !env.wrapSections) {
return;
}
+
+ DU.dumpDOM(rootNode, 'DOM: before section wrap!')
var doc = rootNode.ownerDocument;
var leadSection = {
@@ -303,7 +316,7 @@
rootNode: rootNode,
sectionNumber: 0,
inTemplate: false,
- templatesToExamine: [],
+ tplsAndExtsToExamine: [],
getSrc: function(s, e) {
return this.env.page.src.substring(s,e);
},
@@ -315,7 +328,7 @@
rootNode.insertBefore(leadSection.container, rootNode.firstChild);
// Resolve template conflicts after all sections have been added to the
DOM
- resolveTemplateSectionConflicts(state);
+ resolveTplExtSectionConflicts(state);
}
module.exports = {
--
To view, visit https://gerrit.wikimedia.org/r/398077
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idb1f793a315fb5e068a0f520d0f3297f3b3ff9ef
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits