Subramanya Sastry has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/395116 )
Change subject: lib/parse.js: Make wt2html and html2wt methods do what they say
......................................................................
lib/parse.js: Make wt2html and html2wt methods do what they say
Make wt2wt and html2html be external transformations on output
of those methods.
Made out.lint conditional on linting being enabled.
Change-Id: Ifa7150d9badcf5b558b3774185431ef1a1e4f7a0
---
M lib/parse.js
1 file changed, 39 insertions(+), 32 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/16/395116/1
diff --git a/lib/parse.js b/lib/parse.js
index b045dab..61a2fdb 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -8,7 +8,7 @@
var DU = require('./utils/DOMUtils.js').DOMUtils;
var Promise = require('./utils/promise.js');
-var wt2html, html2wt;
+var _wt2html, _html2wt;
/**
* Transform wikitext to html
@@ -23,7 +23,7 @@
* @return {String} return.contentmodel
* @return {Object} [return.pb] If pageBundle was requested
*/
-wt2html = function(obj, env, wt) {
+_wt2html = function(obj, env, wt) {
// `wt` will be `undefined` when we fetched page source and info,
// which we don't want to overwrite.
if (wt !== undefined) {
@@ -37,28 +37,25 @@
}
})
.then(function(doc) {
- if (['wt2html', 'html2html'].includes(obj.mode)) {
- var out;
- if (env.pageBundle) {
- out = DU.extractDpAndSerialize(obj.bodyOnly ?
doc.body : doc, {
- innerXML: obj.bodyOnly,
- });
- } else {
- out = {
- html: DU.toXML(obj.bodyOnly ? doc.body
: doc, {
- innerXML: obj.bodyOnly,
- }),
- };
- }
- out.lint = env.lintLogger.buffer;
- if (env.conf.parsoid.linting) {
- env.log("end/parse");
- }
- out.contentmodel = (obj.contentmodel ||
env.page.getContentModel());
- return out;
+ var out;
+ if (env.pageBundle) {
+ out = DU.extractDpAndSerialize(obj.bodyOnly ? doc.body
: doc, {
+ innerXML: obj.bodyOnly,
+ });
} else {
- return html2wt(obj, env, DU.toXML(doc));
+ out = {
+ html: DU.toXML(obj.bodyOnly ? doc.body : doc, {
+ innerXML: obj.bodyOnly,
+ }),
+ };
}
+
+ if (env.conf.parsoid.linting) {
+ out.lint = env.lintLogger.buffer;
+ env.log("end/parse");
+ }
+ out.contentmodel = (obj.contentmodel ||
env.page.getContentModel());
+ return out;
});
};
@@ -73,7 +70,7 @@
* @return {Promise} Assuming we're ending at wt
* @return {String} return.wt
*/
-html2wt = function(obj, env, html, pb) {
+_html2wt = function(obj, env, html, pb) {
var useSelser = (obj.selser !== undefined);
var doc = DU.parseHTML(html);
pb = pb || DU.extractPageBundle(doc);
@@ -89,11 +86,7 @@
var handler = env.getContentHandler(obj.contentmodel);
return handler.fromHTML(env, doc.body, useSelser)
.then(function(out) {
- if (['html2wt', 'wt2wt', 'selser'].includes(obj.mode)) {
- return { wt: out };
- } else {
- return wt2html(obj, env, out);
- }
+ return { wt: out };
});
};
@@ -152,6 +145,7 @@
env.page.meta.revision.revid = obj.oldid;
}
+ var p;
if (['html2wt', 'html2html', 'selser'].includes(obj.mode)) {
// Selser
var selser = obj.selser;
@@ -171,8 +165,15 @@
throw new Error('this is broken');
}
}
- return html2wt(obj, env, obj.input, obj.pb);
- } else {
+ p = _html2wt(obj, env, obj.input, obj.pb);
+ if (obj.mode === 'html2html') {
+ return p.then(function(out) {
+ return _wt2html(obj, env, out.wt);
+ });
+ } else { /* html2wt, selser */
+ return p;
+ }
+ } else { /* wt2html, wt2wt */
// The content version to output
if (obj.contentVersion) {
env.setContentVersion(obj.contentVersion);
@@ -182,7 +183,6 @@
env.cacheReusableExpansions(obj.reuseExpansions);
}
- var p;
if (obj.input === undefined) {
var target = env.normalizeAndResolvePageTitle();
p = TemplateRequest
@@ -195,7 +195,14 @@
}
return p
.then(function(wt) {
- return wt2html(obj, env, wt);
+ p = _wt2html(obj, env, wt);
+ if (['wt2html'].includes(obj.mode)) {
+ return p;
+ } else { /* wt2wt */
+ return p.then(function(out) {
+ return _html2wt(obj, env,
out.html);
+ });
+ }
});
}
})
--
To view, visit https://gerrit.wikimedia.org/r/395116
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifa7150d9badcf5b558b3774185431ef1a1e4f7a0
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