Subramanya Sastry has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/321681

Change subject: Linter: Add linting of self-closed tags
......................................................................

Linter: Add linting of self-closed tags

* Added mocha tests as well.
* Useful for the tidy replacement project.

Change-Id: I8baf52e1161c8d40ebc4720255804f2b497ab8e9
---
M lib/wt2html/pp/handlers/linter.js
M tests/mocha/lintertest.js
2 files changed, 26 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/81/321681/1

diff --git a/lib/wt2html/pp/handlers/linter.js 
b/lib/wt2html/pp/handlers/linter.js
index e06cd84..0c1e7a0 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/handlers/linter.js
@@ -84,15 +84,23 @@
 
        // Dont lint auto-inserted start/end if:
        // 1. c is a void element
-       // 2. c is not self-closed
-       // 3. c is not tbody
+       // 2. c is tbody
        if (DU.isEncapsulationWrapper(c) ||
                (!Util.isVoidElement(cNodeName) &&
-               !dp.selfClose &&
                cNodeName !== 'tbody' &&
                DU.hasLiteralHTMLMarker(dp) &&
                dsr)) {
 
+               if (dp.selfClose) {
+                       lintObj = {
+                               src: env.page.src,
+                               dsr: dsr,
+                               templateInfo: templateInfo,
+                               params: { name: cNodeName },
+                       };
+                       env.log('lint/self-closed-tag', lintObj);
+               }
+
                if (dp.autoInsertedEnd === true && (tplInfo || dsr[2] > 0)) {
                        lintObj = {
                                src: env.page.src,
diff --git a/tests/mocha/lintertest.js b/tests/mocha/lintertest.js
index 962143a..f228698 100644
--- a/tests/mocha/lintertest.js
+++ b/tests/mocha/lintertest.js
@@ -183,5 +183,20 @@
                                result.should.have.length(0);
                        });
                });
+               it('should lint self-closing tags corrrectly', function() {
+                       return parseWT('foo<b />bar<span />baz<hr />boo<br 
/>').then(function(result) {
+                               result.should.have.length(2);
+                               result[0].should.have.a.property("type", 
"self-closed-tag");
+                               result[0].dsr.should.include.members([ 3, 8, 5, 
0 ]);
+                               result[0].should.have.a.property("src", "<b 
/>");
+                               result[0].should.have.a.property("params");
+                               result[0].params.should.have.a.property("name", 
"b");
+                               result[1].should.have.a.property("type", 
"self-closed-tag");
+                               result[1].dsr.should.include.members([ 11, 19, 
8, 0 ]);
+                               result[1].should.have.a.property("src", "<span 
/>");
+                               result[1].should.have.a.property("params");
+                               result[1].params.should.have.a.property("name", 
"span");
+                       });
+               });
        });
 });

-- 
To view, visit https://gerrit.wikimedia.org/r/321681
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8baf52e1161c8d40ebc4720255804f2b497ab8e9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to