jenkins-bot has submitted this change and it was merged. ( 
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, 29 insertions(+), 32 deletions(-)

Approvals:
  jenkins-bot: Verified
  Arlolra: Looks good to me, approved



diff --git a/lib/parse.js b/lib/parse.js
index b045dab..75f56ee 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,10 @@
                                        throw new Error('this is broken');
                                }
                        }
-                       return html2wt(obj, env, obj.input, obj.pb);
-               } else {
+                       return _html2wt(obj, env, obj.input, 
obj.pb).then(function(out) {
+                               return obj.mode === 'html2html' ? _wt2html(obj, 
env, out.wt) : out;
+                       });
+               } else { /* wt2html, wt2wt */
                        // The content version to output
                        if (obj.contentVersion) {
                                env.setContentVersion(obj.contentVersion);
@@ -182,7 +178,6 @@
                                
env.cacheReusableExpansions(obj.reuseExpansions);
                        }
 
-                       var p;
                        if (obj.input === undefined) {
                                var target = env.normalizeAndResolvePageTitle();
                                p = TemplateRequest
@@ -195,7 +190,9 @@
                        }
                        return p
                        .then(function(wt) {
-                               return wt2html(obj, env, wt);
+                               return _wt2html(obj, env, 
wt).then(function(out) {
+                                       return obj.mode === 'wt2html' ? out : 
_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: merged
Gerrit-Change-Id: Ifa7150d9badcf5b558b3774185431ef1a1e4f7a0
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: Sbailey <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to