Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/61919
Change subject: Whitespace fixes
......................................................................
Whitespace fixes
Two test cases - one fixed, one still broken.
Bug: 47712
Change-Id: I42daaf142e548e5b221ff0a52df0ad24ec6a4fd0
---
M modules/ve/dm/ve.dm.Converter.js
M modules/ve/test/dm/ve.dm.example.js
2 files changed, 93 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/19/61919/1
diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index 44b2774..e0d2baf 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -798,7 +798,9 @@
ve.dm.Converter.prototype.getDomSubtreeFromData = function ( data, container )
{
var text, i, j, annotations, annotationElement, dataElement,
dataElementOrSlice,
childDomElements, pre, ours, theirs, parentDomElement,
lastChild,
- isContentNode, sibling, previousSiblings, doUnwrap, textNode,
+ isContentNode, sibling, previousSiblings, doUnwrap,
+ textNode, type,
+ canContainContentStack = [],
conv = this,
doc = container.ownerDocument,
domElement = container,
@@ -935,9 +937,15 @@
dataElement = data[i];
// Element
if ( dataElement.type.charAt( 0 ) === '/' ) {
+ // Close element
parentDomElement = domElement.parentNode;
- isContentNode = !this.metaItemFactory.lookup(
data[i].type.substr( 1 ) ) &&
- this.nodeFactory.isNodeContent(
data[i].type.substr( 1 ) );
+ type = data[i].type.substr( 1 );
+ if ( this.metaItemFactory.lookup( type ) ) {
+ isContentNode =
canContainContentStack[canContainContentStack.length - 1];
+ } else {
+ isContentNode =
this.nodeFactory.isNodeContent( type );
+ canContainContentStack.pop();
+ }
// Process whitespace
// whitespace = [ outerPre, innerPre,
innerPost, outerPost ]
if (
@@ -1061,6 +1069,10 @@
domElement = parentDomElement;
} else {
// Create node from data
+ if ( !this.metaItemFactory.lookup( data[i].type
) ) {
+ canContainContentStack.push(
this.nodeFactory.canNodeContainContent( data[i].type ) );
+ }
+
dataElementOrSlice = getDataElementOrSlice();
childDomElements =
this.getDomElementsFromDataElement( dataElementOrSlice, doc );
if ( childDomElements ) {
diff --git a/modules/ve/test/dm/ve.dm.example.js
b/modules/ve/test/dm/ve.dm.example.js
index bb582da..052e930 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -2024,6 +2024,84 @@
{ 'type': '/MWlanguage' }
]
},
+ 'whitespace preservation with comment at end of table cell': {
+ 'html': '<body><table><tr><td> bar<!-- baz -->
</td></tr></body>',
+ 'data': [
+ { 'type': 'table' },
+ { 'type': 'tableSection', 'attributes': { 'style':
'body' } },
+ { 'type': 'tableRow' },
+ {
+ 'type': 'tableCell',
+ 'attributes': { 'style': 'data' },
+ 'internal': {
+ 'whitespace': [
+ undefined,
+ ' ',
+ ' '
+ ]
+ }
+ },
+ {
+ 'type': 'paragraph',
+ 'internal': {
+ 'generated': 'wrapper',
+ 'whitespace': [
+ ' ',
+ undefined,
+ undefined,
+ ' '
+ ]
+ }
+ },
+ 'b', 'a', 'r',
+ { 'type': '/paragraph' },
+ {
+ 'type': 'alienMeta',
+ 'attributes': {
+ 'style': 'comment',
+ 'text': ' baz '
+ }
+ },
+ { 'type': '/alienMeta' },
+ { 'type': '/tableCell' },
+ { 'type': '/tableRow' },
+ { 'type': '/tableSection' },
+ { 'type': '/table' }
+ ]
+ },
+ 'whitespace preservation with comment at start or end of element': {
+ 'html': '<body><p> <!-- foo -->bar<!-- baz --> </p></body>',
+ 'data': [
+ {
+ 'type': 'paragraph',
+ 'internal': {
+ 'whitespace': [
+ undefined,
+ ' ',
+ ' '
+ ]
+ }
+ },
+ {
+ 'type': 'alienMeta',
+ 'attributes': {
+ 'style': 'comment',
+ 'text': ' foo '
+ }
+ },
+ { 'type': '/alienMeta' },
+ 'b', 'a', 'r',
+ {
+ 'type': 'alienMeta',
+ 'attributes': {
+ 'style': 'comment',
+ 'text': ' baz '
+ }
+ },
+ { 'type': '/alienMeta' },
+ { 'type': '/paragraph' }
+ ]
+ },
'mismatching whitespace data is ignored': {
'html': null,
'data': [
--
To view, visit https://gerrit.wikimedia.org/r/61919
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I42daaf142e548e5b221ff0a52df0ad24ec6a4fd0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits