@ckeditor/ckeditor5-html-support 36.0.1 → 37.0.0-alpha.1
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/README.md +2 -2
- package/build/html-support.js +1 -1
- package/ckeditor5-metadata.json +2 -2
- package/package.json +42 -36
- package/src/augmentation.d.ts +33 -0
- package/src/augmentation.js +5 -0
- package/src/conversionutils.d.ts +42 -0
- package/src/conversionutils.js +57 -77
- package/src/converters.d.ts +56 -0
- package/src/converters.js +104 -156
- package/src/datafilter.d.ts +250 -0
- package/src/datafilter.js +566 -782
- package/src/dataschema.d.ts +169 -0
- package/src/dataschema.js +143 -229
- package/src/fullpage.d.ts +21 -0
- package/src/fullpage.js +65 -86
- package/src/generalhtmlsupport.d.ts +88 -0
- package/src/generalhtmlsupport.js +244 -327
- package/src/generalhtmlsupportconfig.d.ts +67 -0
- package/src/generalhtmlsupportconfig.js +5 -0
- package/src/htmlcomment.d.ts +72 -0
- package/src/htmlcomment.js +175 -239
- package/src/htmlpagedataprocessor.d.ts +22 -0
- package/src/htmlpagedataprocessor.js +53 -76
- package/src/index.d.ts +25 -0
- package/src/index.js +1 -2
- package/src/integrations/codeblock.d.ts +22 -0
- package/src/integrations/codeblock.js +87 -115
- package/src/integrations/customelement.d.ts +25 -0
- package/src/integrations/customelement.js +127 -160
- package/src/integrations/documentlist.d.ts +26 -0
- package/src/integrations/documentlist.js +154 -191
- package/src/integrations/dualcontent.d.ts +44 -0
- package/src/integrations/dualcontent.js +92 -128
- package/src/integrations/heading.d.ts +25 -0
- package/src/integrations/heading.js +41 -54
- package/src/integrations/image.d.ts +25 -0
- package/src/integrations/image.js +154 -212
- package/src/integrations/integrationutils.d.ts +15 -0
- package/src/integrations/integrationutils.js +21 -0
- package/src/integrations/mediaembed.d.ts +25 -0
- package/src/integrations/mediaembed.js +101 -147
- package/src/integrations/script.d.ts +25 -0
- package/src/integrations/script.js +45 -67
- package/src/integrations/style.d.ts +25 -0
- package/src/integrations/style.js +45 -67
- package/src/integrations/table.d.ts +22 -0
- package/src/integrations/table.js +113 -160
- package/src/schemadefinitions.d.ts +13 -0
- package/src/schemadefinitions.js +846 -835
|
@@ -0,0 +1,67 @@
|
|
|
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 html-support/generalhtmlsupportconfig
|
|
7
|
+
*/
|
|
8
|
+
import type { MatcherPattern } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* The configuration of the General HTML Support feature.
|
|
11
|
+
* The option is used by the {@link module:html-support/generalhtmlsupport~GeneralHtmlSupport} feature.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* ClassicEditor
|
|
15
|
+
* .create( {
|
|
16
|
+
* htmlSupport: ... // General HTML Support feature config.
|
|
17
|
+
* } )
|
|
18
|
+
* .then( ... )
|
|
19
|
+
* .catch( ... );
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
23
|
+
*/
|
|
24
|
+
export interface GeneralHtmlSupportConfig {
|
|
25
|
+
/**
|
|
26
|
+
* The configuration of allowed content rules used by General HTML Support.
|
|
27
|
+
*
|
|
28
|
+
* Setting this configuration option will enable HTML features that are not explicitly supported by any other
|
|
29
|
+
* dedicated CKEditor 5 features.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const htmlSupportConfig.allow = [
|
|
33
|
+
* {
|
|
34
|
+
* name: 'div', // Enable 'div' element support,
|
|
35
|
+
* classes: [ 'special-container' ], // allow 'special-container' class,
|
|
36
|
+
* styles: 'background', // allow 'background' style,
|
|
37
|
+
* attributes: true // allow any attribute (can be empty).
|
|
38
|
+
* },
|
|
39
|
+
* {
|
|
40
|
+
* name: 'p', // Extend existing Paragraph feature,
|
|
41
|
+
* classes: 'highlighted' // with 'highlighted' class,
|
|
42
|
+
* attributes: [
|
|
43
|
+
* { key: 'data-i18n-context, value: true } // and i18n attribute.
|
|
44
|
+
* ]
|
|
45
|
+
* }
|
|
46
|
+
* ];
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
allow?: Array<MatcherPattern>;
|
|
50
|
+
/**
|
|
51
|
+
* The configuration of disallowed content rules used by General HTML Support.
|
|
52
|
+
*
|
|
53
|
+
* Setting this configuration option will disable listed HTML features.
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* const htmlSupportConfig.disallow = [
|
|
57
|
+
* {
|
|
58
|
+
* name: /[\s\S]+/ // For every HTML feature,
|
|
59
|
+
* attributes: {
|
|
60
|
+
* key: /^on.*$/ // disable 'on*' attributes, like 'onClick', 'onError' etc.
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* ];
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
disallow?: Array<MatcherPattern>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 html-support/htmlcomment
|
|
7
|
+
*/
|
|
8
|
+
import type { Position, Range } from 'ckeditor5/src/engine';
|
|
9
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
10
|
+
/**
|
|
11
|
+
* The HTML comment feature. It preserves the HTML comments (`<!-- -->`) in the editor data.
|
|
12
|
+
*
|
|
13
|
+
* For a detailed overview, check the {@glink features/general-html-support#html-comments HTML comment feature documentation}.
|
|
14
|
+
*/
|
|
15
|
+
export default class HtmlComment extends Plugin {
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
static get pluginName(): 'HtmlComment';
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
init(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an HTML comment on the specified position and returns its ID.
|
|
26
|
+
*
|
|
27
|
+
* *Note*: If two comments are created at the same position, the second comment will be inserted before the first one.
|
|
28
|
+
*
|
|
29
|
+
* @returns Comment ID. This ID can be later used to e.g. remove the comment from the content.
|
|
30
|
+
*/
|
|
31
|
+
createHtmlComment(position: Position, content: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Removes an HTML comment with the given comment ID.
|
|
34
|
+
*
|
|
35
|
+
* It does nothing and returns `false` if the comment with the given ID does not exist.
|
|
36
|
+
* Otherwise it removes the comment and returns `true`.
|
|
37
|
+
*
|
|
38
|
+
* Note that a comment can be removed also by removing the content around the comment.
|
|
39
|
+
*
|
|
40
|
+
* @param commentID The ID of the comment to be removed.
|
|
41
|
+
* @returns `true` when the comment with the given ID was removed, `false` otherwise.
|
|
42
|
+
*/
|
|
43
|
+
removeHtmlComment(commentID: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Gets the HTML comment data for the comment with a given ID.
|
|
46
|
+
*
|
|
47
|
+
* Returns `null` if the comment does not exist.
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
getHtmlCommentData(commentID: string): HtmlCommentData | null;
|
|
51
|
+
/**
|
|
52
|
+
* Gets all HTML comments in the given range.
|
|
53
|
+
*
|
|
54
|
+
* By default it includes comments at the range boundaries.
|
|
55
|
+
*
|
|
56
|
+
* @param range
|
|
57
|
+
* @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
|
|
58
|
+
* @returns HTML comment IDs
|
|
59
|
+
*/
|
|
60
|
+
getHtmlCommentsInRange(range: Range, { skipBoundaries }?: {
|
|
61
|
+
skipBoundaries?: boolean | undefined;
|
|
62
|
+
}): Array<string>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* An interface for the HTML comments data.
|
|
66
|
+
*
|
|
67
|
+
* It consists of the {@link module:engine/model/position~Position `position`} and `content`.
|
|
68
|
+
*/
|
|
69
|
+
export interface HtmlCommentData {
|
|
70
|
+
position: Position;
|
|
71
|
+
content: string;
|
|
72
|
+
}
|
package/src/htmlcomment.js
CHANGED
|
@@ -2,251 +2,187 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @module html-support/htmlcomment
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
5
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
6
|
import { uid } from 'ckeditor5/src/utils';
|
|
12
|
-
|
|
13
7
|
/**
|
|
14
8
|
* The HTML comment feature. It preserves the HTML comments (`<!-- -->`) in the editor data.
|
|
15
9
|
*
|
|
16
10
|
* For a detailed overview, check the {@glink features/general-html-support#html-comments HTML comment feature documentation}.
|
|
17
|
-
*
|
|
18
|
-
* @extends module:core/plugin~Plugin
|
|
19
11
|
*/
|
|
20
12
|
export default class HtmlComment extends Plugin {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
* @param {String} commentID
|
|
197
|
-
* @returns {module:html-support/htmlcomment~HtmlCommentData}
|
|
198
|
-
*/
|
|
199
|
-
getHtmlCommentData( commentID ) {
|
|
200
|
-
const editor = this.editor;
|
|
201
|
-
const marker = editor.model.markers.get( commentID );
|
|
202
|
-
const root = editor.model.document.getRoot();
|
|
203
|
-
|
|
204
|
-
if ( !marker ) {
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
content: root.getAttribute( commentID ),
|
|
210
|
-
position: marker.getStart()
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Gets all HTML comments in the given range.
|
|
216
|
-
*
|
|
217
|
-
* By default it includes comments at the range boundaries.
|
|
218
|
-
*
|
|
219
|
-
* @param {module:engine/model/range~Range} range
|
|
220
|
-
* @param {Object} [options]
|
|
221
|
-
* @param {Boolean} [options.skipBoundaries=false] When set to `true` the range boundaries will be skipped.
|
|
222
|
-
* @returns {Array.<String>} HTML comment IDs
|
|
223
|
-
*/
|
|
224
|
-
getHtmlCommentsInRange( range, { skipBoundaries = false } = {} ) {
|
|
225
|
-
const includeBoundaries = !skipBoundaries;
|
|
226
|
-
|
|
227
|
-
// Unfortunately, MarkerCollection#getMarkersAtPosition() filters out collapsed markers.
|
|
228
|
-
return Array.from( this.editor.model.markers.getMarkersGroup( '$comment' ) )
|
|
229
|
-
.filter( marker => isCommentMarkerInRange( marker, range ) )
|
|
230
|
-
.map( marker => marker.name );
|
|
231
|
-
|
|
232
|
-
function isCommentMarkerInRange( commentMarker, range ) {
|
|
233
|
-
const position = commentMarker.getRange().start;
|
|
234
|
-
|
|
235
|
-
return (
|
|
236
|
-
( position.isAfter( range.start ) || ( includeBoundaries && position.isEqual( range.start ) ) ) &&
|
|
237
|
-
( position.isBefore( range.end ) || ( includeBoundaries && position.isEqual( range.end ) ) )
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
static get pluginName() {
|
|
17
|
+
return 'HtmlComment';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
init() {
|
|
23
|
+
const editor = this.editor;
|
|
24
|
+
editor.data.processor.skipComments = false;
|
|
25
|
+
// Allow storing comment's content as the $root attribute with the name `$comment:<unique id>`.
|
|
26
|
+
editor.model.schema.addAttributeCheck((context, attributeName) => {
|
|
27
|
+
if (context.endsWith('$root') && attributeName.startsWith('$comment')) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
// Convert the `$comment` view element to `$comment:<unique id>` marker and store its content (the comment itself) as a $root
|
|
32
|
+
// attribute. The comment content is needed in the `dataDowncast` pipeline to re-create the comment node.
|
|
33
|
+
editor.conversion.for('upcast').elementToMarker({
|
|
34
|
+
view: '$comment',
|
|
35
|
+
model: (viewElement, { writer }) => {
|
|
36
|
+
const root = this.editor.model.document.getRoot();
|
|
37
|
+
const commentContent = viewElement.getCustomProperty('$rawContent');
|
|
38
|
+
const markerName = `$comment:${uid()}`;
|
|
39
|
+
writer.setAttribute(markerName, commentContent, root);
|
|
40
|
+
return markerName;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
// Convert the `$comment` marker to `$comment` UI element with `$rawContent` custom property containing the comment content.
|
|
44
|
+
editor.conversion.for('dataDowncast').markerToElement({
|
|
45
|
+
model: '$comment',
|
|
46
|
+
view: (modelElement, { writer }) => {
|
|
47
|
+
const root = this.editor.model.document.getRoot();
|
|
48
|
+
const markerName = modelElement.markerName;
|
|
49
|
+
const commentContent = root.getAttribute(markerName);
|
|
50
|
+
const comment = writer.createUIElement('$comment');
|
|
51
|
+
writer.setCustomProperty('$rawContent', commentContent, comment);
|
|
52
|
+
return comment;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
// Remove comments' markers and their corresponding $root attributes, which are no longer present.
|
|
56
|
+
editor.model.document.registerPostFixer(writer => {
|
|
57
|
+
const root = editor.model.document.getRoot();
|
|
58
|
+
const changedMarkers = editor.model.document.differ.getChangedMarkers();
|
|
59
|
+
const changedCommentMarkers = changedMarkers.filter(marker => {
|
|
60
|
+
return marker.name.startsWith('$comment');
|
|
61
|
+
});
|
|
62
|
+
const removedCommentMarkers = changedCommentMarkers.filter(marker => {
|
|
63
|
+
const newRange = marker.data.newRange;
|
|
64
|
+
return newRange && newRange.root.rootName === '$graveyard';
|
|
65
|
+
});
|
|
66
|
+
if (removedCommentMarkers.length === 0) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
for (const marker of removedCommentMarkers) {
|
|
70
|
+
writer.removeMarker(marker.name);
|
|
71
|
+
writer.removeAttribute(marker.name, root);
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
// Delete all comment markers from the document before setting new data.
|
|
76
|
+
editor.data.on('set', () => {
|
|
77
|
+
for (const commentMarker of editor.model.markers.getMarkersGroup('$comment')) {
|
|
78
|
+
this.removeHtmlComment(commentMarker.name);
|
|
79
|
+
}
|
|
80
|
+
}, { priority: 'high' });
|
|
81
|
+
// Delete all comment markers that are within a removed range.
|
|
82
|
+
// Delete all comment markers at the limit element boundaries if the whole content of the limit element is removed.
|
|
83
|
+
editor.model.on('deleteContent', (evt, [selection]) => {
|
|
84
|
+
for (const range of selection.getRanges()) {
|
|
85
|
+
const limitElement = editor.model.schema.getLimitElement(range);
|
|
86
|
+
const firstPosition = editor.model.createPositionAt(limitElement, 0);
|
|
87
|
+
const lastPosition = editor.model.createPositionAt(limitElement, 'end');
|
|
88
|
+
let affectedCommentIDs;
|
|
89
|
+
if (firstPosition.isTouching(range.start) && lastPosition.isTouching(range.end)) {
|
|
90
|
+
affectedCommentIDs = this.getHtmlCommentsInRange(editor.model.createRange(firstPosition, lastPosition));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
affectedCommentIDs = this.getHtmlCommentsInRange(range, { skipBoundaries: true });
|
|
94
|
+
}
|
|
95
|
+
for (const commentMarkerID of affectedCommentIDs) {
|
|
96
|
+
this.removeHtmlComment(commentMarkerID);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}, { priority: 'high' });
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Creates an HTML comment on the specified position and returns its ID.
|
|
103
|
+
*
|
|
104
|
+
* *Note*: If two comments are created at the same position, the second comment will be inserted before the first one.
|
|
105
|
+
*
|
|
106
|
+
* @returns Comment ID. This ID can be later used to e.g. remove the comment from the content.
|
|
107
|
+
*/
|
|
108
|
+
createHtmlComment(position, content) {
|
|
109
|
+
const id = uid();
|
|
110
|
+
const editor = this.editor;
|
|
111
|
+
const model = editor.model;
|
|
112
|
+
const root = model.document.getRoot();
|
|
113
|
+
const markerName = `$comment:${id}`;
|
|
114
|
+
return model.change(writer => {
|
|
115
|
+
const range = writer.createRange(position);
|
|
116
|
+
writer.addMarker(markerName, {
|
|
117
|
+
usingOperation: true,
|
|
118
|
+
affectsData: true,
|
|
119
|
+
range
|
|
120
|
+
});
|
|
121
|
+
writer.setAttribute(markerName, content, root);
|
|
122
|
+
return markerName;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Removes an HTML comment with the given comment ID.
|
|
127
|
+
*
|
|
128
|
+
* It does nothing and returns `false` if the comment with the given ID does not exist.
|
|
129
|
+
* Otherwise it removes the comment and returns `true`.
|
|
130
|
+
*
|
|
131
|
+
* Note that a comment can be removed also by removing the content around the comment.
|
|
132
|
+
*
|
|
133
|
+
* @param commentID The ID of the comment to be removed.
|
|
134
|
+
* @returns `true` when the comment with the given ID was removed, `false` otherwise.
|
|
135
|
+
*/
|
|
136
|
+
removeHtmlComment(commentID) {
|
|
137
|
+
const editor = this.editor;
|
|
138
|
+
const root = editor.model.document.getRoot();
|
|
139
|
+
const marker = editor.model.markers.get(commentID);
|
|
140
|
+
if (!marker) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
editor.model.change(writer => {
|
|
144
|
+
writer.removeMarker(marker);
|
|
145
|
+
writer.removeAttribute(commentID, root);
|
|
146
|
+
});
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Gets the HTML comment data for the comment with a given ID.
|
|
151
|
+
*
|
|
152
|
+
* Returns `null` if the comment does not exist.
|
|
153
|
+
*
|
|
154
|
+
*/
|
|
155
|
+
getHtmlCommentData(commentID) {
|
|
156
|
+
const editor = this.editor;
|
|
157
|
+
const marker = editor.model.markers.get(commentID);
|
|
158
|
+
const root = editor.model.document.getRoot();
|
|
159
|
+
if (!marker) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
content: root.getAttribute(commentID),
|
|
164
|
+
position: marker.getStart()
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Gets all HTML comments in the given range.
|
|
169
|
+
*
|
|
170
|
+
* By default it includes comments at the range boundaries.
|
|
171
|
+
*
|
|
172
|
+
* @param range
|
|
173
|
+
* @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
|
|
174
|
+
* @returns HTML comment IDs
|
|
175
|
+
*/
|
|
176
|
+
getHtmlCommentsInRange(range, { skipBoundaries = false } = {}) {
|
|
177
|
+
const includeBoundaries = !skipBoundaries;
|
|
178
|
+
// Unfortunately, MarkerCollection#getMarkersAtPosition() filters out collapsed markers.
|
|
179
|
+
return Array.from(this.editor.model.markers.getMarkersGroup('$comment'))
|
|
180
|
+
.filter(marker => isCommentMarkerInRange(marker, range))
|
|
181
|
+
.map(marker => marker.name);
|
|
182
|
+
function isCommentMarkerInRange(commentMarker, range) {
|
|
183
|
+
const position = commentMarker.getRange().start;
|
|
184
|
+
return ((position.isAfter(range.start) || (includeBoundaries && position.isEqual(range.start))) &&
|
|
185
|
+
(position.isBefore(range.end) || (includeBoundaries && position.isEqual(range.end))));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
241
188
|
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* An interface for the HTML comments data.
|
|
245
|
-
*
|
|
246
|
-
* It consists of the {@link module:engine/model/position~Position `position`} and `content`.
|
|
247
|
-
*
|
|
248
|
-
* @typedef {Object} module:html-support/htmlcomment~HtmlCommentData
|
|
249
|
-
*
|
|
250
|
-
* @property {module:engine/model/position~Position} position
|
|
251
|
-
* @property {String} content
|
|
252
|
-
*/
|
|
@@ -0,0 +1,22 @@
|
|
|
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 html-support/htmlpagedataprocessor
|
|
7
|
+
*/
|
|
8
|
+
import { HtmlDataProcessor, type ViewDocumentFragment } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* The full page HTML data processor class.
|
|
11
|
+
* This data processor implementation uses HTML as input and output data.
|
|
12
|
+
*/
|
|
13
|
+
export default class HtmlPageDataProcessor extends HtmlDataProcessor {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
toView(data: string): ViewDocumentFragment;
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
toData(viewFragment: ViewDocumentFragment): string;
|
|
22
|
+
}
|