This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree 1 file changed +21
-12
lines changed
1 file changed +21
-12
lines changed Original file line number Diff line number Diff line change 8
8
*/
9
9
10
10
import Plugin from '@ckeditor/ckeditor5-core/src/plugin' ;
11
- import { attributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/two-way-converters' ;
12
11
13
12
import HighlightCommand from './highlightcommand' ;
14
13
@@ -50,23 +49,33 @@ export default class HighlightEditing extends Plugin {
50
49
51
50
const options = editor . config . get ( 'highlight.options' ) ;
52
51
53
- attributeToElement ( editor . conversion , 'highlight' , options . map ( _getConverterDefinition ) ) ;
52
+ // Set-up the two-way conversion.
53
+ editor . conversion . attributeToElement ( _buildDefinition ( options ) ) ;
54
54
55
55
editor . commands . add ( 'highlight' , new HighlightCommand ( editor ) ) ;
56
56
}
57
57
}
58
58
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.
61
60
//
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 ] = {
68
75
name : 'mark' ,
69
76
class : option . class
70
- }
71
- } ;
77
+ } ;
78
+ }
79
+
80
+ return definition ;
72
81
}
You can’t perform that action at this time.
0 commit comments