Arlolra has uploaded a new change for review. https://gerrit.wikimedia.org/r/230943
Change subject: Don't migrate trailing whitespace in anchors in rtTestMode ...................................................................... Don't migrate trailing whitespace in anchors in rtTestMode * Reduces the noise in our roundtrip testing. * Also, just drop the trailing whitespace, rather than migrating it out, if next text node starts with spaces. * Examples, enwiki/Annona_conica enwiki/Accra_International_Conference_Centre and many more ... Change-Id: I3ebdc361128c6c2750925ff1a7a32dcf6a9d9b33 --- M lib/wts.normalizeDOM.js M tests/parserTests.txt 2 files changed, 30 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/43/230943/1 diff --git a/lib/wts.normalizeDOM.js b/lib/wts.normalizeDOM.js index f7937c9..cf65fbd 100644 --- a/lib/wts.normalizeDOM.js +++ b/lib/wts.normalizeDOM.js @@ -199,6 +199,29 @@ } }; +Normalizer.prototype.moveTrailingSpacesOut = function(node) { + var next = DU.nextNonDeletedSibling(node); + var last = DU.lastNonDeletedChildNode(node); + var endsInSpace = DU.isText(last) && last.nodeValue.match(/\s+$/); + // Conditional on rtTestMode to reduce the noise in testing. + if (!this.inRtTestMode && endsInSpace) { + last.nodeValue = last.nodeValue.substring(0, endsInSpace.index); + if (!DU.isText(next)) { + var txt = node.ownerDocument.createTextNode(''); + node.parentNode.insertBefore(txt, next); + next = txt; + } + // Try to be a little smarter and drop the spaces if possible. + if (!/^\s+/.test(next.nodeValue)) { + next.nodeValue = endsInSpace[0] + next.nodeValue; + // next (a text node) is new / had new content added to it + this.addDiffMarks(next, 'inserted'); + } + this.addDiffMarks(node, 'children-changed'); + this.addDiffMarks(node.parentNode, 'children-changed'); + } +}; + /** * Normalizations implemented right now: * ------------------------------------- @@ -240,24 +263,7 @@ if (/^mw:WikiLink$/.test(node.getAttribute('rel')) && this.stripIfEmpty(node) !== node) { return next; } - var last = DU.lastNonDeletedChildNode(node); - var endsInSpace = DU.isText(last) && last.nodeValue.match(/\s+$/); - // Move trailing spaces out of links - if (endsInSpace) { - last.nodeValue = last.nodeValue.substring(0, endsInSpace.index); - if (!DU.isText(next)) { - var txt = node.ownerDocument.createTextNode(''); - node.parentNode.insertBefore(txt, next); - next = txt; - } - next.nodeValue = endsInSpace[0] + next.nodeValue; - - // Update diff markers - // next (a text node) is new / had new content added to it - this.addDiffMarks(next, 'inserted'); - this.addDiffMarks(node, 'children-changed'); - this.addDiffMarks(node.parentNode, 'children-changed'); - } + this.moveTrailingSpacesOut(node); return node; // Table cells @@ -270,7 +276,6 @@ this.addDiffMarks(first, 'inserted', true); this.addDiffMarks(node, 'children-changed'); } - return node; // Default diff --git a/tests/parserTests.txt b/tests/parserTests.txt index d96347d..df5f5cd 100644 --- a/tests/parserTests.txt +++ b/tests/parserTests.txt @@ -25405,10 +25405,13 @@ !! html/parsoid <p><a rel="mw:WikiLink" href="./Berlin" title="Berlin">Berlin </a>is the capital of Germany.</p> <p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo </a><b>bar</b></p> +<p><a rel="mw:WikiLink" href="./Boston" title="Boston">Boston </a> is a city.</p> !! wikitext [[Berlin ]]<nowiki/>is the capital of Germany. [[Foo ]]'''bar''' + +[[Boston ]] is a city. !! end !! test @@ -25421,10 +25424,13 @@ !! html/parsoid <p><a rel="mw:WikiLink" href="./Berlin" title="Berlin">Berlin </a>is the capital of Germany.</p> <p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo </a><b>bar</b></p> +<p><a rel="mw:WikiLink" href="./Boston" title="Boston">Boston </a> is a city.</p> !! wikitext [[Berlin]] is the capital of Germany. [[Foo]] '''bar''' + +[[Boston]] is a city. !! end !! test -- To view, visit https://gerrit.wikimedia.org/r/230943 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3ebdc361128c6c2750925ff1a7a32dcf6a9d9b33 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Arlolra <abrea...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits