@ckeditor/ckeditor5-highlight 40.0.0 → 40.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +2 -2
- package/package.json +2 -2
- package/src/augmentation.d.ts +23 -23
- package/src/augmentation.js +5 -5
- package/src/highlight.d.ts +28 -28
- package/src/highlight.js +32 -32
- package/src/highlightcommand.d.ts +45 -45
- package/src/highlightcommand.js +91 -91
- package/src/highlightconfig.d.ts +171 -171
- package/src/highlightconfig.js +5 -5
- package/src/highlightediting.d.ts +28 -28
- package/src/highlightediting.js +109 -109
- package/src/highlightui.d.ts +73 -73
- package/src/highlightui.js +216 -216
- package/src/index.d.ts +13 -13
- package/src/index.js +11 -11
- package/build/highlight.js.map +0 -1
package/src/highlightconfig.d.ts
CHANGED
@@ -1,171 +1,171 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module highlight/highlightconfig
|
7
|
-
*/
|
8
|
-
/**
|
9
|
-
* The highlight option descriptor. See {@link module:highlight/highlightconfig~HighlightConfig} to learn more.
|
10
|
-
*
|
11
|
-
* ```ts
|
12
|
-
* {
|
13
|
-
* model: 'pinkMarker',
|
14
|
-
* class: 'marker-pink',
|
15
|
-
* title: 'Pink Marker',
|
16
|
-
* color: 'var(--ck-highlight-marker-pink)',
|
17
|
-
* type: 'marker'
|
18
|
-
* }
|
19
|
-
* ```
|
20
|
-
*/
|
21
|
-
export interface HighlightOption {
|
22
|
-
/**
|
23
|
-
* The user-readable title of the option.
|
24
|
-
*/
|
25
|
-
title: string;
|
26
|
-
/**
|
27
|
-
* The unique attribute value in the model.
|
28
|
-
*/
|
29
|
-
model: string;
|
30
|
-
/**
|
31
|
-
* The CSS `var()` used for the highlighter. The color is used in the user interface to represent the highlighter.
|
32
|
-
* There is a possibility to use the default color format like rgb, hex or hsl, but you need to care about the color of `<mark>`
|
33
|
-
* by adding CSS classes definition.
|
34
|
-
*/
|
35
|
-
color: string;
|
36
|
-
/**
|
37
|
-
* The CSS class used on the `<mark>` element in the view. It should match the `color` setting.
|
38
|
-
*/
|
39
|
-
class: string;
|
40
|
-
/**
|
41
|
-
* The type of highlighter:
|
42
|
-
*
|
43
|
-
* * `'marker'` – Uses the `color` as the `background-color` style,
|
44
|
-
* * `'pen'` – Uses the `color` as the font `color` style.
|
45
|
-
*/
|
46
|
-
type: 'marker' | 'pen';
|
47
|
-
}
|
48
|
-
/**
|
49
|
-
* The configuration of the {@link module:highlight/highlight~Highlight highlight feature}.
|
50
|
-
* ```ts
|
51
|
-
* ClassicEditor
|
52
|
-
* .create( editorElement, {
|
53
|
-
* highlight: ... // Highlight feature configuration.
|
54
|
-
* } )
|
55
|
-
* .then( ... )
|
56
|
-
* .catch( ... );
|
57
|
-
* ```
|
58
|
-
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
59
|
-
*/
|
60
|
-
export interface HighlightConfig {
|
61
|
-
/**
|
62
|
-
* The available highlight options. The default value is:
|
63
|
-
* ```ts
|
64
|
-
* options: [
|
65
|
-
* {
|
66
|
-
* model: 'yellowMarker',
|
67
|
-
* class: 'marker-yellow',
|
68
|
-
* title: 'Yellow marker',
|
69
|
-
* color: 'var(--ck-highlight-marker-yellow)',
|
70
|
-
* type: 'marker'
|
71
|
-
* },
|
72
|
-
* {
|
73
|
-
* model: 'greenMarker',
|
74
|
-
* class: 'marker-green',
|
75
|
-
* title: 'Green marker',
|
76
|
-
* color: 'var(--ck-highlight-marker-green)',
|
77
|
-
* type: 'marker'
|
78
|
-
* },
|
79
|
-
* {
|
80
|
-
* model: 'pinkMarker',
|
81
|
-
* class: 'marker-pink',
|
82
|
-
* title: 'Pink marker',
|
83
|
-
* color: 'var(--ck-highlight-marker-pink)',
|
84
|
-
* type: 'marker'
|
85
|
-
* },
|
86
|
-
* {
|
87
|
-
* model: 'blueMarker',
|
88
|
-
* class: 'marker-blue',
|
89
|
-
* title: 'Blue marker',
|
90
|
-
* color: 'var(--ck-highlight-marker-blue)',
|
91
|
-
* type: 'marker'
|
92
|
-
* },
|
93
|
-
* {
|
94
|
-
* model: 'redPen',
|
95
|
-
* class: 'pen-red',
|
96
|
-
* title: 'Red pen',
|
97
|
-
* color: 'var(--ck-highlight-pen-red)',
|
98
|
-
* type: 'pen'
|
99
|
-
* },
|
100
|
-
* {
|
101
|
-
* model: 'greenPen',
|
102
|
-
* class: 'pen-green',
|
103
|
-
* title: 'Green pen',
|
104
|
-
* color: 'var(--ck-highlight-pen-green)',
|
105
|
-
* type: 'pen'
|
106
|
-
* }
|
107
|
-
* ]
|
108
|
-
* ```
|
109
|
-
*
|
110
|
-
* There are two types of highlighters available:
|
111
|
-
*
|
112
|
-
* * `'marker'` – Rendered as a `<mark>` element, styled with the `background-color`.
|
113
|
-
* * `'pen'` – Rendered as a `<mark>` element, styled with the font `color`.
|
114
|
-
*
|
115
|
-
* **Note**: The highlight feature provides a stylesheet with the CSS classes and corresponding colors defined
|
116
|
-
* as CSS variables.
|
117
|
-
*
|
118
|
-
* ```css
|
119
|
-
* :root {
|
120
|
-
* --ck-highlight-marker-yellow: #fdfd77;
|
121
|
-
* --ck-highlight-marker-green: #63f963;
|
122
|
-
* --ck-highlight-marker-pink: #fc7999;
|
123
|
-
* --ck-highlight-marker-blue: #72cdfd;
|
124
|
-
* --ck-highlight-pen-red: #e91313;
|
125
|
-
* --ck-highlight-pen-green: #118800;
|
126
|
-
* }
|
127
|
-
*
|
128
|
-
* .marker-yellow { ... }
|
129
|
-
* .marker-green { ... }
|
130
|
-
* .marker-pink { ... }
|
131
|
-
* .marker-blue { ... }
|
132
|
-
* .pen-red { ... }
|
133
|
-
* .pen-green { ... }
|
134
|
-
* ```
|
135
|
-
*
|
136
|
-
* It is possible to define the `color` property directly as `rgba(R, G, B, A)`,
|
137
|
-
* `#RRGGBB[AA]` or `hsla(H, S, L, A)`. In such situation, the color will **only** apply to the UI of
|
138
|
-
* the editor and the `<mark>` elements in the content must be styled by custom classes provided by
|
139
|
-
* a dedicated stylesheet.
|
140
|
-
*
|
141
|
-
* **Note**: It is recommended for the `color` property to correspond to the class in the content
|
142
|
-
* stylesheet because it represents the highlighter in the user interface of the editor.
|
143
|
-
*
|
144
|
-
* ```ts
|
145
|
-
* ClassicEditor
|
146
|
-
* .create( editorElement, {
|
147
|
-
* highlight: {
|
148
|
-
* options: [
|
149
|
-
* {
|
150
|
-
* model: 'pinkMarker',
|
151
|
-
* class: 'marker-pink',
|
152
|
-
* title: 'Pink Marker',
|
153
|
-
* color: 'var(--ck-highlight-marker-pink)',
|
154
|
-
* type: 'marker'
|
155
|
-
* },
|
156
|
-
* {
|
157
|
-
* model: 'redPen',
|
158
|
-
* class: 'pen-red',
|
159
|
-
* title: 'Red Pen',
|
160
|
-
* color: 'var(--ck-highlight-pen-red)',
|
161
|
-
* type: 'pen'
|
162
|
-
* },
|
163
|
-
* ]
|
164
|
-
* }
|
165
|
-
* } )
|
166
|
-
* .then( ... )
|
167
|
-
* .catch( ... );
|
168
|
-
* ```
|
169
|
-
*/
|
170
|
-
options: Array<HighlightOption>;
|
171
|
-
}
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module highlight/highlightconfig
|
7
|
+
*/
|
8
|
+
/**
|
9
|
+
* The highlight option descriptor. See {@link module:highlight/highlightconfig~HighlightConfig} to learn more.
|
10
|
+
*
|
11
|
+
* ```ts
|
12
|
+
* {
|
13
|
+
* model: 'pinkMarker',
|
14
|
+
* class: 'marker-pink',
|
15
|
+
* title: 'Pink Marker',
|
16
|
+
* color: 'var(--ck-highlight-marker-pink)',
|
17
|
+
* type: 'marker'
|
18
|
+
* }
|
19
|
+
* ```
|
20
|
+
*/
|
21
|
+
export interface HighlightOption {
|
22
|
+
/**
|
23
|
+
* The user-readable title of the option.
|
24
|
+
*/
|
25
|
+
title: string;
|
26
|
+
/**
|
27
|
+
* The unique attribute value in the model.
|
28
|
+
*/
|
29
|
+
model: string;
|
30
|
+
/**
|
31
|
+
* The CSS `var()` used for the highlighter. The color is used in the user interface to represent the highlighter.
|
32
|
+
* There is a possibility to use the default color format like rgb, hex or hsl, but you need to care about the color of `<mark>`
|
33
|
+
* by adding CSS classes definition.
|
34
|
+
*/
|
35
|
+
color: string;
|
36
|
+
/**
|
37
|
+
* The CSS class used on the `<mark>` element in the view. It should match the `color` setting.
|
38
|
+
*/
|
39
|
+
class: string;
|
40
|
+
/**
|
41
|
+
* The type of highlighter:
|
42
|
+
*
|
43
|
+
* * `'marker'` – Uses the `color` as the `background-color` style,
|
44
|
+
* * `'pen'` – Uses the `color` as the font `color` style.
|
45
|
+
*/
|
46
|
+
type: 'marker' | 'pen';
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* The configuration of the {@link module:highlight/highlight~Highlight highlight feature}.
|
50
|
+
* ```ts
|
51
|
+
* ClassicEditor
|
52
|
+
* .create( editorElement, {
|
53
|
+
* highlight: ... // Highlight feature configuration.
|
54
|
+
* } )
|
55
|
+
* .then( ... )
|
56
|
+
* .catch( ... );
|
57
|
+
* ```
|
58
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
59
|
+
*/
|
60
|
+
export interface HighlightConfig {
|
61
|
+
/**
|
62
|
+
* The available highlight options. The default value is:
|
63
|
+
* ```ts
|
64
|
+
* options: [
|
65
|
+
* {
|
66
|
+
* model: 'yellowMarker',
|
67
|
+
* class: 'marker-yellow',
|
68
|
+
* title: 'Yellow marker',
|
69
|
+
* color: 'var(--ck-highlight-marker-yellow)',
|
70
|
+
* type: 'marker'
|
71
|
+
* },
|
72
|
+
* {
|
73
|
+
* model: 'greenMarker',
|
74
|
+
* class: 'marker-green',
|
75
|
+
* title: 'Green marker',
|
76
|
+
* color: 'var(--ck-highlight-marker-green)',
|
77
|
+
* type: 'marker'
|
78
|
+
* },
|
79
|
+
* {
|
80
|
+
* model: 'pinkMarker',
|
81
|
+
* class: 'marker-pink',
|
82
|
+
* title: 'Pink marker',
|
83
|
+
* color: 'var(--ck-highlight-marker-pink)',
|
84
|
+
* type: 'marker'
|
85
|
+
* },
|
86
|
+
* {
|
87
|
+
* model: 'blueMarker',
|
88
|
+
* class: 'marker-blue',
|
89
|
+
* title: 'Blue marker',
|
90
|
+
* color: 'var(--ck-highlight-marker-blue)',
|
91
|
+
* type: 'marker'
|
92
|
+
* },
|
93
|
+
* {
|
94
|
+
* model: 'redPen',
|
95
|
+
* class: 'pen-red',
|
96
|
+
* title: 'Red pen',
|
97
|
+
* color: 'var(--ck-highlight-pen-red)',
|
98
|
+
* type: 'pen'
|
99
|
+
* },
|
100
|
+
* {
|
101
|
+
* model: 'greenPen',
|
102
|
+
* class: 'pen-green',
|
103
|
+
* title: 'Green pen',
|
104
|
+
* color: 'var(--ck-highlight-pen-green)',
|
105
|
+
* type: 'pen'
|
106
|
+
* }
|
107
|
+
* ]
|
108
|
+
* ```
|
109
|
+
*
|
110
|
+
* There are two types of highlighters available:
|
111
|
+
*
|
112
|
+
* * `'marker'` – Rendered as a `<mark>` element, styled with the `background-color`.
|
113
|
+
* * `'pen'` – Rendered as a `<mark>` element, styled with the font `color`.
|
114
|
+
*
|
115
|
+
* **Note**: The highlight feature provides a stylesheet with the CSS classes and corresponding colors defined
|
116
|
+
* as CSS variables.
|
117
|
+
*
|
118
|
+
* ```css
|
119
|
+
* :root {
|
120
|
+
* --ck-highlight-marker-yellow: #fdfd77;
|
121
|
+
* --ck-highlight-marker-green: #63f963;
|
122
|
+
* --ck-highlight-marker-pink: #fc7999;
|
123
|
+
* --ck-highlight-marker-blue: #72cdfd;
|
124
|
+
* --ck-highlight-pen-red: #e91313;
|
125
|
+
* --ck-highlight-pen-green: #118800;
|
126
|
+
* }
|
127
|
+
*
|
128
|
+
* .marker-yellow { ... }
|
129
|
+
* .marker-green { ... }
|
130
|
+
* .marker-pink { ... }
|
131
|
+
* .marker-blue { ... }
|
132
|
+
* .pen-red { ... }
|
133
|
+
* .pen-green { ... }
|
134
|
+
* ```
|
135
|
+
*
|
136
|
+
* It is possible to define the `color` property directly as `rgba(R, G, B, A)`,
|
137
|
+
* `#RRGGBB[AA]` or `hsla(H, S, L, A)`. In such situation, the color will **only** apply to the UI of
|
138
|
+
* the editor and the `<mark>` elements in the content must be styled by custom classes provided by
|
139
|
+
* a dedicated stylesheet.
|
140
|
+
*
|
141
|
+
* **Note**: It is recommended for the `color` property to correspond to the class in the content
|
142
|
+
* stylesheet because it represents the highlighter in the user interface of the editor.
|
143
|
+
*
|
144
|
+
* ```ts
|
145
|
+
* ClassicEditor
|
146
|
+
* .create( editorElement, {
|
147
|
+
* highlight: {
|
148
|
+
* options: [
|
149
|
+
* {
|
150
|
+
* model: 'pinkMarker',
|
151
|
+
* class: 'marker-pink',
|
152
|
+
* title: 'Pink Marker',
|
153
|
+
* color: 'var(--ck-highlight-marker-pink)',
|
154
|
+
* type: 'marker'
|
155
|
+
* },
|
156
|
+
* {
|
157
|
+
* model: 'redPen',
|
158
|
+
* class: 'pen-red',
|
159
|
+
* title: 'Red Pen',
|
160
|
+
* color: 'var(--ck-highlight-pen-red)',
|
161
|
+
* type: 'pen'
|
162
|
+
* },
|
163
|
+
* ]
|
164
|
+
* }
|
165
|
+
* } )
|
166
|
+
* .then( ... )
|
167
|
+
* .catch( ... );
|
168
|
+
* ```
|
169
|
+
*/
|
170
|
+
options: Array<HighlightOption>;
|
171
|
+
}
|
package/src/highlightconfig.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
export {};
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
export {};
|
@@ -1,28 +1,28 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module highlight/highlightediting
|
7
|
-
*/
|
8
|
-
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
9
|
-
/**
|
10
|
-
* The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
|
11
|
-
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
|
12
|
-
* as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
|
13
|
-
* on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
|
14
|
-
*/
|
15
|
-
export default class HighlightEditing extends Plugin {
|
16
|
-
/**
|
17
|
-
* @inheritDoc
|
18
|
-
*/
|
19
|
-
static get pluginName(): "HighlightEditing";
|
20
|
-
/**
|
21
|
-
* @inheritDoc
|
22
|
-
*/
|
23
|
-
constructor(editor: Editor);
|
24
|
-
/**
|
25
|
-
* @inheritDoc
|
26
|
-
*/
|
27
|
-
init(): void;
|
28
|
-
}
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module highlight/highlightediting
|
7
|
+
*/
|
8
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
9
|
+
/**
|
10
|
+
* The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
|
11
|
+
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
|
12
|
+
* as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
|
13
|
+
* on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
|
14
|
+
*/
|
15
|
+
export default class HighlightEditing extends Plugin {
|
16
|
+
/**
|
17
|
+
* @inheritDoc
|
18
|
+
*/
|
19
|
+
static get pluginName(): "HighlightEditing";
|
20
|
+
/**
|
21
|
+
* @inheritDoc
|
22
|
+
*/
|
23
|
+
constructor(editor: Editor);
|
24
|
+
/**
|
25
|
+
* @inheritDoc
|
26
|
+
*/
|
27
|
+
init(): void;
|
28
|
+
}
|
package/src/highlightediting.js
CHANGED
@@ -1,109 +1,109 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module highlight/highlightediting
|
7
|
-
*/
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
9
|
-
import HighlightCommand from './highlightcommand';
|
10
|
-
/**
|
11
|
-
* The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
|
12
|
-
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
|
13
|
-
* as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
|
14
|
-
* on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
|
15
|
-
*/
|
16
|
-
export default class HighlightEditing extends Plugin {
|
17
|
-
/**
|
18
|
-
* @inheritDoc
|
19
|
-
*/
|
20
|
-
static get pluginName() {
|
21
|
-
return 'HighlightEditing';
|
22
|
-
}
|
23
|
-
/**
|
24
|
-
* @inheritDoc
|
25
|
-
*/
|
26
|
-
constructor(editor) {
|
27
|
-
super(editor);
|
28
|
-
editor.config.define('highlight', {
|
29
|
-
options: [
|
30
|
-
{
|
31
|
-
model: 'yellowMarker',
|
32
|
-
class: 'marker-yellow',
|
33
|
-
title: 'Yellow marker',
|
34
|
-
color: 'var(--ck-highlight-marker-yellow)',
|
35
|
-
type: 'marker'
|
36
|
-
},
|
37
|
-
{
|
38
|
-
model: 'greenMarker',
|
39
|
-
class: 'marker-green',
|
40
|
-
title: 'Green marker',
|
41
|
-
color: 'var(--ck-highlight-marker-green)',
|
42
|
-
type: 'marker'
|
43
|
-
},
|
44
|
-
{
|
45
|
-
model: 'pinkMarker',
|
46
|
-
class: 'marker-pink',
|
47
|
-
title: 'Pink marker',
|
48
|
-
color: 'var(--ck-highlight-marker-pink)',
|
49
|
-
type: 'marker'
|
50
|
-
},
|
51
|
-
{
|
52
|
-
model: 'blueMarker',
|
53
|
-
class: 'marker-blue',
|
54
|
-
title: 'Blue marker',
|
55
|
-
color: 'var(--ck-highlight-marker-blue)',
|
56
|
-
type: 'marker'
|
57
|
-
},
|
58
|
-
{
|
59
|
-
model: 'redPen',
|
60
|
-
class: 'pen-red',
|
61
|
-
title: 'Red pen',
|
62
|
-
color: 'var(--ck-highlight-pen-red)',
|
63
|
-
type: 'pen'
|
64
|
-
},
|
65
|
-
{
|
66
|
-
model: 'greenPen',
|
67
|
-
class: 'pen-green',
|
68
|
-
title: 'Green pen',
|
69
|
-
color: 'var(--ck-highlight-pen-green)',
|
70
|
-
type: 'pen'
|
71
|
-
}
|
72
|
-
]
|
73
|
-
});
|
74
|
-
}
|
75
|
-
/**
|
76
|
-
* @inheritDoc
|
77
|
-
*/
|
78
|
-
init() {
|
79
|
-
const editor = this.editor;
|
80
|
-
// Allow highlight attribute on text nodes.
|
81
|
-
editor.model.schema.extend('$text', { allowAttributes: 'highlight' });
|
82
|
-
const options = editor.config.get('highlight.options');
|
83
|
-
// Set-up the two-way conversion.
|
84
|
-
editor.conversion.attributeToElement(_buildDefinition(options));
|
85
|
-
editor.commands.add('highlight', new HighlightCommand(editor));
|
86
|
-
}
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
* Converts the options array to a converter definition.
|
90
|
-
*
|
91
|
-
* @param options An array with configured options.
|
92
|
-
*/
|
93
|
-
function _buildDefinition(options) {
|
94
|
-
const definition = {
|
95
|
-
model: {
|
96
|
-
key: 'highlight',
|
97
|
-
values: []
|
98
|
-
},
|
99
|
-
view: {}
|
100
|
-
};
|
101
|
-
for (const option of options) {
|
102
|
-
definition.model.values.push(option.model);
|
103
|
-
definition.view[option.model] = {
|
104
|
-
name: 'mark',
|
105
|
-
classes: option.class
|
106
|
-
};
|
107
|
-
}
|
108
|
-
return definition;
|
109
|
-
}
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module highlight/highlightediting
|
7
|
+
*/
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
9
|
+
import HighlightCommand from './highlightcommand';
|
10
|
+
/**
|
11
|
+
* The highlight editing feature. It introduces the {@link module:highlight/highlightcommand~HighlightCommand command} and the `highlight`
|
12
|
+
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
|
13
|
+
* as a `<mark>` element with a `class` attribute (`<mark class="marker-green">...</mark>`) depending
|
14
|
+
* on the {@link module:highlight/highlightconfig~HighlightConfig configuration}.
|
15
|
+
*/
|
16
|
+
export default class HighlightEditing extends Plugin {
|
17
|
+
/**
|
18
|
+
* @inheritDoc
|
19
|
+
*/
|
20
|
+
static get pluginName() {
|
21
|
+
return 'HighlightEditing';
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* @inheritDoc
|
25
|
+
*/
|
26
|
+
constructor(editor) {
|
27
|
+
super(editor);
|
28
|
+
editor.config.define('highlight', {
|
29
|
+
options: [
|
30
|
+
{
|
31
|
+
model: 'yellowMarker',
|
32
|
+
class: 'marker-yellow',
|
33
|
+
title: 'Yellow marker',
|
34
|
+
color: 'var(--ck-highlight-marker-yellow)',
|
35
|
+
type: 'marker'
|
36
|
+
},
|
37
|
+
{
|
38
|
+
model: 'greenMarker',
|
39
|
+
class: 'marker-green',
|
40
|
+
title: 'Green marker',
|
41
|
+
color: 'var(--ck-highlight-marker-green)',
|
42
|
+
type: 'marker'
|
43
|
+
},
|
44
|
+
{
|
45
|
+
model: 'pinkMarker',
|
46
|
+
class: 'marker-pink',
|
47
|
+
title: 'Pink marker',
|
48
|
+
color: 'var(--ck-highlight-marker-pink)',
|
49
|
+
type: 'marker'
|
50
|
+
},
|
51
|
+
{
|
52
|
+
model: 'blueMarker',
|
53
|
+
class: 'marker-blue',
|
54
|
+
title: 'Blue marker',
|
55
|
+
color: 'var(--ck-highlight-marker-blue)',
|
56
|
+
type: 'marker'
|
57
|
+
},
|
58
|
+
{
|
59
|
+
model: 'redPen',
|
60
|
+
class: 'pen-red',
|
61
|
+
title: 'Red pen',
|
62
|
+
color: 'var(--ck-highlight-pen-red)',
|
63
|
+
type: 'pen'
|
64
|
+
},
|
65
|
+
{
|
66
|
+
model: 'greenPen',
|
67
|
+
class: 'pen-green',
|
68
|
+
title: 'Green pen',
|
69
|
+
color: 'var(--ck-highlight-pen-green)',
|
70
|
+
type: 'pen'
|
71
|
+
}
|
72
|
+
]
|
73
|
+
});
|
74
|
+
}
|
75
|
+
/**
|
76
|
+
* @inheritDoc
|
77
|
+
*/
|
78
|
+
init() {
|
79
|
+
const editor = this.editor;
|
80
|
+
// Allow highlight attribute on text nodes.
|
81
|
+
editor.model.schema.extend('$text', { allowAttributes: 'highlight' });
|
82
|
+
const options = editor.config.get('highlight.options');
|
83
|
+
// Set-up the two-way conversion.
|
84
|
+
editor.conversion.attributeToElement(_buildDefinition(options));
|
85
|
+
editor.commands.add('highlight', new HighlightCommand(editor));
|
86
|
+
}
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* Converts the options array to a converter definition.
|
90
|
+
*
|
91
|
+
* @param options An array with configured options.
|
92
|
+
*/
|
93
|
+
function _buildDefinition(options) {
|
94
|
+
const definition = {
|
95
|
+
model: {
|
96
|
+
key: 'highlight',
|
97
|
+
values: []
|
98
|
+
},
|
99
|
+
view: {}
|
100
|
+
};
|
101
|
+
for (const option of options) {
|
102
|
+
definition.model.values.push(option.model);
|
103
|
+
definition.view[option.model] = {
|
104
|
+
name: 'mark',
|
105
|
+
classes: option.class
|
106
|
+
};
|
107
|
+
}
|
108
|
+
return definition;
|
109
|
+
}
|