mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 09:26:37 +00:00
Merge "Remove inserted leading whitespace"
This commit is contained in:
commit
cd9c38aa9a
|
@ -1672,7 +1672,6 @@ ve.dm.mwExample.domToDataCases = {
|
||||||
'data': ve.dm.mwExample.mwNowiki
|
'data': ve.dm.mwExample.mwNowiki
|
||||||
},
|
},
|
||||||
'mw:Nowiki unwraps when text modified': {
|
'mw:Nowiki unwraps when text modified': {
|
||||||
'html': null,
|
|
||||||
'data': ve.dm.mwExample.mwNowiki,
|
'data': ve.dm.mwExample.mwNowiki,
|
||||||
'modify': function ( data ) {
|
'modify': function ( data ) {
|
||||||
data[7][0] = 'z';
|
data[7][0] = 'z';
|
||||||
|
@ -1680,7 +1679,6 @@ ve.dm.mwExample.domToDataCases = {
|
||||||
'normalizedHtml': '<body><p>Foo[[Bzr]]Baz</p></body>'
|
'normalizedHtml': '<body><p>Foo[[Bzr]]Baz</p></body>'
|
||||||
},
|
},
|
||||||
'mw:Nowiki unwraps when annotations modified': {
|
'mw:Nowiki unwraps when annotations modified': {
|
||||||
'html': null,
|
|
||||||
'data': ve.dm.mwExample.mwNowiki,
|
'data': ve.dm.mwExample.mwNowiki,
|
||||||
'modify': function ( data ) {
|
'modify': function ( data ) {
|
||||||
data[7][1].push( ve.dm.example.bold );
|
data[7][1].push( ve.dm.example.bold );
|
||||||
|
|
|
@ -1040,7 +1040,7 @@ ve.dm.Converter.prototype.getDomFromData = function ( documentData, store, inter
|
||||||
* @throws Unbalanced data: looking for closing /type
|
* @throws Unbalanced data: looking for closing /type
|
||||||
*/
|
*/
|
||||||
ve.dm.Converter.prototype.getDomSubtreeFromData = function ( data, container ) {
|
ve.dm.Converter.prototype.getDomSubtreeFromData = function ( data, container ) {
|
||||||
var text, i, j, annotations, dataElement, dataElementOrSlice,
|
var text, i, j, isStart, annotations, dataElement, dataElementOrSlice,
|
||||||
childDomElements, pre, ours, theirs, parentDomElement, lastChild, isContentNode, sibling,
|
childDomElements, pre, ours, theirs, parentDomElement, lastChild, isContentNode, sibling,
|
||||||
previousSiblings, doUnwrap, textNode, type, annotatedDomElementStack, annotatedDomElements,
|
previousSiblings, doUnwrap, textNode, type, annotatedDomElementStack, annotatedDomElements,
|
||||||
dataLen = data.length,
|
dataLen = data.length,
|
||||||
|
@ -1151,9 +1151,16 @@ ve.dm.Converter.prototype.getDomSubtreeFromData = function ( data, container ) {
|
||||||
if ( typeof data[i] === 'string' ) {
|
if ( typeof data[i] === 'string' ) {
|
||||||
// Text
|
// Text
|
||||||
text = '';
|
text = '';
|
||||||
|
isStart = i > 0 &&
|
||||||
|
ve.dm.LinearData.static.isOpenElementData( data[i-1] ) &&
|
||||||
|
ve.dm.LinearData.static.getType( data[i-1] ) !== 'preformatted';
|
||||||
// Continue forward as far as the plain text goes
|
// Continue forward as far as the plain text goes
|
||||||
while ( typeof data[i] === 'string' ) {
|
while ( typeof data[i] === 'string' ) {
|
||||||
text += data[i];
|
// HACK: Skip over leading whitespace (bug 51462) in non-pre tags
|
||||||
|
if ( !( isStart && data[i].match( /\s/ ) ) ) {
|
||||||
|
text += data[i];
|
||||||
|
isStart = false;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
// i points to the first non-text thing, go back one so we don't skip this later
|
// i points to the first non-text thing, go back one so we don't skip this later
|
||||||
|
|
|
@ -894,6 +894,25 @@ ve.dm.example.domToDataCases = {
|
||||||
{ 'type': '/internalList' }
|
{ 'type': '/internalList' }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
'strip leading whitepsace in paragraphs': {
|
||||||
|
'data': [
|
||||||
|
{ 'type': 'paragraph' },
|
||||||
|
' ', 'f', 'o', 'o',
|
||||||
|
{ 'type': '/paragraph' },
|
||||||
|
{ 'type': 'paragraph' },
|
||||||
|
' ', '\t', ' ', '\t', 'b', 'a', 'r',
|
||||||
|
{ 'type': '/paragraph' },
|
||||||
|
{ 'type': 'heading', 'attributes': { 'level': 2 } },
|
||||||
|
' ', ' ', 'b', 'a', 'z',
|
||||||
|
{ 'type': '/heading' },
|
||||||
|
{ 'type': 'preformatted' },
|
||||||
|
' ', '\t', 'q', 'u', 'u', 'x',
|
||||||
|
{ 'type': '/preformatted' },
|
||||||
|
{ 'type': 'internalList' },
|
||||||
|
{ 'type': '/internalList' }
|
||||||
|
],
|
||||||
|
'normalizedHtml': '<body><p>foo</p><p>bar</p><h2>baz</h2><pre> \tquux</pre></body>'
|
||||||
|
},
|
||||||
'image': {
|
'image': {
|
||||||
'html': '<body><img src="' + ve.dm.example.imgSrc + '"></body>',
|
'html': '<body><img src="' + ve.dm.example.imgSrc + '"></body>',
|
||||||
'data': [
|
'data': [
|
||||||
|
@ -1300,7 +1319,6 @@ ve.dm.example.domToDataCases = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'empty document with content added by the editor': {
|
'empty document with content added by the editor': {
|
||||||
'html': null,
|
|
||||||
'data': [
|
'data': [
|
||||||
{ 'type': 'paragraph', 'internal': { 'generated': 'empty' } },
|
{ 'type': 'paragraph', 'internal': { 'generated': 'empty' } },
|
||||||
'F',
|
'F',
|
||||||
|
@ -1313,7 +1331,6 @@ ve.dm.example.domToDataCases = {
|
||||||
'normalizedHtml': '<body><p>Foo</p></body>'
|
'normalizedHtml': '<body><p>Foo</p></body>'
|
||||||
},
|
},
|
||||||
'empty list item with content added by the editor': {
|
'empty list item with content added by the editor': {
|
||||||
'html': null,
|
|
||||||
'data': [
|
'data': [
|
||||||
{ 'type': 'list', 'attributes': { 'style': 'bullet' } },
|
{ 'type': 'list', 'attributes': { 'style': 'bullet' } },
|
||||||
{ 'type': 'listItem' },
|
{ 'type': 'listItem' },
|
||||||
|
@ -2178,7 +2195,6 @@ ve.dm.example.domToDataCases = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'mismatching whitespace data is ignored': {
|
'mismatching whitespace data is ignored': {
|
||||||
'html': null,
|
|
||||||
'data': [
|
'data': [
|
||||||
{ 'type': 'list', 'attributes': { 'style': 'bullet' }, 'internal': { 'whitespace': [ ' ', ' ', ' ', ' ' ] } },
|
{ 'type': 'list', 'attributes': { 'style': 'bullet' }, 'internal': { 'whitespace': [ ' ', ' ', ' ', ' ' ] } },
|
||||||
{ 'type': 'listItem', 'internal': { 'whitespace': [ ' ', ' ', ' ', ' ' ] } },
|
{ 'type': 'listItem', 'internal': { 'whitespace': [ ' ', ' ', ' ', ' ' ] } },
|
||||||
|
|
|
@ -54,7 +54,7 @@ ve.test.utils.runGetDataFromDomTests = function( assert, cases ) {
|
||||||
ve.dm.modelRegistry.register( ve.dm.PreformattedNode );
|
ve.dm.modelRegistry.register( ve.dm.PreformattedNode );
|
||||||
|
|
||||||
for ( msg in cases ) {
|
for ( msg in cases ) {
|
||||||
if ( cases[msg].html !== null ) {
|
if ( cases[msg].html !== undefined ) {
|
||||||
n++;
|
n++;
|
||||||
if ( cases[msg].storeItems ) {
|
if ( cases[msg].storeItems ) {
|
||||||
n += cases[msg].storeItems.length;
|
n += cases[msg].storeItems.length;
|
||||||
|
@ -64,7 +64,7 @@ ve.test.utils.runGetDataFromDomTests = function( assert, cases ) {
|
||||||
QUnit.expect( n );
|
QUnit.expect( n );
|
||||||
|
|
||||||
for ( msg in cases ) {
|
for ( msg in cases ) {
|
||||||
if ( cases[msg].html !== null ) {
|
if ( cases[msg].html !== undefined ) {
|
||||||
doc = new ve.dm.Document( [] );
|
doc = new ve.dm.Document( [] );
|
||||||
store = doc.getStore();
|
store = doc.getStore();
|
||||||
internalList = doc.getInternalList();
|
internalList = doc.getInternalList();
|
||||||
|
|
Loading…
Reference in a new issue