jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/346611 )

Change subject: Add linter detection for T161341
......................................................................


Add linter detection for T161341

* Added new mocha tests.

* Verified on svwiki:Kugelstein and cebwiki:Wujieyue_Shan
  and in both cases, the relevant templates were identified
  as the source of the deletable tables.

Change-Id: Id137f61a3249ffbf983e56de50d8d67a336b676f
---
M lib/wt2html/pp/handlers/linter.js
M tests/mocha/linter.js
2 files changed, 127 insertions(+), 0 deletions(-)

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



diff --git a/lib/wt2html/pp/handlers/linter.js 
b/lib/wt2html/pp/handlers/linter.js
index 0d7b005..b83ec0f 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/handlers/linter.js
@@ -260,6 +260,53 @@
        }
 }
 
+/*
+ * In this example below, the second table is in a fosterable position
+ * (inside a <tr>). The tree builder closes the first table at that point
+ * and starts a new table there. We are detecting this pattern because
+ * Tidy does something very different here. It strips the inner table
+ * and retains the outer table. So, for preserving rendering of pages
+ * that are tailored for Tidy, editors have to fix up this wikitext
+ * to strip the inner table (to mimic what Tidy does).
+ *
+ *   {| style='border:1px solid red;'
+ *   |a
+ *   |-
+ *   {| style='border:1px solid blue;'
+ *   |b
+ *   |c
+ *   |}
+ *   |}
+*/
+function logDeletableTables(env, c, dp, tplInfo) {
+       var templateInfo;
+       if (c.nodeName === 'TABLE') {
+               var prev = DU.previousNonSepSibling(c);
+               if (prev && prev.nodeName === 'TABLE' && 
DU.getDataParsoid(prev).autoInsertedEnd) {
+                       var dsr;
+                       if (tplInfo) {
+                               templateInfo = { name: 
DU.findEnclosingTemplateName(tplInfo) };
+                               dsr = tplInfo.dsr;
+                       } else {
+                               // Identify the dsr-span of the opening tag
+                               // of the table that needs to be deleted
+                               dsr = Util.clone(dp.dsr);
+                               if (dsr[2]) {
+                                       dsr[1] = dsr[0] + dsr[2];
+                                       dsr[2] = 0;
+                                       dsr[3] = 0;
+                               }
+                       }
+                       var lintObj = {
+                               dsr: dsr,
+                               templateInfo: templateInfo,
+                               params: { name: 'table' },
+                       };
+                       env.log('lint/deletable-table-tag', lintObj);
+               }
+       }
+}
+
 function logWikitextFixups(node, env, atTopLevel, tplInfo) {
        // For now, don't run linter in subpipelines.
        // Only on the final DOM for the top-level page.
@@ -280,6 +327,9 @@
        // Log Ignored Table Attributes
        logIgnoredTableAttr(env, node, dp, tplInfo);
 
+       // Log deletable tables (T161341)
+       logDeletableTables(env, node, dp, tplInfo);
+
        // Log obsolete HTML tags
        logObsoleteHTMLTags(env, node, dp, tplInfo);
 
diff --git a/tests/mocha/linter.js b/tests/mocha/linter.js
index e5d0490..dce338c 100644
--- a/tests/mocha/linter.js
+++ b/tests/mocha/linter.js
@@ -205,5 +205,82 @@
                                result[0].dsr.should.include.members([ 0, 17, 
null, null ]);
                        });
                });
+               it('should identify deletable table tag for T161341 (1)', 
function() {
+                       var wt = [
+                               "{| style='border:1px solid red;'",
+                               "|a",
+                               "|-",
+                               "{| style='border:1px solid blue;'",
+                               "|b",
+                               "|c",
+                               "|}",
+                               "|}",
+                       ].join('\n');
+                       return parseWT(wt).then(function(result) {
+                               result.should.have.length(2);
+                               result[0].should.have.a.property("type", 
"deletable-table-tag");
+                               result[0].should.have.a.property("params");
+                               result[0].params.should.have.a.property("name", 
"table");
+                               result[0].dsr.should.include.members([ 39, 72, 
0, 0 ]);
+                       });
+               });
+               it('should identify deletable table tag for T161341 (2)', 
function() {
+                       var wt = [
+                               "{| style='border:1px solid red;'",
+                               "|a",
+                               "|-  ",
+                               "   <!--boo-->   ",
+                               "{| style='border:1px solid blue;'",
+                               "|b",
+                               "|c",
+                               "|}",
+                       ].join('\n');
+                       return parseWT(wt).then(function(result) {
+                               result.should.have.length(1);
+                               result[0].should.have.a.property("type", 
"deletable-table-tag");
+                               result[0].should.have.a.property("params");
+                               result[0].params.should.have.a.property("name", 
"table");
+                               result[0].dsr.should.include.members([ 58, 91, 
0, 0 ]);
+                       });
+               });
+               it('should identify deletable table tag for T161341 (3)', 
function() {
+                       var wt = [
+                               "{{1x|{{{!}}",
+                               "{{!}}a",
+                               "{{!}}-",
+                               "{{{!}}",
+                               "{{!}}b",
+                               "{{!}}c",
+                               "{{!}}}",
+                               "}}",
+                       ].join('\n');
+                       return parseWT(wt).then(function(result) {
+                               result.should.have.length(1);
+                               result[0].should.have.a.property("type", 
"deletable-table-tag");
+                               
result[0].should.have.a.property("templateInfo");
+                               
result[0].templateInfo.should.have.a.property("name", "1x");
+                               result[0].dsr.should.include.members([ 0, 56, 
0, 0 ]);
+                       });
+               });
+               it('should identify deletable table tag for T161341 (4)', 
function() {
+                       var wt = [
+                               "{{1x|{{{!}}",
+                               "{{!}}a",
+                               "{{!}}-",
+                               "}}",
+                               "{|",
+                               "|b",
+                               "|c",
+                               "|}",
+                       ].join('\n');
+                       return parseWT(wt).then(function(result) {
+                               result.should.have.length(2);
+                               result[1].should.have.a.property("type", 
"deletable-table-tag");
+                               
result[1].should.not.have.a.property("templateInfo");
+                               result[1].should.have.a.property("params");
+                               result[1].params.should.have.a.property("name", 
"table");
+                               result[1].dsr.should.include.members([ 29, 31, 
0, 0 ]);
+                       });
+               });
        });
 });

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id137f61a3249ffbf983e56de50d8d67a336b676f
Gerrit-PatchSet: 4
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: Legoktm <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to