Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 3e2d2cd

Browse files
committed
Changed: Aligning with new conversion helpers API.
1 parent 10227bd commit 3e2d2cd

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/highlightediting.js

+21-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
11-
import { attributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/two-way-converters';
1211

1312
import HighlightCommand from './highlightcommand';
1413

@@ -50,23 +49,33 @@ export default class HighlightEditing extends Plugin {
5049

5150
const options = editor.config.get( 'highlight.options' );
5251

53-
attributeToElement( editor.conversion, 'highlight', options.map( _getConverterDefinition ) );
52+
// Set-up the two-way conversion.
53+
editor.conversion.attributeToElement( _buildDefinition( options ) );
5454

5555
editor.commands.add( 'highlight', new HighlightCommand( editor ) );
5656
}
5757
}
5858

59-
// Converts {@link module:highlight/highlight~HighlightOption}
60-
// to {@link module:engine/conversion/definition-based-converters~ConverterDefinition}
59+
// Converts options array to a converter definition.
6160
//
62-
// @param {module:highlight/highlight~HighlightOption} option
63-
// @returns {module:engine/conversion/definition-based-converters~ConverterDefinition}
64-
function _getConverterDefinition( option ) {
65-
return {
66-
model: option.model,
67-
view: {
61+
// @param {Array.<module:highlight/highlight~HighlightOption>} options Array with configured options.
62+
// @returns {module:engine/conversion/conversion~ConverterDefinition}
63+
function _buildDefinition( options ) {
64+
const definition = {
65+
model: {
66+
key: 'highlight',
67+
values: []
68+
},
69+
view: {}
70+
};
71+
72+
for ( const option of options ) {
73+
definition.model.values.push( option.model );
74+
definition.view[ option.model ] = {
6875
name: 'mark',
6976
class: option.class
70-
}
71-
};
77+
};
78+
}
79+
80+
return definition;
7281
}

0 commit comments

Comments
 (0)