jenkins-bot has submitted this change and it was merged.
Change subject: HACK: Don't merge adjacent annotations from Parsoid
......................................................................
HACK: Don't merge adjacent annotations from Parsoid
Adjacent annotations should not be merged if they both
originate from Parsoid. This is a hack because this logic
should be in Parsoid, not VE.
Bug: 49873
Change-Id: If1e23e3039178300d72b1c0c585931417bb603b5
---
M modules/ve-mw/test/dm/ve.dm.mwExample.js
M modules/ve/dm/ve.dm.Annotation.js
M modules/ve/dm/ve.dm.AnnotationSet.js
3 files changed, 117 insertions(+), 6 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve-mw/test/dm/ve.dm.mwExample.js
b/modules/ve-mw/test/dm/ve.dm.mwExample.js
index d343293..3373912 100644
--- a/modules/ve-mw/test/dm/ve.dm.mwExample.js
+++ b/modules/ve-mw/test/dm/ve.dm.mwExample.js
@@ -535,6 +535,77 @@
];
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 @@
]
},
'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',
diff --git a/modules/ve/dm/ve.dm.Annotation.js
b/modules/ve/dm/ve.dm.Annotation.js
index 305b3a9..0f8ccc4 100644
--- a/modules/ve/dm/ve.dm.Annotation.js
+++ b/modules/ve/dm/ve.dm.Annotation.js
@@ -111,4 +111,37 @@
object.htmlAttributes = htmlAttributes;
}
return object;
-};
\ No newline at end of file
+};
+
+/**
+ * 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()
+ );
+};
diff --git a/modules/ve/dm/ve.dm.AnnotationSet.js
b/modules/ve/dm/ve.dm.AnnotationSet.js
index 0a7eb79..bb62a49 100644
--- a/modules/ve/dm/ve.dm.AnnotationSet.js
+++ b/modules/ve/dm/ve.dm.AnnotationSet.js
@@ -268,10 +268,7 @@
*/
ve.dm.AnnotationSet.prototype.containsComparableForSerialization = function (
annotation ) {
return this.filter( function ( a ) {
- return ve.compare(
- annotation.getComparableObjectForSerialization(),
- a.getComparableObjectForSerialization()
- );
+ return annotation.compareToForSerialization( a );
}, true );
};
--
To view, visit https://gerrit.wikimedia.org/r/73523
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If1e23e3039178300d72b1c0c585931417bb603b5
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits