@ckeditor/ckeditor5-html-support 39.0.2 → 40.0.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.
Files changed (49) hide show
  1. package/build/html-support.js +1 -1
  2. package/build/html-support.js.map +1 -0
  3. package/package.json +2 -2
  4. package/src/augmentation.d.ts +33 -33
  5. package/src/augmentation.js +5 -5
  6. package/src/converters.d.ts +60 -60
  7. package/src/converters.js +180 -180
  8. package/src/datafilter.d.ts +304 -304
  9. package/src/datafilter.js +720 -720
  10. package/src/dataschema.d.ts +183 -183
  11. package/src/dataschema.js +196 -196
  12. package/src/fullpage.d.ts +21 -21
  13. package/src/fullpage.js +80 -80
  14. package/src/generalhtmlsupport.d.ts +98 -98
  15. package/src/generalhtmlsupport.js +240 -240
  16. package/src/generalhtmlsupportconfig.d.ts +77 -77
  17. package/src/generalhtmlsupportconfig.js +5 -5
  18. package/src/htmlcomment.d.ts +71 -71
  19. package/src/htmlcomment.js +218 -218
  20. package/src/htmlpagedataprocessor.d.ts +22 -22
  21. package/src/htmlpagedataprocessor.js +67 -67
  22. package/src/index.d.ts +25 -25
  23. package/src/index.js +14 -14
  24. package/src/integrations/codeblock.d.ts +23 -23
  25. package/src/integrations/codeblock.js +101 -101
  26. package/src/integrations/customelement.d.ts +27 -27
  27. package/src/integrations/customelement.js +146 -146
  28. package/src/integrations/documentlist.d.ts +27 -27
  29. package/src/integrations/documentlist.js +178 -203
  30. package/src/integrations/dualcontent.d.ts +45 -45
  31. package/src/integrations/dualcontent.js +119 -119
  32. package/src/integrations/heading.d.ts +31 -31
  33. package/src/integrations/heading.js +60 -60
  34. package/src/integrations/image.d.ts +26 -26
  35. package/src/integrations/image.js +189 -189
  36. package/src/integrations/integrationutils.d.ts +15 -15
  37. package/src/integrations/integrationutils.js +21 -21
  38. package/src/integrations/mediaembed.d.ts +26 -26
  39. package/src/integrations/mediaembed.js +119 -119
  40. package/src/integrations/script.d.ts +26 -26
  41. package/src/integrations/script.js +59 -59
  42. package/src/integrations/style.d.ts +26 -26
  43. package/src/integrations/style.js +59 -59
  44. package/src/integrations/table.d.ts +23 -23
  45. package/src/integrations/table.js +163 -163
  46. package/src/schemadefinitions.d.ts +13 -13
  47. package/src/schemadefinitions.js +956 -956
  48. package/src/utils.d.ts +72 -72
  49. package/src/utils.js +139 -139
@@ -1,71 +1,71 @@
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/html/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
- getHtmlCommentData(commentID: string): HtmlCommentData | null;
50
- /**
51
- * Gets all HTML comments in the given range.
52
- *
53
- * By default, it includes comments at the range boundaries.
54
- *
55
- * @param range
56
- * @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
57
- * @returns HTML comment IDs
58
- */
59
- getHtmlCommentsInRange(range: Range, { skipBoundaries }?: {
60
- skipBoundaries?: boolean | undefined;
61
- }): Array<string>;
62
- }
63
- /**
64
- * An interface for the HTML comments data.
65
- *
66
- * It consists of the {@link module:engine/model/position~Position `position`} and `content`.
67
- */
68
- export interface HtmlCommentData {
69
- position: Position;
70
- content: string;
71
- }
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/html/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
+ getHtmlCommentData(commentID: string): HtmlCommentData | null;
50
+ /**
51
+ * Gets all HTML comments in the given range.
52
+ *
53
+ * By default, it includes comments at the range boundaries.
54
+ *
55
+ * @param range
56
+ * @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
57
+ * @returns HTML comment IDs
58
+ */
59
+ getHtmlCommentsInRange(range: Range, { skipBoundaries }?: {
60
+ skipBoundaries?: boolean | undefined;
61
+ }): Array<string>;
62
+ }
63
+ /**
64
+ * An interface for the HTML comments data.
65
+ *
66
+ * It consists of the {@link module:engine/model/position~Position `position`} and `content`.
67
+ */
68
+ export interface HtmlCommentData {
69
+ position: Position;
70
+ content: string;
71
+ }
@@ -1,218 +1,218 @@
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
- import { Plugin } from 'ckeditor5/src/core';
6
- import { uid } from 'ckeditor5/src/utils';
7
- /**
8
- * The HTML comment feature. It preserves the HTML comments (`<!-- -->`) in the editor data.
9
- *
10
- * For a detailed overview, check the {@glink features/html/html-comments HTML comment feature documentation}.
11
- */
12
- export default class HtmlComment extends Plugin {
13
- /**
14
- * @inheritDoc
15
- */
16
- static get pluginName() {
17
- return 'HtmlComment';
18
- }
19
- /**
20
- * @inheritDoc
21
- */
22
- init() {
23
- const editor = this.editor;
24
- const loadedCommentsContent = new Map();
25
- editor.data.processor.skipComments = false;
26
- // Allow storing comment's content as the $root attribute with the name `$comment:<unique id>`.
27
- editor.model.schema.addAttributeCheck((context, attributeName) => {
28
- if (context.endsWith('$root') && attributeName.startsWith('$comment')) {
29
- return true;
30
- }
31
- });
32
- // Convert the `$comment` view element to `$comment:<unique id>` marker and store its content (the comment itself) as a $root
33
- // attribute. The comment content is needed in the `dataDowncast` pipeline to re-create the comment node.
34
- editor.conversion.for('upcast').elementToMarker({
35
- view: '$comment',
36
- model: viewElement => {
37
- const markerUid = uid();
38
- const markerName = `$comment:${markerUid}`;
39
- const commentContent = viewElement.getCustomProperty('$rawContent');
40
- loadedCommentsContent.set(markerName, commentContent);
41
- return markerName;
42
- }
43
- });
44
- // Convert the `$comment` marker to `$comment` UI element with `$rawContent` custom property containing the comment content.
45
- editor.conversion.for('dataDowncast').markerToElement({
46
- model: '$comment',
47
- view: (modelElement, { writer }) => {
48
- let root = undefined;
49
- for (const rootName of this.editor.model.document.getRootNames()) {
50
- root = this.editor.model.document.getRoot(rootName);
51
- if (root.hasAttribute(modelElement.markerName)) {
52
- break;
53
- }
54
- }
55
- const markerName = modelElement.markerName;
56
- const commentContent = root.getAttribute(markerName);
57
- const comment = writer.createUIElement('$comment');
58
- writer.setCustomProperty('$rawContent', commentContent, comment);
59
- return comment;
60
- }
61
- });
62
- // Remove comments' markers and their corresponding $root attributes, which are moved to the graveyard.
63
- editor.model.document.registerPostFixer(writer => {
64
- let changed = false;
65
- const markers = editor.model.document.differ.getChangedMarkers().filter(marker => marker.name.startsWith('$comment:'));
66
- for (const marker of markers) {
67
- const { oldRange, newRange } = marker.data;
68
- if (oldRange && newRange && oldRange.root == newRange.root) {
69
- // The marker was moved in the same root. Don't do anything.
70
- continue;
71
- }
72
- if (oldRange) {
73
- // The comment marker was moved from one root to another (most probably to the graveyard).
74
- // Remove the related attribute from the previous root.
75
- const oldRoot = oldRange.root;
76
- if (oldRoot.hasAttribute(marker.name)) {
77
- writer.removeAttribute(marker.name, oldRoot);
78
- changed = true;
79
- }
80
- }
81
- if (newRange) {
82
- const newRoot = newRange.root;
83
- if (newRoot.rootName == '$graveyard') {
84
- // Comment marker was moved to the graveyard -- remove it entirely.
85
- writer.removeMarker(marker.name);
86
- changed = true;
87
- }
88
- else if (!newRoot.hasAttribute(marker.name)) {
89
- // Comment marker was just added or was moved to another root - updated roots attributes.
90
- //
91
- // Added fallback to `''` for the comment content in case if someone incorrectly added just the marker "by hand"
92
- // and forgot to add the root attribute or add them in different change blocks.
93
- //
94
- // It caused an infinite loop in one of the unit tests.
95
- writer.setAttribute(marker.name, loadedCommentsContent.get(marker.name) || '', newRoot);
96
- changed = true;
97
- }
98
- }
99
- }
100
- return changed;
101
- });
102
- // Delete all comment markers from the document before setting new data.
103
- editor.data.on('set', () => {
104
- for (const commentMarker of editor.model.markers.getMarkersGroup('$comment')) {
105
- this.removeHtmlComment(commentMarker.name);
106
- }
107
- }, { priority: 'high' });
108
- // Delete all comment markers that are within a removed range.
109
- // Delete all comment markers at the limit element boundaries if the whole content of the limit element is removed.
110
- editor.model.on('deleteContent', (evt, [selection]) => {
111
- for (const range of selection.getRanges()) {
112
- const limitElement = editor.model.schema.getLimitElement(range);
113
- const firstPosition = editor.model.createPositionAt(limitElement, 0);
114
- const lastPosition = editor.model.createPositionAt(limitElement, 'end');
115
- let affectedCommentIDs;
116
- if (firstPosition.isTouching(range.start) && lastPosition.isTouching(range.end)) {
117
- affectedCommentIDs = this.getHtmlCommentsInRange(editor.model.createRange(firstPosition, lastPosition));
118
- }
119
- else {
120
- affectedCommentIDs = this.getHtmlCommentsInRange(range, { skipBoundaries: true });
121
- }
122
- for (const commentMarkerID of affectedCommentIDs) {
123
- this.removeHtmlComment(commentMarkerID);
124
- }
125
- }
126
- }, { priority: 'high' });
127
- }
128
- /**
129
- * Creates an HTML comment on the specified position and returns its ID.
130
- *
131
- * *Note*: If two comments are created at the same position, the second comment will be inserted before the first one.
132
- *
133
- * @returns Comment ID. This ID can be later used to e.g. remove the comment from the content.
134
- */
135
- createHtmlComment(position, content) {
136
- const id = uid();
137
- const editor = this.editor;
138
- const model = editor.model;
139
- const root = model.document.getRoot(position.root.rootName);
140
- const markerName = `$comment:${id}`;
141
- return model.change(writer => {
142
- const range = writer.createRange(position);
143
- writer.addMarker(markerName, {
144
- usingOperation: true,
145
- affectsData: true,
146
- range
147
- });
148
- writer.setAttribute(markerName, content, root);
149
- return markerName;
150
- });
151
- }
152
- /**
153
- * Removes an HTML comment with the given comment ID.
154
- *
155
- * It does nothing and returns `false` if the comment with the given ID does not exist.
156
- * Otherwise it removes the comment and returns `true`.
157
- *
158
- * Note that a comment can be removed also by removing the content around the comment.
159
- *
160
- * @param commentID The ID of the comment to be removed.
161
- * @returns `true` when the comment with the given ID was removed, `false` otherwise.
162
- */
163
- removeHtmlComment(commentID) {
164
- const editor = this.editor;
165
- const marker = editor.model.markers.get(commentID);
166
- if (!marker) {
167
- return false;
168
- }
169
- editor.model.change(writer => {
170
- writer.removeMarker(marker);
171
- });
172
- return true;
173
- }
174
- /**
175
- * Gets the HTML comment data for the comment with a given ID.
176
- *
177
- * Returns `null` if the comment does not exist.
178
- */
179
- getHtmlCommentData(commentID) {
180
- const editor = this.editor;
181
- const marker = editor.model.markers.get(commentID);
182
- if (!marker) {
183
- return null;
184
- }
185
- let content = '';
186
- for (const root of this.editor.model.document.getRoots()) {
187
- if (root.hasAttribute(commentID)) {
188
- content = root.getAttribute(commentID);
189
- break;
190
- }
191
- }
192
- return {
193
- content,
194
- position: marker.getStart()
195
- };
196
- }
197
- /**
198
- * Gets all HTML comments in the given range.
199
- *
200
- * By default, it includes comments at the range boundaries.
201
- *
202
- * @param range
203
- * @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
204
- * @returns HTML comment IDs
205
- */
206
- getHtmlCommentsInRange(range, { skipBoundaries = false } = {}) {
207
- const includeBoundaries = !skipBoundaries;
208
- // Unfortunately, MarkerCollection#getMarkersAtPosition() filters out collapsed markers.
209
- return Array.from(this.editor.model.markers.getMarkersGroup('$comment'))
210
- .filter(marker => isCommentMarkerInRange(marker, range))
211
- .map(marker => marker.name);
212
- function isCommentMarkerInRange(commentMarker, range) {
213
- const position = commentMarker.getRange().start;
214
- return ((position.isAfter(range.start) || (includeBoundaries && position.isEqual(range.start))) &&
215
- (position.isBefore(range.end) || (includeBoundaries && position.isEqual(range.end))));
216
- }
217
- }
218
- }
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
+ import { Plugin } from 'ckeditor5/src/core';
6
+ import { uid } from 'ckeditor5/src/utils';
7
+ /**
8
+ * The HTML comment feature. It preserves the HTML comments (`<!-- -->`) in the editor data.
9
+ *
10
+ * For a detailed overview, check the {@glink features/html/html-comments HTML comment feature documentation}.
11
+ */
12
+ export default class HtmlComment extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName() {
17
+ return 'HtmlComment';
18
+ }
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ init() {
23
+ const editor = this.editor;
24
+ const loadedCommentsContent = new Map();
25
+ editor.data.processor.skipComments = false;
26
+ // Allow storing comment's content as the $root attribute with the name `$comment:<unique id>`.
27
+ editor.model.schema.addAttributeCheck((context, attributeName) => {
28
+ if (context.endsWith('$root') && attributeName.startsWith('$comment')) {
29
+ return true;
30
+ }
31
+ });
32
+ // Convert the `$comment` view element to `$comment:<unique id>` marker and store its content (the comment itself) as a $root
33
+ // attribute. The comment content is needed in the `dataDowncast` pipeline to re-create the comment node.
34
+ editor.conversion.for('upcast').elementToMarker({
35
+ view: '$comment',
36
+ model: viewElement => {
37
+ const markerUid = uid();
38
+ const markerName = `$comment:${markerUid}`;
39
+ const commentContent = viewElement.getCustomProperty('$rawContent');
40
+ loadedCommentsContent.set(markerName, commentContent);
41
+ return markerName;
42
+ }
43
+ });
44
+ // Convert the `$comment` marker to `$comment` UI element with `$rawContent` custom property containing the comment content.
45
+ editor.conversion.for('dataDowncast').markerToElement({
46
+ model: '$comment',
47
+ view: (modelElement, { writer }) => {
48
+ let root = undefined;
49
+ for (const rootName of this.editor.model.document.getRootNames()) {
50
+ root = this.editor.model.document.getRoot(rootName);
51
+ if (root.hasAttribute(modelElement.markerName)) {
52
+ break;
53
+ }
54
+ }
55
+ const markerName = modelElement.markerName;
56
+ const commentContent = root.getAttribute(markerName);
57
+ const comment = writer.createUIElement('$comment');
58
+ writer.setCustomProperty('$rawContent', commentContent, comment);
59
+ return comment;
60
+ }
61
+ });
62
+ // Remove comments' markers and their corresponding $root attributes, which are moved to the graveyard.
63
+ editor.model.document.registerPostFixer(writer => {
64
+ let changed = false;
65
+ const markers = editor.model.document.differ.getChangedMarkers().filter(marker => marker.name.startsWith('$comment:'));
66
+ for (const marker of markers) {
67
+ const { oldRange, newRange } = marker.data;
68
+ if (oldRange && newRange && oldRange.root == newRange.root) {
69
+ // The marker was moved in the same root. Don't do anything.
70
+ continue;
71
+ }
72
+ if (oldRange) {
73
+ // The comment marker was moved from one root to another (most probably to the graveyard).
74
+ // Remove the related attribute from the previous root.
75
+ const oldRoot = oldRange.root;
76
+ if (oldRoot.hasAttribute(marker.name)) {
77
+ writer.removeAttribute(marker.name, oldRoot);
78
+ changed = true;
79
+ }
80
+ }
81
+ if (newRange) {
82
+ const newRoot = newRange.root;
83
+ if (newRoot.rootName == '$graveyard') {
84
+ // Comment marker was moved to the graveyard -- remove it entirely.
85
+ writer.removeMarker(marker.name);
86
+ changed = true;
87
+ }
88
+ else if (!newRoot.hasAttribute(marker.name)) {
89
+ // Comment marker was just added or was moved to another root - updated roots attributes.
90
+ //
91
+ // Added fallback to `''` for the comment content in case if someone incorrectly added just the marker "by hand"
92
+ // and forgot to add the root attribute or add them in different change blocks.
93
+ //
94
+ // It caused an infinite loop in one of the unit tests.
95
+ writer.setAttribute(marker.name, loadedCommentsContent.get(marker.name) || '', newRoot);
96
+ changed = true;
97
+ }
98
+ }
99
+ }
100
+ return changed;
101
+ });
102
+ // Delete all comment markers from the document before setting new data.
103
+ editor.data.on('set', () => {
104
+ for (const commentMarker of editor.model.markers.getMarkersGroup('$comment')) {
105
+ this.removeHtmlComment(commentMarker.name);
106
+ }
107
+ }, { priority: 'high' });
108
+ // Delete all comment markers that are within a removed range.
109
+ // Delete all comment markers at the limit element boundaries if the whole content of the limit element is removed.
110
+ editor.model.on('deleteContent', (evt, [selection]) => {
111
+ for (const range of selection.getRanges()) {
112
+ const limitElement = editor.model.schema.getLimitElement(range);
113
+ const firstPosition = editor.model.createPositionAt(limitElement, 0);
114
+ const lastPosition = editor.model.createPositionAt(limitElement, 'end');
115
+ let affectedCommentIDs;
116
+ if (firstPosition.isTouching(range.start) && lastPosition.isTouching(range.end)) {
117
+ affectedCommentIDs = this.getHtmlCommentsInRange(editor.model.createRange(firstPosition, lastPosition));
118
+ }
119
+ else {
120
+ affectedCommentIDs = this.getHtmlCommentsInRange(range, { skipBoundaries: true });
121
+ }
122
+ for (const commentMarkerID of affectedCommentIDs) {
123
+ this.removeHtmlComment(commentMarkerID);
124
+ }
125
+ }
126
+ }, { priority: 'high' });
127
+ }
128
+ /**
129
+ * Creates an HTML comment on the specified position and returns its ID.
130
+ *
131
+ * *Note*: If two comments are created at the same position, the second comment will be inserted before the first one.
132
+ *
133
+ * @returns Comment ID. This ID can be later used to e.g. remove the comment from the content.
134
+ */
135
+ createHtmlComment(position, content) {
136
+ const id = uid();
137
+ const editor = this.editor;
138
+ const model = editor.model;
139
+ const root = model.document.getRoot(position.root.rootName);
140
+ const markerName = `$comment:${id}`;
141
+ return model.change(writer => {
142
+ const range = writer.createRange(position);
143
+ writer.addMarker(markerName, {
144
+ usingOperation: true,
145
+ affectsData: true,
146
+ range
147
+ });
148
+ writer.setAttribute(markerName, content, root);
149
+ return markerName;
150
+ });
151
+ }
152
+ /**
153
+ * Removes an HTML comment with the given comment ID.
154
+ *
155
+ * It does nothing and returns `false` if the comment with the given ID does not exist.
156
+ * Otherwise it removes the comment and returns `true`.
157
+ *
158
+ * Note that a comment can be removed also by removing the content around the comment.
159
+ *
160
+ * @param commentID The ID of the comment to be removed.
161
+ * @returns `true` when the comment with the given ID was removed, `false` otherwise.
162
+ */
163
+ removeHtmlComment(commentID) {
164
+ const editor = this.editor;
165
+ const marker = editor.model.markers.get(commentID);
166
+ if (!marker) {
167
+ return false;
168
+ }
169
+ editor.model.change(writer => {
170
+ writer.removeMarker(marker);
171
+ });
172
+ return true;
173
+ }
174
+ /**
175
+ * Gets the HTML comment data for the comment with a given ID.
176
+ *
177
+ * Returns `null` if the comment does not exist.
178
+ */
179
+ getHtmlCommentData(commentID) {
180
+ const editor = this.editor;
181
+ const marker = editor.model.markers.get(commentID);
182
+ if (!marker) {
183
+ return null;
184
+ }
185
+ let content = '';
186
+ for (const root of this.editor.model.document.getRoots()) {
187
+ if (root.hasAttribute(commentID)) {
188
+ content = root.getAttribute(commentID);
189
+ break;
190
+ }
191
+ }
192
+ return {
193
+ content,
194
+ position: marker.getStart()
195
+ };
196
+ }
197
+ /**
198
+ * Gets all HTML comments in the given range.
199
+ *
200
+ * By default, it includes comments at the range boundaries.
201
+ *
202
+ * @param range
203
+ * @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
204
+ * @returns HTML comment IDs
205
+ */
206
+ getHtmlCommentsInRange(range, { skipBoundaries = false } = {}) {
207
+ const includeBoundaries = !skipBoundaries;
208
+ // Unfortunately, MarkerCollection#getMarkersAtPosition() filters out collapsed markers.
209
+ return Array.from(this.editor.model.markers.getMarkersGroup('$comment'))
210
+ .filter(marker => isCommentMarkerInRange(marker, range))
211
+ .map(marker => marker.name);
212
+ function isCommentMarkerInRange(commentMarker, range) {
213
+ const position = commentMarker.getRange().start;
214
+ return ((position.isAfter(range.start) || (includeBoundaries && position.isEqual(range.start))) &&
215
+ (position.isBefore(range.end) || (includeBoundaries && position.isEqual(range.end))));
216
+ }
217
+ }
218
+ }
@@ -1,22 +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
- }
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
+ }