Subramanya Sastry has uploaded a new change for review.

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

Change subject: T53444: Strip <br>s from headings via new HTML normalization 
routine
......................................................................

T53444: Strip <br>s from headings via new HTML normalization routine

* Added parser tests that spec behavior.

Change-Id: Ia80e07be71cb2d10beb440bb075edc4e93f6399a
---
M lib/html2wt/normalizeDOM.js
M tests/parserTests.txt
2 files changed, 43 insertions(+), 0 deletions(-)


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

diff --git a/lib/html2wt/normalizeDOM.js b/lib/html2wt/normalizeDOM.js
index 1363bad..309e92e 100644
--- a/lib/html2wt/normalizeDOM.js
+++ b/lib/html2wt/normalizeDOM.js
@@ -231,6 +231,21 @@
        }
 };
 
+Normalizer.prototype.stripBRs = function(node) {
+       var child = node.firstChild;
+       while (child) {
+               var next = child.nextSibling;
+               if (child.nodeName === 'BR') {
+                       // replace <br/> with a single space
+                       node.removeChild(child);
+                       node.insertBefore(node.ownerDocument.createTextNode(' 
'), next);
+               } else if (DU.isElt(child)) {
+                       stripBRs(node);
+               }
+               child = next;
+       }
+};
+
 /**
  * Normalizations implemented right now:
  * -------------------------------------
@@ -239,6 +254,7 @@
  * 3. Force SOL transparent links to serialize before/after heading
  * 4. Trailing spaces are migrated out of links
  * 5. Space is added before escapable prefixes in table cells
+ * 6. Strip <br/> from headings
  */
 Normalizer.prototype.normalizeNode = function(node) {
        // Only if scrubWikitext flag is enabled
@@ -261,6 +277,7 @@
        if (/^H[1-6]$/.test(node.nodeName)) {
                this.hoistLinks(node, false);
                this.hoistLinks(node, true);
+               this.stripBRs(node);
                return this.stripIfEmpty(node);
 
        // Quote tags
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 324a4e0..9c4e58b 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -24910,6 +24910,32 @@
 !! end
 
 !! test
+Headings: Replace <br/> with a single whitespace char (when scrubWikitext = 
true)
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": true
+}
+!! html/parsoid
+<h2>foo<br/>bar</h2>
+!! wikitext
+== foo bar ==
+!! end
+
+!! test
+Headings: Replace <br/> with a single whitespace char (when scrubWikitext = 
false)
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": false
+}
+!! html/parsoid
+<h2>foo<br/>bar</h2>
+!! wikitext
+== foo<br> bar ==
+!! end
+
+!! test
 Parsoid: Serialize positional parameters with = in them as named parameter
 !! options
 parsoid=html2wt

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

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