Subramanya Sastry has uploaded a new change for review.

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


Change subject: WIP: (Bug 57276) Update <pre> sep constraints in serializer
......................................................................

WIP: (Bug 57276) Update <pre> sep constraints in serializer

Change-Id: I24ff084301d7f188e0d64a7034659193fa20ae34
---
M js/lib/mediawiki.WikitextSerializer.js
M js/tests/parserTests-blacklist.js
2 files changed, 39 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid 
refs/changes/65/97165/1

diff --git a/js/lib/mediawiki.WikitextSerializer.js 
b/js/lib/mediawiki.WikitextSerializer.js
index 9117d6b..951a951 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -2674,24 +2674,54 @@
                                content = ' ' +
                                        
content.replace(/(\n(<!--(?:[^\-]|\-(?!\->))*\-\->)*)(?!$)/g, '$1 ' );
 
-                               // Strip trailing separators
-                               //var trailingSep = content.match(/\s*$/);
-                               //content = content.replace(/\s*$/, '');
-
                                cb(content, node);
 
-                               // Preserve separator source
-                               //state.sep.src = trailingSep && trailingSep[0] 
|| '';
                                state.sep.src = '';
                        }
                        state.inIndentPre = false;
                },
                sepnls: {
                        before: function(node, otherNode) {
-                               return node.data.parsoid.stx === 'html' ? {} : 
{min:1};
+                               if (node.data.parsoid.stx === 'html') {
+                                       return {};
+                               } else if (otherNode.nodeName === 'PRE') {
+                                       var minNLs = 2, maxNLs = 0;
+                                       if (DU.isText(node.firstChild)) {
+                                               var nlMatch = 
node.firstChild.nodeValue.match(/^(\n*)/);
+                                               minNLs = 2 - nlMatch[1].length;
+                                               maxNLs += nlMatch[1].length;
+                                       }
+                                       if (DU.isText(otherNode.lastChild)) {
+                                               var nlMatch = 
otherNode.lastChild.nodeValue.match(/[^]*?(\n*)$/);
+                                               minNLs = minNLs - 
nlMatch[1].length;
+                                               maxNLs += nlMatch[1].length;
+                                       }
+                                       console.warn("maxNLs: " + maxNLs);
+                                       return {min: minNLs < 0 ? 0 : minNLs, 
max: maxNLs < 2 ? 2 : maxNLs};
+                               } else {
+                                       return {min:1};
+                               }
                        },
                        after: function(node, otherNode) {
-                               return node.data.parsoid.stx === 'html' ? {} : 
{min:1};
+                               if (node.data.parsoid.stx === 'html') {
+                                       return {};
+                               } else if (otherNode.nodeName === 'PRE') {
+                                       var minNLs = 2, maxNLs = 0;
+                                       if (DU.isText(otherNode.firstChild)) {
+                                               var nlMatch = 
otherNode.firstChild.nodeValue.match(/^(\n*)/);
+                                               minNLs = minNLs - 
nlMatch[1].length;
+                                               maxNLs += nlMatch[1].length;
+                                       }
+                                       if (DU.isText(node.lastChild)) {
+                                               var nlMatch = 
node.lastChild.nodeValue.match(/[^]*?(\n*)$/);
+                                               minNLs = minNLs - 
nlMatch[1].length;
+                                               maxNLs += nlMatch[1].length;
+                                       }
+                                       console.warn("maxNLs: " + maxNLs);
+                                       return {min: minNLs < 0 ? 0 : minNLs, 
max: maxNLs < 2 ? 2 : maxNLs};
+                               } else {
+                                       return {min:1};
+                               }
                        }
                }
        },
diff --git a/js/tests/parserTests-blacklist.js 
b/js/tests/parserTests-blacklist.js
index d66ce46..11abadb 100644
--- a/js/tests/parserTests-blacklist.js
+++ b/js/tests/parserTests-blacklist.js
@@ -712,7 +712,6 @@
 add("html2html", "<pre> with forbidden attribute values (bug 3202)");
 add("html2html", "<nowiki> inside <pre> (bug 13238)");
 add("html2html", "Empty pre; pre inside other HTML tags (bug 54946)");
-add("html2html", "HTML pre followed by indent-pre");
 add("html2html", "3a. Indent-Pre and block tags (single-line html)");
 add("html2html", "3b. Indent-Pre and block tags (pre-content on separate 
line)");
 add("html2html", "4. Multiple spaces at start-of-line");
@@ -2455,6 +2454,7 @@
 add("selser", "6. Pre-blocks should extend across lines with leading WS even 
when there is no wrappable content [0,2,0,0,0]", " a\n \n <!-- continue -->\n 
b\n\n c\n \nd");
 add("selser", "6. Pre-blocks should extend across lines with leading WS even 
when there is no wrappable content [2,4,0,0,3]", "iinv6rmhb9e8kt9\n a\n \n <!-- 
continue -->\n b\n\n c\n \n");
 add("selser", "6. Pre-blocks should extend across lines with leading WS even 
when there is no wrappable content [[3,0,0],4,0,2,4]", " a\n \n <!-- continue 
-->\n b\n\n c\n \n1trt4nooes7qr529");
+add("selser", "6. Pre-blocks should extend across lines with leading WS even 
when there is no wrappable content [3,3,2,2,3]", "\ns0pc83i87b6v42t9\n c\n \n");
 add("selser", "6. Pre-blocks should extend across lines with leading WS even 
when there is no wrappable content [0,0,0,4,[2]]", " a\n \n <!-- continue -->\n 
b\n\n c\n \nd");
 add("selser", "HTML-pre: 1. embedded newlines [0,0,0,0,2,4,[4]]", 
"<pre>foo</pre>\n\n<pre>\nfoo\n</pre>\n\n0j7m5dwvy5t81tt9<pre>\n\nfoo\n</pre>\n\n<pre>\n\n\nfoo\n</pre>");
 add("selser", "HTML-pre: 1. embedded newlines [0,2,[4],0,[4],3,2]", 
"<pre>foo</pre>\n\n<pre>\nfoo\n</pre>\n\n<pre>\n\nfoo\n</pre>\n\n7ysmnukvidpctyb9<pre>\n\n\nfoo\n</pre>");

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I24ff084301d7f188e0d64a7034659193fa20ae34
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/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