mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-24 15:04:02 +00:00
Use Promise.async/yield in lib/ext/Cite
Change-Id: I08458b0083de8d9aec9673af7f08c4b2e25112e5
This commit is contained in:
parent
8713e6cb55
commit
fd719e02e2
|
@ -113,71 +113,68 @@ Ref.prototype.tokenHandler = function(manager, pipelineOpts, refTok, cb) {
|
|||
};
|
||||
|
||||
Ref.prototype.serialHandler = {
|
||||
handle: Promise.method(function(node, state, wrapperUnmodified) {
|
||||
return state.serializer.serializeExtensionStartTag(node, state)
|
||||
.then(function(startTagSrc) {
|
||||
var dataMw = DU.getDataMw(node);
|
||||
var env = state.env;
|
||||
var html;
|
||||
if (!dataMw.body) {
|
||||
return startTagSrc; // We self-closed this already.
|
||||
} else if (typeof dataMw.body.html === 'string') {
|
||||
// First look for the extension's content in data-mw.body.html
|
||||
html = dataMw.body.html;
|
||||
} else if (typeof dataMw.body.id === 'string') {
|
||||
// If the body isn't contained in data-mw.body.html, look if
|
||||
// there's an element pointed to by body.id.
|
||||
var bodyElt = node.ownerDocument.getElementById(dataMw.body.id);
|
||||
if (!bodyElt && env.page.editedDoc) {
|
||||
// Try to get to it from the main page.
|
||||
// This can happen when the <ref> is inside another
|
||||
// extension, most commonly inside a <references>.
|
||||
// The recursive call to serializeDOM puts us inside
|
||||
// inside a new document.
|
||||
bodyElt = env.page.editedDoc.getElementById(dataMw.body.id);
|
||||
}
|
||||
if (bodyElt) {
|
||||
// n.b. this is going to drop any diff markers but since
|
||||
// the dom differ doesn't traverse into extension content
|
||||
// none should exist anyways.
|
||||
html = DU.ppToXML(bodyElt, { innerXML: true });
|
||||
} else {
|
||||
// Some extra debugging for VisualEditor
|
||||
var extraDebug = '';
|
||||
var firstA = node.querySelector('a[href]');
|
||||
if (firstA && /^#/.test(firstA.getAttribute('href'))) {
|
||||
var href = firstA.getAttribute('href');
|
||||
try {
|
||||
var ref = node.ownerDocument.querySelector(href);
|
||||
if (ref) {
|
||||
extraDebug += ' [own doc: ' + ref.outerHTML + ']';
|
||||
}
|
||||
ref = env.page.editedDoc.querySelector(href);
|
||||
if (ref) {
|
||||
extraDebug += ' [main doc: ' + ref.outerHTML + ']';
|
||||
}
|
||||
} catch (e) { } // eslint-disable-line
|
||||
if (!extraDebug) {
|
||||
extraDebug = ' [reference ' + href + ' not found]';
|
||||
handle: Promise.async(function *(node, state, wrapperUnmodified) {
|
||||
var startTagSrc = yield state.serializer.serializeExtensionStartTag(node, state);
|
||||
var dataMw = DU.getDataMw(node);
|
||||
var env = state.env;
|
||||
var html;
|
||||
if (!dataMw.body) {
|
||||
return startTagSrc; // We self-closed this already.
|
||||
} else if (typeof dataMw.body.html === 'string') {
|
||||
// First look for the extension's content in data-mw.body.html
|
||||
html = dataMw.body.html;
|
||||
} else if (typeof dataMw.body.id === 'string') {
|
||||
// If the body isn't contained in data-mw.body.html, look if
|
||||
// there's an element pointed to by body.id.
|
||||
var bodyElt = node.ownerDocument.getElementById(dataMw.body.id);
|
||||
if (!bodyElt && env.page.editedDoc) {
|
||||
// Try to get to it from the main page.
|
||||
// This can happen when the <ref> is inside another
|
||||
// extension, most commonly inside a <references>.
|
||||
// The recursive call to serializeDOM puts us inside
|
||||
// inside a new document.
|
||||
bodyElt = env.page.editedDoc.getElementById(dataMw.body.id);
|
||||
}
|
||||
if (bodyElt) {
|
||||
// n.b. this is going to drop any diff markers but since
|
||||
// the dom differ doesn't traverse into extension content
|
||||
// none should exist anyways.
|
||||
html = DU.ppToXML(bodyElt, { innerXML: true });
|
||||
} else {
|
||||
// Some extra debugging for VisualEditor
|
||||
var extraDebug = '';
|
||||
var firstA = node.querySelector('a[href]');
|
||||
if (firstA && /^#/.test(firstA.getAttribute('href'))) {
|
||||
var href = firstA.getAttribute('href');
|
||||
try {
|
||||
var ref = node.ownerDocument.querySelector(href);
|
||||
if (ref) {
|
||||
extraDebug += ' [own doc: ' + ref.outerHTML + ']';
|
||||
}
|
||||
ref = env.page.editedDoc.querySelector(href);
|
||||
if (ref) {
|
||||
extraDebug += ' [main doc: ' + ref.outerHTML + ']';
|
||||
}
|
||||
} catch (e) { } // eslint-disable-line
|
||||
if (!extraDebug) {
|
||||
extraDebug = ' [reference ' + href + ' not found]';
|
||||
}
|
||||
env.log('error/' + dataMw.name,
|
||||
}
|
||||
env.log('error/' + dataMw.name,
|
||||
'extension src id ' + dataMw.body.id +
|
||||
' points to non-existent element for:', node.outerHTML,
|
||||
'. More debug info: ', extraDebug);
|
||||
return ''; // Drop it!
|
||||
}
|
||||
} else {
|
||||
env.log('error', 'Ref body unavailable for: ' + node.outerHTML);
|
||||
return ''; // Drop it!
|
||||
}
|
||||
return state.serializer.serializeHTML({
|
||||
env: state.env,
|
||||
extName: dataMw.name,
|
||||
}, html).then(function(src) {
|
||||
return startTagSrc + src + '</' + dataMw.name + '>';
|
||||
});
|
||||
});
|
||||
} else {
|
||||
env.log('error', 'Ref body unavailable for: ' + node.outerHTML);
|
||||
return ''; // Drop it!
|
||||
}
|
||||
var src = yield state.serializer.serializeHTML({
|
||||
env: state.env,
|
||||
extName: dataMw.name,
|
||||
}, html);
|
||||
return startTagSrc + src + '</' + dataMw.name + '>';
|
||||
}),
|
||||
};
|
||||
|
||||
|
@ -664,29 +661,26 @@ References.prototype.insertMissingReferencesIntoDOM = function(refsData, node) {
|
|||
};
|
||||
|
||||
References.prototype.serialHandler = {
|
||||
handle: Promise.method(function(node, state, wrapperUnmodified) {
|
||||
handle: Promise.async(function *(node, state, wrapperUnmodified) {
|
||||
var dataMw = DU.getDataMw(node);
|
||||
if (dataMw.autoGenerated && state.rtTestMode) {
|
||||
// Eliminate auto-inserted <references /> noise in rt-testing
|
||||
return Promise.resolve('');
|
||||
return '';
|
||||
} else {
|
||||
return state.serializer.serializeExtensionStartTag(node, state)
|
||||
.then(function(startTagSrc) {
|
||||
if (!dataMw.body) {
|
||||
return startTagSrc; // We self-closed this already.
|
||||
} else if (typeof dataMw.body.html === 'string') {
|
||||
return state.serializer.serializeHTML({
|
||||
env: state.env,
|
||||
extName: dataMw.name,
|
||||
}, dataMw.body.html).then(function(src) {
|
||||
return startTagSrc + src + '</' + dataMw.name + '>';
|
||||
});
|
||||
} else {
|
||||
state.env.log('error',
|
||||
'References body unavailable for: ' + node.outerHTML);
|
||||
return ''; // Drop it!
|
||||
}
|
||||
});
|
||||
var startTagSrc = yield state.serializer.serializeExtensionStartTag(node, state);
|
||||
if (!dataMw.body) {
|
||||
return startTagSrc; // We self-closed this already.
|
||||
} else if (typeof dataMw.body.html === 'string') {
|
||||
var src = yield state.serializer.serializeHTML({
|
||||
env: state.env,
|
||||
extName: dataMw.name,
|
||||
}, dataMw.body.html);
|
||||
return startTagSrc + src + '</' + dataMw.name + '>';
|
||||
} else {
|
||||
state.env.log('error',
|
||||
'References body unavailable for: ' + node.outerHTML);
|
||||
return ''; // Drop it!
|
||||
}
|
||||
}
|
||||
}),
|
||||
before: function(node, otherNode, state) {
|
||||
|
|
Loading…
Reference in a new issue