Subramanya Sastry has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398649 )

Change subject: Linter: Additional updates to multiline-html-table-in-list
......................................................................

Linter: Additional updates to multiline-html-table-in-list

* Handle HTML lists -- don't trigger linter issue there
* Handle dl/dt lists -- trigger linter issue there
* Added new tests

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


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

diff --git a/lib/wt2html/pp/handlers/linter.js 
b/lib/wt2html/pp/handlers/linter.js
index caa1891..c414d87 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/handlers/linter.js
@@ -874,19 +874,27 @@
        detectMultipleUnclosedFormattingTags(lints);
 }
 
-function hasListAncestor(node) {
-       while (node && node.nodeName !== 'LI') {
+function getWikitextListItemAncestor(node) {
+       while (node && !DU.isListItem(node)) {
                node = node.parentNode;
        }
 
+       // If the list item is a HTML list item, ignore it
        // If the list item comes from references content, ignore it
-       return node && 
!(/mw:Extension\/references/.test(node.parentNode.getAttribute('typeof')));
+       if (node && !DU.isLiteralHTMLNode(node) &&
+               
!(/mw:Extension\/references/.test(node.parentNode.getAttribute('typeof')))
+       )  {
+               return node;
+       } else {
+               return null;
+       }
 }
 
 function logPHPParserBug(env, node, dp, tplInfo) {
+       var li;
        if (!DU.isLiteralHTMLNode(node) ||
                node.nodeName !== 'TABLE' ||
-               !hasListAncestor(node) ||
+               !(li = getWikitextListItemAncestor(node)) ||
                !/\n/.test(node.outerHTML)
        ) {
                return;
@@ -901,7 +909,7 @@
                templateInfo: templateInfo,
                params: {
                        name: 'table',
-                       ancestorName: 'li',
+                       ancestorName: li.nodeName.toLowerCase(),
                }
        };
        env.log('lint/multiline-html-table-in-list', lintObj);
diff --git a/tests/mocha/linter.js b/tests/mocha/linter.js
index f1679db..a4f914f 100644
--- a/tests/mocha/linter.js
+++ b/tests/mocha/linter.js
@@ -912,6 +912,25 @@
                                        
result[0].params.should.have.a.property("ancestorName", "li");
                                });
                        });
+                       it('should detect multiline HTML tables in lists (3)', 
function() {
+                               return parseWT("; 
<table><tr><td>x</td></tr>\n</table>").then(function(result) {
+                                       result.should.have.length(1);
+                                       
result[0].should.have.a.property("type", "multiline-html-table-in-list");
+                                       
result[0].params.should.have.a.property("name", "table");
+                                       
result[0].params.should.have.a.property("ancestorName", "dt");
+                               });
+                       });
+                       it('should detect multiline HTML tables in lists (4)', 
function() {
+                               return parseWT(": 
<table><tr><td>x</td></tr>\n</table>").then(function(result) {
+                                       result.should.have.length(1);
+                                       
result[0].should.have.a.property("type", "multiline-html-table-in-list");
+                                       
result[0].params.should.have.a.property("name", "table");
+                                       
result[0].params.should.have.a.property("ancestorName", "dd");
+                               });
+                       });
+                       it('should not detect multiline HTML tables in HTML 
lists', function() {
+                               return 
expectEmptyResults("<ul><li><table>\n<tr><td>x</td></tr>\n</table>\n</li></ul>");
+                       });
                        it('should not detect single-line HTML tables in 
lists', function() {
                                return expectEmptyResults("* 
<div><table><tr><td>x</td></tr></table></div>");
                        });

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I33206f29cf9a9e6b9000091824eff2302d45bd32
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