C. Scott Ananian has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/398941 )
Change subject: Move addRedLinks to DOMPostProcessor; allow async processors.
......................................................................
Move addRedLinks to DOMPostProcessor; allow async processors.
The forthcoming LanguageConverter pass will also be hooked into
DOMPostProcessor. This uses the 'yield' syntax (node 4 and up) to
allow asynchronous processing steps in DOMPostProcessor.
Change-Id: Id7d97a8c944c05177250adb31a22349f5db01943
---
M lib/parse.js
M lib/wt2html/DOMPostProcessor.js
2 files changed, 12 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/41/398941/1
diff --git a/lib/parse.js b/lib/parse.js
index b7a2995..5df43ed 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -33,11 +33,6 @@
}
var handler = env.getContentHandler(obj.contentmodel);
return handler.toHTML(env)
- .tap(function(doc) {
- if (env.conf.parsoid.useBatchAPI) {
- return DU.addRedLinks(env, doc);
- }
- })
.then(function(doc) {
var out;
if (env.pageBundle) {
diff --git a/lib/wt2html/DOMPostProcessor.js b/lib/wt2html/DOMPostProcessor.js
index 113073f..6e509e6 100644
--- a/lib/wt2html/DOMPostProcessor.js
+++ b/lib/wt2html/DOMPostProcessor.js
@@ -11,6 +11,7 @@
var DU = require('../utils/DOMUtils.js').DOMUtils;
var DOMTraverser = require('../utils/DOMTraverser.js').DOMTraverser;
+var Promise = require('../utils/promise.js');
// processors
var requireProcessor = function(p) {
@@ -249,6 +250,13 @@
domVisitor.addHandler(null, CleanUp.cleanupAndSaveDataParsoid);
addPP('cleanupAndSaveDP', domVisitor.traverse.bind(domVisitor));
+ // (Optional) red links
+ addPP('addRedLinks', function(rootNode, env, options, atTopLevel) {
+ if (atTopLevel && env.conf.parsoid.useBatchAPI) {
+ // Async; returns promise for completion.
+ return DU.addRedLinks(env, rootNode.ownerDocument);
+ }
+ });
}
// Inherit from EventEmitter
@@ -466,7 +474,7 @@
document.body.classList.add('mw-parser-output');
};
-DOMPostProcessor.prototype.doPostProcess = function(document) {
+DOMPostProcessor.prototype.doPostProcess = Promise.async(function *(document) {
var env = this.env;
var psd = env.conf.parsoid;
@@ -510,7 +518,8 @@
ppStart = Date.now();
env.log(logLevel, prefix + "; " + ppName + "
start");
}
- pp.proc(document.body, env, this.options,
this.atTopLevel);
+ // Processors can return a Promise iff they need to be
async.
+ yield pp.proc(document.body, env, this.options,
this.atTopLevel);
if (tracePP) {
ppEnd = Date.now();
env.log(logLevel, prefix + "; " + ppName + "
end; time = " + (ppEnd - ppStart));
@@ -542,7 +551,7 @@
}
this.emit('document', document);
-};
+});
/**
* Register for the 'document' event, normally emitted from the HTML5 tree
--
To view, visit https://gerrit.wikimedia.org/r/398941
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id7d97a8c944c05177250adb31a22349f5db01943
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: C. Scott Ananian <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits