jenkins-bot has submitted this change and it was merged.
Change subject: Record whitespace on generated empty paragraphs correctly
......................................................................
Record whitespace on generated empty paragraphs correctly
Whitespace was never recorded on generated: 'empty' paragraphs.
This was almost never noticeable because the linmod output
triggered a separate bug in the data->DOM where whitespace
consistency isn't checked correctly. This meant cases like
<li>\n</li> produced crazy linmod output (with the whitespace
being recorded twice on the li and not at all on the empty paragraph)
but still round-tripped correctly. The only case where
this caused round-trip failures was <body>\n</body>.
Change-Id: Iee23f477714fb56ae6829abb842470b93a4037cc
---
M src/dm/ve.dm.Converter.js
M tests/dm/ve.dm.example.js
2 files changed, 42 insertions(+), 6 deletions(-)
Approvals:
Esanders: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/dm/ve.dm.Converter.js b/src/dm/ve.dm.Converter.js
index 2e12030..189447b 100644
--- a/src/dm/ve.dm.Converter.js
+++ b/src/dm/ve.dm.Converter.js
@@ -608,7 +608,7 @@
var i, childNode, childNodes, childDataElements, text, childTypes,
matches,
wrappingParagraph, prevElement, childAnnotations, modelName,
modelClass,
- annotation, childIsContent, aboutGroup, htmlAttributes,
+ annotation, childIsContent, aboutGroup, htmlAttributes,
emptyParagraph,
modelRegistry = this.modelRegistry,
data = [],
nextWhitespace = '',
@@ -963,7 +963,9 @@
!this.nodeFactory.isNodeContent( context.branchType ) &&
( childTypes === null || ve.indexOf( 'paragraph', childTypes )
!== -1 )
) {
- data.push( { type: 'paragraph', internal: { generated: 'empty'
} } );
+ emptyParagraph = { type: 'paragraph', internal: { generated:
'empty' } };
+ processNextWhitespace( emptyParagraph );
+ data.push( emptyParagraph );
data.push( { type: '/paragraph' } );
}
@@ -980,10 +982,10 @@
}
// Don't return an empty document
if ( context.branchType === 'document' && isAllInstanceOf( data,
ve.dm.MetaItem ) && !annotationSet ) {
- return data.concat( [
- { type: 'paragraph', internal: { generated: 'empty' } },
- { type: '/paragraph' }
- ] );
+ emptyParagraph = { type: 'paragraph', internal: { generated:
'empty' } };
+ processNextWhitespace( emptyParagraph );
+ data.push( emptyParagraph );
+ data.push( { type: '/paragraph' } );
}
this.contextStack.pop();
diff --git a/tests/dm/ve.dm.example.js b/tests/dm/ve.dm.example.js
index 8f24515..fa02c5e 100644
--- a/tests/dm/ve.dm.example.js
+++ b/tests/dm/ve.dm.example.js
@@ -2467,6 +2467,40 @@
{ type: '/internalList' }
]
},
+ 'whitespace preservation in empty list item': {
+ body: '<ul><li>\n\t</li></ul>',
+ data: [
+ { type: 'list', attributes: { style: 'bullet' } },
+ { type: 'listItem', internal: { whitespace: [
undefined, '\n\t' ] } },
+ { type: 'paragraph', internal: { generated: 'empty',
whitespace: [ '\n\t' ] } },
+ { type: '/paragraph' },
+ { type: '/listItem' },
+ { type: '/list' },
+ { type: 'internalList' },
+ { type: '/internalList' }
+ ]
+ },
+ 'whitespace preservation in body with only plain text': {
+ body: ' Hello\n\t',
+ data: [
+ { type: 'paragraph', internal: { generated: 'wrapper',
whitespace: [ ' ', undefined, undefined, '\n\t' ] } },
+ 'H', 'e', 'l', 'l', 'o',
+ { type: '/paragraph' },
+ { type: 'internalList' },
+ { type: '/internalList' }
+ ],
+ innerWhitespace: [ ' ', '\n\t' ]
+ },
+ 'whitespace preservation in empty body': {
+ body: '\n\t',
+ data: [
+ { type: 'paragraph', internal: { generated: 'empty',
whitespace: [ '\n\t' ] } },
+ { type: '/paragraph' },
+ { type: 'internalList' },
+ { type: '/internalList' }
+ ],
+ innerWhitespace: [ '\n\t', undefined ]
+ },
'mismatching whitespace data is ignored': {
data: [
{ type: 'list', attributes: { style: 'bullet' },
internal: { whitespace: [ ' ', ' ', ' ', ' ' ] } },
--
To view, visit https://gerrit.wikimedia.org/r/179879
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iee23f477714fb56ae6829abb842470b93a4037cc
Gerrit-PatchSet: 2
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits