Merge "HACK: Don't merge adjacent annotations from Parsoid"

This commit is contained in:
jenkins-bot 2013-07-15 01:38:34 +00:00 committed by Gerrit Code Review
commit ffcee3bafa
3 changed files with 117 additions and 6 deletions

View file

@ -535,6 +535,77 @@ ve.dm.mwExample.references = [
];
ve.dm.mwExample.domToDataCases = {
'adjacent annotations': {
'html':
'<body>' +
'<b>a</b><b data-parsoid="1">b</b><b>c</b><b data-parsoid="2">d</b> ' +
'<b>a</b><b>b</b> ' +
'<b data-parsoid="3">ab</b><b data-parsoid="4">c</b>' +
'</body>',
'data': [
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
[ 'a', [ ve.dm.example.bold ] ],
[
'b',
[ {
'type': 'textStyle/bold',
'htmlAttributes': [ { 'values': {
'data-parsoid': '1'
} } ]
} ]
],
[ 'c', [ ve.dm.example.bold ] ],
[
'd',
[ {
'type': 'textStyle/bold',
'htmlAttributes': [ { 'values': {
'data-parsoid': '2'
} } ]
} ]
],
' ',
[ 'a', [ ve.dm.example.bold ] ],
[ 'b', [ ve.dm.example.bold ] ],
' ',
[
'a',
[ {
'type': 'textStyle/bold',
'htmlAttributes': [ { 'values': {
'data-parsoid': '3'
} } ]
} ]
],
[
'b',
[ {
'type': 'textStyle/bold',
'htmlAttributes': [ { 'values': {
'data-parsoid': '3'
} } ]
} ]
],
[
'c',
[ {
'type': 'textStyle/bold',
'htmlAttributes': [ { 'values': {
'data-parsoid': '4'
} } ]
} ]
],
{ 'type': '/paragraph' },
{ 'type': 'internalList' },
{ 'type': '/internalList' }
],
'normalizedHtml':
'<body>' +
'<b>abcd</b> ' +
'<b>ab</b> ' +
'<b data-parsoid="3">ab</b><b data-parsoid="4">c</b>' +
'</body>'
},
'mw:Image': {
'html': '<body><p>' + ve.dm.mwExample.MWInlineImageHtml + '</p></body>',
'data': [
@ -1433,7 +1504,17 @@ ve.dm.mwExample.domToDataCases = {
]
},
'attribute preservation does not crash due to text node split': {
'html': '<body><figure typeof="mw:Image/Thumb" data-parsoid="{}"><a href="Foo" data-parsoid="{}"><img src="Bar" width="1" height="2" resource="FooBar" data-parsoid="{}"></a><figcaption data-parsoid="{}"> foo <a rel="mw:WikiLink" href="./Bar" data-parsoid="{}">bar</a> baz</figcaption></figure></body>',
'html':
'<body>' +
'<figure typeof="mw:Image/Thumb" data-parsoid="{}">' +
'<a href="Foo" data-parsoid="{}">' +
'<img src="Bar" width="1" height="2" resource="FooBar" data-parsoid="{}">' +
'</a>' +
'<figcaption data-parsoid="{}">' +
' foo <a rel="mw:WikiLink" href="./Bar" data-parsoid="{}">bar</a> baz' +
'</figcaption>' +
'</figure>' +
'</body>',
'data': [
{
'type': 'mwBlockImage',

View file

@ -111,4 +111,37 @@ ve.dm.Annotation.prototype.getComparableObjectForSerialization = function () {
object.htmlAttributes = htmlAttributes;
}
return object;
};
};
/**
* HACK: Check if the annotation was generated by the converter
*
* Used by compareToForSerialization to avoid merging generated annotations.
*
* @returns {boolean} The annotation was generated
*/
ve.dm.Annotation.prototype.isGenerated = function () {
var attributes = this.getHtmlAttributes();
return attributes[0] && attributes[0].values && attributes[0].values['data-parsoid'];
};
/**
* HACK: Compare to another annotation for serialization
*
* Compares two annotations using getComparableObjectForSerialization, unless
* they are both generated annotations, in which case they must be identical.
*
* @param {ve.dm.Annotation} annotation Annotation to compare to
* @returns {boolean} The other annotation is similar to this one
*/
ve.dm.Annotation.prototype.compareToForSerialization = function ( annotation ) {
// If both annotations were generated
if ( this.isGenerated() && annotation.isGenerated() ) {
return ve.compare( this, annotation );
}
return ve.compare(
this.getComparableObjectForSerialization(),
annotation.getComparableObjectForSerialization()
);
};

View file

@ -268,10 +268,7 @@ ve.dm.AnnotationSet.prototype.containsComparable = function ( annotation ) {
*/
ve.dm.AnnotationSet.prototype.containsComparableForSerialization = function ( annotation ) {
return this.filter( function ( a ) {
return ve.compare(
annotation.getComparableObjectForSerialization(),
a.getComparableObjectForSerialization()
);
return annotation.compareToForSerialization( a );
}, true );
};