jenkins-bot has submitted this change and it was merged.

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, 46 insertions(+), 0 deletions(-)

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



diff --git a/lib/html2wt/normalizeDOM.js b/lib/html2wt/normalizeDOM.js
index 1363bad..47ee798 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)) {
+                       this.stripBRs(child);
+               }
+               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..7b3fe9f 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -25725,6 +25725,35 @@
 !! 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>
+<h2>foo <span><br/>bar</span> baz</h2>
+!! wikitext
+== foo bar ==
+
+== foo <span> bar</span> baz ==
+!! 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
 1. WT Quote Tags: suppress newly created empty style tags
 !! options
 parsoid={

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia80e07be71cb2d10beb440bb075edc4e93f6399a
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to