GWicke has uploaded a new change for review.
https://gerrit.wikimedia.org/r/73113
Change subject: Bug 50120: Avoid paragraph wrapping for DOM fragments with
blocks
......................................................................
Bug 50120: Avoid paragraph wrapping for DOM fragments with blocks
We represent DOM fragments in the token stream with wrapper tokens. For
multi-sibling fragments we represent the first and last sibling. In some rare
cases however those elements are inline, while a sibling or a child somewhere
in the DOMFragment contains a block-level element.
Additionally, these inlines need to be special content like categories that
are not normally be included in a paragraph. If they were not, then the
wrapping paragraph would straddle the transclusion content, which would in
turn disable fragment reuse.
Our paragraph wrapping was 'helpfully' broken up by the browser in a way that
broke up the encapsulation group for transclusion content. That then led to
the second half of that content bleeding out into the page on round-trip.
TODO:
* Re-parse HTML from source in round-trip testing with a compliant HTML parser
so that issues like this are picked up.
* Add DOM Fragment reuse testing to rt testing and possibly parserTests
Change-Id: I20f16ab0298092ec60070cbbe96ee8db419ce43f
---
M js/lib/mediawiki.DOMPostProcessor.js
M js/lib/mediawiki.DOMUtils.js
2 files changed, 17 insertions(+), 28 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/13/73113/1
diff --git a/js/lib/mediawiki.DOMPostProcessor.js
b/js/lib/mediawiki.DOMPostProcessor.js
index 485e2c9..8fe50bb 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -2617,32 +2617,6 @@
deleteNode(sibling);
}
- // Potentially undo paragraph wrapping.
- if (parentNode.nodeName === 'P' &&
- (parentNode.childNodes.length === 1 ||
- // This approximates the case where
there are more nodes,
- // but those would normally not
trigger a paragraph.
- // XXX gwicke: This can likely be
improved!
- /^[
\t]*$/.test(parentNode.textContent)))
- {
- // check if the content has a blocklevel element
- var hasBlock =
DU.hasBlockElementDescendant(dummyNode);
- //console.log(dummyNode.nodeName, hasBlock,
- //
JSON.stringify(dummyNode.textContent),
- // dummyNode.innerHTML);
- if (hasBlock || /^[
\t]*$/.test(dummyNode.textContent || '')) {
- // Block-level elements are not wrapped
into paragraphs,
- // so fix it up here. Remove the
parentNode and use its
- // parent instead.
- var newParent = parentNode.parentNode;
- while (parentNode.firstChild) {
- // move children up
-
newParent.insertBefore(parentNode.firstChild, parentNode);
- }
- deleteNode(parentNode);
- parentNode = newParent;
- }
- }
// Transfer the new dsr -- just dsr[0] and dsr[1] since
tag-widths
// will be incorrect for reuse of template expansions
diff --git a/js/lib/mediawiki.DOMUtils.js b/js/lib/mediawiki.DOMUtils.js
index 0d0b0b2..6bd5dde 100644
--- a/js/lib/mediawiki.DOMUtils.js
+++ b/js/lib/mediawiki.DOMUtils.js
@@ -874,8 +874,23 @@
// First, get two tokens representing the start element
var tokens = makeWrapperForNode ( nodes[0] );
- // If we have several sibling, also represent the last sibling.
- if (nodes.length > 1) {
+ var needBlockWrapper = false;
+ if (!DU.isBlockNode(nodes[0]) && !DU.isBlockNode(nodes.last()))
{
+ nodes.forEach(function(n) {
+ if (!needBlockWrapper &&
DU.hasBlockElementDescendant(n)) {
+ needBlockWrapper = true;
+ }
+ });
+ }
+
+ if (needBlockWrapper) {
+ // Create a block-level wrapper to suppress paragraph
+ // wrapping, as the fragment contains a block-level
element
+ // somewhere further down the tree.
+ var blockPlaceholder =
nodes[0].ownerDocument.createElement('hr');
+ tokens =
tokens.concat(makeWrapperForNode(blockPlaceholder));
+ } else if (nodes.length > 1) {
+ // If we have several siblings, also represent the last
sibling.
tokens =
tokens.concat(makeWrapperForNode(nodes.last()));
}
--
To view, visit https://gerrit.wikimedia.org/r/73113
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I20f16ab0298092ec60070cbbe96ee8db419ce43f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: GWicke <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits