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

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

WIP: Add linter detection for T161341

TODO:
1. More testing
2. mocha tests

Change-Id: Id137f61a3249ffbf983e56de50d8d67a336b676f
---
M lib/wt2html/pp/handlers/linter.js
1 file changed, 51 insertions(+), 0 deletions(-)


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

diff --git a/lib/wt2html/pp/handlers/linter.js 
b/lib/wt2html/pp/handlers/linter.js
index 0d7b005..370a435 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/handlers/linter.js
@@ -260,6 +260,54 @@
        }
 }
 
+/*
+ * 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 dsr;
+       var templateInfo;
+       if (c.nodeName === 'TABLE' && dp.autoInsertedEnd) {
+               var next = DU.nextNonSepSibling(c);
+               if (next && next.nodeName === 'TABLE') {
+                       var nextDsr;
+                       if (tplInfo) {
+                               templateInfo = { name: 
DU.findEnclosingTemplateName(tplInfo) };
+                               nextDsr = tplInfo.dsr;
+                       } else {
+                               // Identify the dsr-span of the opening tag
+                               // of the table that needs to be deleted
+                               nextDsr = 
Util.clone(DU.getDataParsoid(next).dsr);
+                               if (nextDsr[2]) {
+                                       nextDsr[1] = nextDsr[0] + nextDsr[2];
+                                       nextDsr[2] = 0;
+                                       nextDsr[3] = 0;
+                               }
+                       }
+                       var lintObj = {
+                               dsr: nextDsr,
+                               templateInfo: templateInfo,
+                               params: { name: next.nodeName.toLowerCase() },
+                       };
+                       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 +328,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);
 

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

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

Reply via email to