T113331: Move auto-generated refs flag from data-parsoid to data-mw

VisualEditor requires this info and presumably other clients might
and this is, in reality, semantic information about wikitext.

The html2html failure is because:
* even when the references html has been autogenerated,
  in non-rt-testing html2wt mode, we always generate the
  <references /> tag.
* we moved the flag from data-parsoid to data-mw but ignore changes
  to data-parsoid while comparing test output.
* So, in html -> wt mode, <references /> is always generated
  => data-mw.autoGenerated flag doesn't show up in the wt -> html
     phase of the (html -> wt -> html) test
  => the html2html test fails.

Change-Id: I8e79f2a436a1ca276b9351228a3d8f02d7ebd0c6
This commit is contained in:
Subramanya Sastry 2016-03-24 15:19:14 -05:00
parent 3b44e7e544
commit 53117cef54

View file

@ -481,7 +481,7 @@ References.prototype.extractRefFromNode = function(node, refsData,
}
};
References.prototype.insertReferencesIntoDOM = function(refsNode, refsData, refsInReferencesHTML) {
References.prototype.insertReferencesIntoDOM = function(refsNode, refsData, refsInReferencesHTML, autoGenerated) {
var dp = DU.getDataParsoid(refsNode);
var group = dp.group || '';
@ -495,6 +495,12 @@ References.prototype.insertReferencesIntoDOM = function(refsNode, refsData, refs
},
};
// Mark this auto-generated so that we can skip this during
// html -> wt and so that clients can strip it if necessary.
if (autoGenerated) {
dataMw.autoGenerated = true;
}
var src = dp.src || '<references/>'; // fall back so we don't crash
// Extract ext-source for <references>..</references> usage
var body = Util.extractExtBody('references', src).trim();
@ -541,7 +547,6 @@ References.prototype.insertMissingReferencesIntoDOM = function(env, refsData, no
// The new references come out of "nowhere", so to make selser work
// propertly, add a zero-sized DSR pointing to the end of the document.
dp.dsr = [env.page.src.length, env.page.src.length, 0, 0];
dp.autoInsertedRefs = true;
if (refsGroup) {
ol.setAttribute('data-mw-group', refsGroup);
dp.group = refsGroup;
@ -552,20 +557,19 @@ References.prototype.insertMissingReferencesIntoDOM = function(env, refsData, no
// each <references /> tag appears on its own line.
node.appendChild(doc.createTextNode("\n"));
node.appendChild(ol);
self.insertReferencesIntoDOM(ol, refsData, [""]);
self.insertReferencesIntoDOM(ol, refsData, [""], true);
});
};
References.prototype.serialHandler = {
handle: Promise.method(function(node, state, wrapperUnmodified) {
var dp = DU.getDataParsoid(node);
if (dp.autoInsertedRefs && state.rtTestMode) {
var dataMw = DU.getDataMw(node);
if (dataMw.autoGenerated && state.rtTestMode) {
// Eliminate auto-inserted <references /> noise in rt-testing
return Promise.resolve('');
} else {
return state.serializer.serializeExtensionStartTag(node, state)
.then(function(startTagSrc) {
var dataMw = DU.getDataMw(node);
if (!dataMw.body) {
return startTagSrc; // We self-closed this already.
} else if (typeof dataMw.body.html === 'string') {