Subramanya Sastry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/56916
Change subject: Migrate trailing newlines out of nodes with auto-inserted end
tags
......................................................................
Migrate trailing newlines out of nodes with auto-inserted end tags
* If a node has its end-tag autoinserted, then it is safe to
migrated trailing newlines out of it. The serializer works best
when trailing newlines are outside HTML nodes, and this is part
of the series of fixes trying to get the DOM to conform to that.
Should we make the serializer more robust and not rely on this
assumption (ex: parsoid clients, VE)?
* Fixes the following snippet from: en:World of our own which itself
has fewer RT errors
{|
|<small>
a</small>
|}
* No change in parser test results (TODO: add new tests).
Change-Id: I82e73c8527bfcd52d72cdd7bfbf71bed9b88852b
---
M js/lib/mediawiki.DOMPostProcessor.js
1 file changed, 14 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/16/56916/1
diff --git a/js/lib/mediawiki.DOMPostProcessor.js
b/js/lib/mediawiki.DOMPostProcessor.js
index 8d4b21c..38fdcfe 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -652,12 +652,18 @@
// Migrate trailing newlines out of
function migrateTrailingNLs(elt, env) {
- // If a node ends a line in wikitext, or if it is the last node in
- // the DOM subtree rooted at a node that ends a line in wikitext, we
- // should migrate the newline out of it.
+
+ // We can migrate a newline out of a node if one of the following is
true:
+ // (1) The ends a line in wikitext (=> not a literal html tag)
+ // (2) The node has an auto-closed end-tag (wikitext-generated or
literal html tag)
+ // (3) It is the rightmost node in the DOM subtree rooted at a node
+ // that ends a line in wikitext
function canMigrateNLOutOfNode(node) {
// These nodes either end a line in wikitext (tr, li, dd, ol,
ul, dl, caption, p)
// or have implicit closing tags that can leak newlines to
those that end a line (th, td)
+ //
+ // SSS FIXME: Given condition 2, we may not need to check th/td
anymore
+ // (if we can rely on auto inserted start/end tags being
present always).
var nodesToMigrateFrom = Util.arrayToHash([
"th", "td", "tr", "li", "dd", "ol", "ul", "dl",
"caption", "p"
]);
@@ -666,7 +672,11 @@
return nodesToMigrateFrom[node.nodeName.toLowerCase()]
&& !DU.isLiteralHTMLNode(node);
}
- return node && (nodeEndsLineInWT(node) || (!node.nextSibling &&
canMigrateNLOutOfNode(node.parentNode)));
+ return node && (
+ nodeEndsLineInWT(node) ||
+ (DU.isElt(node) &&
DU.dataParsoid(node).autoInsertedEnd) ||
+ (!node.nextSibling &&
canMigrateNLOutOfNode(node.parentNode))
+ );
}
// A node has zero wt width if:
--
To view, visit https://gerrit.wikimedia.org/r/56916
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I82e73c8527bfcd52d72cdd7bfbf71bed9b88852b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits