@ckeditor/ckeditor5-html-support 47.6.1 → 48.0.0-alpha.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 (208) hide show
  1. package/LICENSE.md +1 -1
  2. package/ckeditor5-metadata.json +6 -6
  3. package/{src → dist}/converters.d.ts +2 -2
  4. package/{src → dist}/datafilter.d.ts +3 -3
  5. package/{src → dist}/dataschema.d.ts +2 -2
  6. package/{src → dist}/emptyblock.d.ts +1 -1
  7. package/{src → dist}/fullpage.d.ts +1 -1
  8. package/{src → dist}/generalhtmlsupport.d.ts +3 -3
  9. package/{src → dist}/generalhtmlsupportconfig.d.ts +1 -1
  10. package/{src → dist}/htmlcomment.d.ts +2 -2
  11. package/{src → dist}/htmlpagedataprocessor.d.ts +1 -1
  12. package/dist/index-editor.css +29 -29
  13. package/dist/index.css +30 -40
  14. package/dist/index.css.map +1 -1
  15. package/dist/index.js +29 -8
  16. package/dist/index.js.map +1 -1
  17. package/{src → dist}/integrations/codeblock.d.ts +1 -1
  18. package/{src → dist}/integrations/customelement.d.ts +1 -1
  19. package/{src → dist}/integrations/dualcontent.d.ts +1 -1
  20. package/{src → dist}/integrations/heading.d.ts +2 -2
  21. package/{src → dist}/integrations/horizontalline.d.ts +1 -1
  22. package/{src → dist}/integrations/iframe.d.ts +1 -1
  23. package/{src → dist}/integrations/image.d.ts +1 -1
  24. package/{src → dist}/integrations/integrationutils.d.ts +1 -1
  25. package/{src → dist}/integrations/list.d.ts +1 -1
  26. package/{src → dist}/integrations/mediaembed.d.ts +1 -1
  27. package/{src → dist}/integrations/script.d.ts +1 -1
  28. package/{src → dist}/integrations/style.d.ts +1 -1
  29. package/{src → dist}/integrations/table.d.ts +1 -1
  30. package/{src → dist}/schemadefinitions.d.ts +2 -2
  31. package/{src → dist}/utils.d.ts +1 -1
  32. package/package.json +30 -53
  33. package/build/html-support.js +0 -5
  34. package/build/translations/af.js +0 -1
  35. package/build/translations/ar.js +0 -1
  36. package/build/translations/ast.js +0 -1
  37. package/build/translations/az.js +0 -1
  38. package/build/translations/be.js +0 -1
  39. package/build/translations/bg.js +0 -1
  40. package/build/translations/bn.js +0 -1
  41. package/build/translations/bs.js +0 -1
  42. package/build/translations/ca.js +0 -1
  43. package/build/translations/cs.js +0 -1
  44. package/build/translations/da.js +0 -1
  45. package/build/translations/de-ch.js +0 -1
  46. package/build/translations/de.js +0 -1
  47. package/build/translations/el.js +0 -1
  48. package/build/translations/en-au.js +0 -1
  49. package/build/translations/en-gb.js +0 -1
  50. package/build/translations/eo.js +0 -1
  51. package/build/translations/es-co.js +0 -1
  52. package/build/translations/es.js +0 -1
  53. package/build/translations/et.js +0 -1
  54. package/build/translations/eu.js +0 -1
  55. package/build/translations/fa.js +0 -1
  56. package/build/translations/fi.js +0 -1
  57. package/build/translations/fr.js +0 -1
  58. package/build/translations/gl.js +0 -1
  59. package/build/translations/gu.js +0 -1
  60. package/build/translations/he.js +0 -1
  61. package/build/translations/hi.js +0 -1
  62. package/build/translations/hr.js +0 -1
  63. package/build/translations/hu.js +0 -1
  64. package/build/translations/hy.js +0 -1
  65. package/build/translations/id.js +0 -1
  66. package/build/translations/it.js +0 -1
  67. package/build/translations/ja.js +0 -1
  68. package/build/translations/jv.js +0 -1
  69. package/build/translations/kk.js +0 -1
  70. package/build/translations/km.js +0 -1
  71. package/build/translations/kn.js +0 -1
  72. package/build/translations/ko.js +0 -1
  73. package/build/translations/ku.js +0 -1
  74. package/build/translations/lt.js +0 -1
  75. package/build/translations/lv.js +0 -1
  76. package/build/translations/ms.js +0 -1
  77. package/build/translations/nb.js +0 -1
  78. package/build/translations/ne.js +0 -1
  79. package/build/translations/nl.js +0 -1
  80. package/build/translations/no.js +0 -1
  81. package/build/translations/oc.js +0 -1
  82. package/build/translations/pl.js +0 -1
  83. package/build/translations/pt-br.js +0 -1
  84. package/build/translations/pt.js +0 -1
  85. package/build/translations/ro.js +0 -1
  86. package/build/translations/ru.js +0 -1
  87. package/build/translations/si.js +0 -1
  88. package/build/translations/sk.js +0 -1
  89. package/build/translations/sl.js +0 -1
  90. package/build/translations/sq.js +0 -1
  91. package/build/translations/sr-latn.js +0 -1
  92. package/build/translations/sr.js +0 -1
  93. package/build/translations/sv.js +0 -1
  94. package/build/translations/th.js +0 -1
  95. package/build/translations/ti.js +0 -1
  96. package/build/translations/tk.js +0 -1
  97. package/build/translations/tr.js +0 -1
  98. package/build/translations/tt.js +0 -1
  99. package/build/translations/ug.js +0 -1
  100. package/build/translations/uk.js +0 -1
  101. package/build/translations/ur.js +0 -1
  102. package/build/translations/uz.js +0 -1
  103. package/build/translations/vi.js +0 -1
  104. package/build/translations/zh-cn.js +0 -1
  105. package/build/translations/zh.js +0 -1
  106. package/lang/contexts.json +0 -3
  107. package/lang/translations/af.po +0 -16
  108. package/lang/translations/ar.po +0 -16
  109. package/lang/translations/ast.po +0 -16
  110. package/lang/translations/az.po +0 -16
  111. package/lang/translations/be.po +0 -16
  112. package/lang/translations/bg.po +0 -16
  113. package/lang/translations/bn.po +0 -16
  114. package/lang/translations/bs.po +0 -16
  115. package/lang/translations/ca.po +0 -16
  116. package/lang/translations/cs.po +0 -16
  117. package/lang/translations/da.po +0 -16
  118. package/lang/translations/de-ch.po +0 -16
  119. package/lang/translations/de.po +0 -16
  120. package/lang/translations/el.po +0 -16
  121. package/lang/translations/en-au.po +0 -16
  122. package/lang/translations/en-gb.po +0 -16
  123. package/lang/translations/en.po +0 -16
  124. package/lang/translations/eo.po +0 -16
  125. package/lang/translations/es-co.po +0 -16
  126. package/lang/translations/es.po +0 -16
  127. package/lang/translations/et.po +0 -16
  128. package/lang/translations/eu.po +0 -16
  129. package/lang/translations/fa.po +0 -16
  130. package/lang/translations/fi.po +0 -16
  131. package/lang/translations/fr.po +0 -16
  132. package/lang/translations/gl.po +0 -16
  133. package/lang/translations/gu.po +0 -16
  134. package/lang/translations/he.po +0 -16
  135. package/lang/translations/hi.po +0 -16
  136. package/lang/translations/hr.po +0 -16
  137. package/lang/translations/hu.po +0 -16
  138. package/lang/translations/hy.po +0 -16
  139. package/lang/translations/id.po +0 -16
  140. package/lang/translations/it.po +0 -16
  141. package/lang/translations/ja.po +0 -16
  142. package/lang/translations/jv.po +0 -16
  143. package/lang/translations/kk.po +0 -16
  144. package/lang/translations/km.po +0 -16
  145. package/lang/translations/kn.po +0 -16
  146. package/lang/translations/ko.po +0 -16
  147. package/lang/translations/ku.po +0 -16
  148. package/lang/translations/lt.po +0 -16
  149. package/lang/translations/lv.po +0 -16
  150. package/lang/translations/ms.po +0 -16
  151. package/lang/translations/nb.po +0 -16
  152. package/lang/translations/ne.po +0 -16
  153. package/lang/translations/nl.po +0 -16
  154. package/lang/translations/no.po +0 -16
  155. package/lang/translations/oc.po +0 -16
  156. package/lang/translations/pl.po +0 -16
  157. package/lang/translations/pt-br.po +0 -16
  158. package/lang/translations/pt.po +0 -16
  159. package/lang/translations/ro.po +0 -16
  160. package/lang/translations/ru.po +0 -16
  161. package/lang/translations/si.po +0 -16
  162. package/lang/translations/sk.po +0 -16
  163. package/lang/translations/sl.po +0 -16
  164. package/lang/translations/sq.po +0 -16
  165. package/lang/translations/sr-latn.po +0 -16
  166. package/lang/translations/sr.po +0 -16
  167. package/lang/translations/sv.po +0 -16
  168. package/lang/translations/th.po +0 -16
  169. package/lang/translations/ti.po +0 -16
  170. package/lang/translations/tk.po +0 -16
  171. package/lang/translations/tr.po +0 -16
  172. package/lang/translations/tt.po +0 -16
  173. package/lang/translations/ug.po +0 -16
  174. package/lang/translations/uk.po +0 -16
  175. package/lang/translations/ur.po +0 -16
  176. package/lang/translations/uz.po +0 -16
  177. package/lang/translations/vi.po +0 -16
  178. package/lang/translations/zh-cn.po +0 -16
  179. package/lang/translations/zh.po +0 -16
  180. package/src/augmentation.js +0 -5
  181. package/src/converters.js +0 -190
  182. package/src/datafilter.js +0 -837
  183. package/src/dataschema.js +0 -199
  184. package/src/emptyblock.js +0 -146
  185. package/src/fullpage.js +0 -184
  186. package/src/generalhtmlsupport.js +0 -257
  187. package/src/generalhtmlsupportconfig.js +0 -5
  188. package/src/htmlcomment.js +0 -225
  189. package/src/htmlpagedataprocessor.js +0 -70
  190. package/src/index.js +0 -31
  191. package/src/integrations/codeblock.js +0 -107
  192. package/src/integrations/customelement.js +0 -166
  193. package/src/integrations/dualcontent.js +0 -126
  194. package/src/integrations/heading.js +0 -72
  195. package/src/integrations/horizontalline.js +0 -80
  196. package/src/integrations/iframe.js +0 -76
  197. package/src/integrations/image.js +0 -195
  198. package/src/integrations/integrationutils.js +0 -21
  199. package/src/integrations/list.js +0 -185
  200. package/src/integrations/mediaembed.js +0 -125
  201. package/src/integrations/script.js +0 -66
  202. package/src/integrations/style.js +0 -66
  203. package/src/integrations/table.js +0 -209
  204. package/src/schemadefinitions.js +0 -979
  205. package/src/utils.js +0 -169
  206. package/theme/datafilter.css +0 -56
  207. /package/{src → dist}/augmentation.d.ts +0 -0
  208. /package/{src → dist}/index.d.ts +0 -0
@@ -1,257 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module html-support/generalhtmlsupport
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { toArray } from 'ckeditor5/src/utils.js';
10
- import { DataFilter } from './datafilter.js';
11
- import { CodeBlockElementSupport } from './integrations/codeblock.js';
12
- import { DualContentModelElementSupport } from './integrations/dualcontent.js';
13
- import { HeadingElementSupport } from './integrations/heading.js';
14
- import { ImageElementSupport } from './integrations/image.js';
15
- import { MediaEmbedElementSupport } from './integrations/mediaembed.js';
16
- import { ScriptElementSupport } from './integrations/script.js';
17
- import { TableElementSupport } from './integrations/table.js';
18
- import { StyleElementSupport } from './integrations/style.js';
19
- import { ListElementSupport } from './integrations/list.js';
20
- import { HorizontalLineElementSupport } from './integrations/horizontalline.js';
21
- import { IframeElementSupport } from './integrations/iframe.js';
22
- import { CustomElementSupport } from './integrations/customelement.js';
23
- import { getHtmlAttributeName, modifyGhsAttribute, removeFormatting } from './utils.js';
24
- /**
25
- * The General HTML Support feature.
26
- *
27
- * This is a "glue" plugin which initializes the {@link module:html-support/datafilter~DataFilter data filter} configuration
28
- * and features integration with the General HTML Support.
29
- */
30
- export class GeneralHtmlSupport extends Plugin {
31
- /**
32
- * @inheritDoc
33
- */
34
- static get pluginName() {
35
- return 'GeneralHtmlSupport';
36
- }
37
- /**
38
- * @inheritDoc
39
- */
40
- static get isOfficialPlugin() {
41
- return true;
42
- }
43
- /**
44
- * @inheritDoc
45
- */
46
- static get requires() {
47
- return [
48
- DataFilter,
49
- CodeBlockElementSupport,
50
- DualContentModelElementSupport,
51
- HeadingElementSupport,
52
- ImageElementSupport,
53
- MediaEmbedElementSupport,
54
- ScriptElementSupport,
55
- TableElementSupport,
56
- StyleElementSupport,
57
- ListElementSupport,
58
- HorizontalLineElementSupport,
59
- IframeElementSupport,
60
- CustomElementSupport
61
- ];
62
- }
63
- /**
64
- * @inheritDoc
65
- */
66
- init() {
67
- const editor = this.editor;
68
- const dataFilter = editor.plugins.get(DataFilter);
69
- // Load the allowed empty inline elements' configuration.
70
- // Note that this modifies DataSchema so must be loaded before registering filtering rules.
71
- dataFilter.loadAllowedEmptyElementsConfig(editor.config.get('htmlSupport.allowEmpty') || []);
72
- // Load the filtering configuration.
73
- dataFilter.loadAllowedConfig(editor.config.get('htmlSupport.allow') || []);
74
- dataFilter.loadDisallowedConfig(editor.config.get('htmlSupport.disallow') || []);
75
- }
76
- /**
77
- * @inheritDoc
78
- */
79
- afterInit() {
80
- const removeFormatCommand = this.editor.commands.get('removeFormat');
81
- removeFormatCommand?.registerCustomAttribute(attributeName => attributeName.startsWith('html') && attributeName.endsWith('Attributes'), removeFormatting);
82
- }
83
- /**
84
- * Returns a GHS model attribute name related to a given view element name.
85
- *
86
- * @internal
87
- * @param viewElementName A view element name.
88
- */
89
- getGhsAttributeNameForElement(viewElementName) {
90
- const dataSchema = this.editor.plugins.get('DataSchema');
91
- const definitions = Array.from(dataSchema.getDefinitionsForView(viewElementName, false));
92
- const inlineDefinition = definitions.find(definition => (definition.isInline && !definitions[0].isObject));
93
- if (inlineDefinition) {
94
- return inlineDefinition.model;
95
- }
96
- return getHtmlAttributeName(viewElementName);
97
- }
98
- /**
99
- * Updates GHS model attribute for a specified view element name, so it includes the given class name.
100
- *
101
- * @internal
102
- * @param viewElementName A view element name.
103
- * @param className The css class to add.
104
- * @param selectable The selection or element to update.
105
- */
106
- addModelHtmlClass(viewElementName, className, selectable) {
107
- const model = this.editor.model;
108
- const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
109
- model.change(writer => {
110
- for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
111
- modifyGhsAttribute(writer, item, ghsAttributeName, 'classes', classes => {
112
- for (const value of toArray(className)) {
113
- classes.add(value);
114
- }
115
- });
116
- }
117
- });
118
- }
119
- /**
120
- * Updates GHS model attribute for a specified view element name, so it does not include the given class name.
121
- *
122
- * @internal
123
- * @param viewElementName A view element name.
124
- * @param className The css class to remove.
125
- * @param selectable The selection or element to update.
126
- */
127
- removeModelHtmlClass(viewElementName, className, selectable) {
128
- const model = this.editor.model;
129
- const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
130
- model.change(writer => {
131
- for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
132
- modifyGhsAttribute(writer, item, ghsAttributeName, 'classes', classes => {
133
- for (const value of toArray(className)) {
134
- classes.delete(value);
135
- }
136
- });
137
- }
138
- });
139
- }
140
- /**
141
- * Updates GHS model attribute for a specified view element name, so it includes the given attribute.
142
- *
143
- * @param viewElementName A view element name.
144
- * @param attributes The object with attributes to set.
145
- * @param selectable The selection or element to update.
146
- */
147
- setModelHtmlAttributes(viewElementName, attributes, selectable) {
148
- const model = this.editor.model;
149
- const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
150
- model.change(writer => {
151
- for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
152
- modifyGhsAttribute(writer, item, ghsAttributeName, 'attributes', attributesMap => {
153
- for (const [key, value] of Object.entries(attributes)) {
154
- attributesMap.set(key, value);
155
- }
156
- });
157
- }
158
- });
159
- }
160
- /**
161
- * Updates GHS model attribute for a specified view element name, so it does not include the given attribute.
162
- *
163
- * @param viewElementName A view element name.
164
- * @param attributeName The attribute name (or names) to remove.
165
- * @param selectable The selection or element to update.
166
- */
167
- removeModelHtmlAttributes(viewElementName, attributeName, selectable) {
168
- const model = this.editor.model;
169
- const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
170
- model.change(writer => {
171
- for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
172
- modifyGhsAttribute(writer, item, ghsAttributeName, 'attributes', attributesMap => {
173
- for (const key of toArray(attributeName)) {
174
- attributesMap.delete(key);
175
- }
176
- });
177
- }
178
- });
179
- }
180
- /**
181
- * Updates GHS model attribute for a specified view element name, so it includes a given style.
182
- *
183
- * @param viewElementName A view element name.
184
- * @param styles The object with styles to set.
185
- * @param selectable The selection or element to update.
186
- */
187
- setModelHtmlStyles(viewElementName, styles, selectable) {
188
- const model = this.editor.model;
189
- const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
190
- model.change(writer => {
191
- for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
192
- modifyGhsAttribute(writer, item, ghsAttributeName, 'styles', stylesMap => {
193
- for (const [key, value] of Object.entries(styles)) {
194
- stylesMap.set(key, value);
195
- }
196
- });
197
- }
198
- });
199
- }
200
- /**
201
- * Updates GHS model attribute for a specified view element name, so it does not include a given style.
202
- *
203
- * @param viewElementName A view element name.
204
- * @param properties The style (or styles list) to remove.
205
- * @param selectable The selection or element to update.
206
- */
207
- removeModelHtmlStyles(viewElementName, properties, selectable) {
208
- const model = this.editor.model;
209
- const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
210
- model.change(writer => {
211
- for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
212
- modifyGhsAttribute(writer, item, ghsAttributeName, 'styles', stylesMap => {
213
- for (const key of toArray(properties)) {
214
- stylesMap.delete(key);
215
- }
216
- });
217
- }
218
- });
219
- }
220
- }
221
- /**
222
- * Returns an iterator over an items in the selectable that accept given GHS attribute.
223
- */
224
- function* getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName) {
225
- if (!selectable) {
226
- return;
227
- }
228
- if (!(Symbol.iterator in selectable) && selectable.is('documentSelection') && selectable.isCollapsed) {
229
- if (model.schema.checkAttributeInSelection(selectable, ghsAttributeName)) {
230
- yield selectable;
231
- }
232
- }
233
- else {
234
- for (const range of getValidRangesForSelectable(model, selectable, ghsAttributeName)) {
235
- yield* range.getItems({ shallow: true });
236
- }
237
- }
238
- }
239
- /**
240
- * Translates a given selectable to an iterable of ranges.
241
- */
242
- function getValidRangesForSelectable(model, selectable, ghsAttributeName) {
243
- if (!(Symbol.iterator in selectable) &&
244
- (selectable.is('node') ||
245
- selectable.is('$text') ||
246
- selectable.is('$textProxy'))) {
247
- if (model.schema.checkAttribute(selectable, ghsAttributeName)) {
248
- return [model.createRangeOn(selectable)];
249
- }
250
- else {
251
- return [];
252
- }
253
- }
254
- else {
255
- return model.schema.getValidRanges(model.createSelection(selectable).getRanges(), ghsAttributeName);
256
- }
257
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- export {};
@@ -1,225 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- import { Plugin } from 'ckeditor5/src/core.js';
6
- import { uid } from 'ckeditor5/src/utils.js';
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 class HtmlComment extends Plugin {
13
- /**
14
- * @inheritDoc
15
- */
16
- static get pluginName() {
17
- return 'HtmlComment';
18
- }
19
- /**
20
- * @inheritDoc
21
- */
22
- static get isOfficialPlugin() {
23
- return true;
24
- }
25
- /**
26
- * @inheritDoc
27
- */
28
- init() {
29
- const editor = this.editor;
30
- const loadedCommentsContent = new Map();
31
- editor.data.processor.skipComments = false;
32
- // Allow storing comment's content as the $root attribute with the name `$comment:<unique id>`.
33
- editor.model.schema.addAttributeCheck((context, attributeName) => {
34
- if (context.endsWith('$root') && attributeName.startsWith('$comment')) {
35
- return true;
36
- }
37
- });
38
- // Convert the `$comment` view element to `$comment:<unique id>` marker and store its content (the comment itself) as a $root
39
- // attribute. The comment content is needed in the `dataDowncast` pipeline to re-create the comment node.
40
- editor.conversion.for('upcast').elementToMarker({
41
- view: '$comment',
42
- model: viewElement => {
43
- const markerUid = uid();
44
- const markerName = `$comment:${markerUid}`;
45
- const commentContent = viewElement.getCustomProperty('$rawContent');
46
- loadedCommentsContent.set(markerName, commentContent);
47
- return markerName;
48
- }
49
- });
50
- // Convert the `$comment` marker to `$comment` UI element with `$rawContent` custom property containing the comment content.
51
- editor.conversion.for('dataDowncast').markerToElement({
52
- model: '$comment',
53
- view: (modelElement, { writer }) => {
54
- let root = undefined;
55
- for (const rootName of this.editor.model.document.getRootNames()) {
56
- root = this.editor.model.document.getRoot(rootName);
57
- if (root.hasAttribute(modelElement.markerName)) {
58
- break;
59
- }
60
- }
61
- const markerName = modelElement.markerName;
62
- const commentContent = root.getAttribute(markerName);
63
- const comment = writer.createUIElement('$comment');
64
- writer.setCustomProperty('$rawContent', commentContent, comment);
65
- return comment;
66
- }
67
- });
68
- // Remove comments' markers and their corresponding $root attributes, which are moved to the graveyard.
69
- editor.model.document.registerPostFixer(writer => {
70
- let changed = false;
71
- const markers = editor.model.document.differ.getChangedMarkers().filter(marker => marker.name.startsWith('$comment:'));
72
- for (const marker of markers) {
73
- const { oldRange, newRange } = marker.data;
74
- if (oldRange && newRange && oldRange.root == newRange.root) {
75
- // The marker was moved in the same root. Don't do anything.
76
- continue;
77
- }
78
- if (oldRange) {
79
- // The comment marker was moved from one root to another (most probably to the graveyard).
80
- // Remove the related attribute from the previous root.
81
- const oldRoot = oldRange.root;
82
- if (oldRoot.hasAttribute(marker.name)) {
83
- writer.removeAttribute(marker.name, oldRoot);
84
- changed = true;
85
- }
86
- }
87
- if (newRange) {
88
- const newRoot = newRange.root;
89
- if (newRoot.rootName == '$graveyard') {
90
- // Comment marker was moved to the graveyard -- remove it entirely.
91
- writer.removeMarker(marker.name);
92
- changed = true;
93
- }
94
- else if (!newRoot.hasAttribute(marker.name)) {
95
- // Comment marker was just added or was moved to another root - updated roots attributes.
96
- //
97
- // Added fallback to `''` for the comment content in case if someone incorrectly added just the marker "by hand"
98
- // and forgot to add the root attribute or add them in different change blocks.
99
- //
100
- // It caused an infinite loop in one of the unit tests.
101
- writer.setAttribute(marker.name, loadedCommentsContent.get(marker.name) || '', newRoot);
102
- changed = true;
103
- }
104
- }
105
- }
106
- return changed;
107
- });
108
- // Delete all comment markers from the document before setting new data.
109
- editor.data.on('set', () => {
110
- for (const commentMarker of editor.model.markers.getMarkersGroup('$comment')) {
111
- this.removeHtmlComment(commentMarker.name);
112
- }
113
- }, { priority: 'high' });
114
- // Delete all comment markers that are within a removed range.
115
- // Delete all comment markers at the limit element boundaries if the whole content of the limit element is removed.
116
- editor.model.on('deleteContent', (evt, [selection]) => {
117
- for (const range of selection.getRanges()) {
118
- const limitElement = editor.model.schema.getLimitElement(range);
119
- const firstPosition = editor.model.createPositionAt(limitElement, 0);
120
- const lastPosition = editor.model.createPositionAt(limitElement, 'end');
121
- let affectedCommentIDs;
122
- if (firstPosition.isTouching(range.start) && lastPosition.isTouching(range.end)) {
123
- affectedCommentIDs = this.getHtmlCommentsInRange(editor.model.createRange(firstPosition, lastPosition));
124
- }
125
- else {
126
- affectedCommentIDs = this.getHtmlCommentsInRange(range, { skipBoundaries: true });
127
- }
128
- for (const commentMarkerID of affectedCommentIDs) {
129
- this.removeHtmlComment(commentMarkerID);
130
- }
131
- }
132
- }, { priority: 'high' });
133
- }
134
- /**
135
- * Creates an HTML comment on the specified position and returns its ID.
136
- *
137
- * *Note*: If two comments are created at the same position, the second comment will be inserted before the first one.
138
- *
139
- * @returns Comment ID. This ID can be later used to e.g. remove the comment from the content.
140
- */
141
- createHtmlComment(position, content) {
142
- const id = uid();
143
- const editor = this.editor;
144
- const model = editor.model;
145
- const root = model.document.getRoot(position.root.rootName);
146
- const markerName = `$comment:${id}`;
147
- return model.change(writer => {
148
- const range = writer.createRange(position);
149
- writer.addMarker(markerName, {
150
- usingOperation: true,
151
- affectsData: true,
152
- range
153
- });
154
- writer.setAttribute(markerName, content, root);
155
- return markerName;
156
- });
157
- }
158
- /**
159
- * Removes an HTML comment with the given comment ID.
160
- *
161
- * It does nothing and returns `false` if the comment with the given ID does not exist.
162
- * Otherwise it removes the comment and returns `true`.
163
- *
164
- * Note that a comment can be removed also by removing the content around the comment.
165
- *
166
- * @param commentID The ID of the comment to be removed.
167
- * @returns `true` when the comment with the given ID was removed, `false` otherwise.
168
- */
169
- removeHtmlComment(commentID) {
170
- const editor = this.editor;
171
- const marker = editor.model.markers.get(commentID);
172
- if (!marker) {
173
- return false;
174
- }
175
- editor.model.change(writer => {
176
- writer.removeMarker(marker);
177
- });
178
- return true;
179
- }
180
- /**
181
- * Gets the HTML comment data for the comment with a given ID.
182
- *
183
- * Returns `null` if the comment does not exist.
184
- */
185
- getHtmlCommentData(commentID) {
186
- const editor = this.editor;
187
- const marker = editor.model.markers.get(commentID);
188
- if (!marker) {
189
- return null;
190
- }
191
- let content = '';
192
- for (const root of this.editor.model.document.getRoots()) {
193
- if (root.hasAttribute(commentID)) {
194
- content = root.getAttribute(commentID);
195
- break;
196
- }
197
- }
198
- return {
199
- content,
200
- position: marker.getStart()
201
- };
202
- }
203
- /**
204
- * Gets all HTML comments in the given range.
205
- *
206
- * By default, it includes comments at the range boundaries.
207
- *
208
- * @param range The range to search for HTML comments.
209
- * @param options Additional options.
210
- * @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
211
- * @returns HTML comment IDs
212
- */
213
- getHtmlCommentsInRange(range, { skipBoundaries = false } = {}) {
214
- const includeBoundaries = !skipBoundaries;
215
- // Unfortunately, MarkerCollection#getMarkersAtPosition() filters out collapsed markers.
216
- return Array.from(this.editor.model.markers.getMarkersGroup('$comment'))
217
- .filter(marker => isCommentMarkerInRange(marker, range))
218
- .map(marker => marker.name);
219
- function isCommentMarkerInRange(commentMarker, range) {
220
- const position = commentMarker.getRange().start;
221
- return ((position.isAfter(range.start) || (includeBoundaries && position.isEqual(range.start))) &&
222
- (position.isBefore(range.end) || (includeBoundaries && position.isEqual(range.end))));
223
- }
224
- }
225
- }
@@ -1,70 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module html-support/htmlpagedataprocessor
7
- */
8
- import { HtmlDataProcessor, ViewUpcastWriter } from 'ckeditor5/src/engine.js';
9
- /**
10
- * The full page HTML data processor class.
11
- * This data processor implementation uses HTML as input and output data.
12
- */
13
- export class HtmlPageDataProcessor extends HtmlDataProcessor {
14
- /**
15
- * @inheritDoc
16
- */
17
- toView(data) {
18
- // Ignore content that is not a full page source.
19
- if (!/<(?:html|body|head|meta)(?:\s[^>]*)?>/i.test(data.trim().slice(0, 10000))) {
20
- return super.toView(data);
21
- }
22
- // Store doctype and xml declaration in a separate properties as they can't be stringified later.
23
- let docType = '';
24
- let xmlDeclaration = '';
25
- data = data.trim().replace(/<\?xml\s[^?]*\?>/i, match => {
26
- xmlDeclaration = match;
27
- return '';
28
- });
29
- data = data.trim().replace(/^<!DOCTYPE\s[^>]*?>/i, match => {
30
- docType = match;
31
- return '';
32
- });
33
- // Convert input HTML data to DOM DocumentFragment.
34
- const domFragment = this._toDom(data);
35
- // Convert DOM DocumentFragment to view DocumentFragment.
36
- const viewFragment = this.domConverter.domToView(domFragment, { skipComments: this.skipComments });
37
- const writer = new ViewUpcastWriter(viewFragment.document);
38
- // Using the DOM document with body content extracted as a skeleton of the page.
39
- writer.setCustomProperty('$fullPageDocument', domFragment.ownerDocument.documentElement.outerHTML, viewFragment);
40
- // List of `<style>` elements extracted from document's `<head>` element.
41
- const headStylesElements = Array.from(domFragment.ownerDocument.querySelectorAll('head style'));
42
- writer.setCustomProperty('$fullPageHeadStyles', headStylesElements, viewFragment);
43
- if (docType) {
44
- writer.setCustomProperty('$fullPageDocType', docType, viewFragment);
45
- }
46
- if (xmlDeclaration) {
47
- writer.setCustomProperty('$fullPageXmlDeclaration', xmlDeclaration, viewFragment);
48
- }
49
- return viewFragment;
50
- }
51
- /**
52
- * @inheritDoc
53
- */
54
- toData(viewFragment) {
55
- let data = super.toData(viewFragment);
56
- const page = viewFragment.getCustomProperty('$fullPageDocument');
57
- const docType = viewFragment.getCustomProperty('$fullPageDocType');
58
- const xmlDeclaration = viewFragment.getCustomProperty('$fullPageXmlDeclaration');
59
- if (page) {
60
- data = page.replace(/<\/body\s*>/, data + '$&');
61
- if (docType) {
62
- data = docType + '\n' + data;
63
- }
64
- if (xmlDeclaration) {
65
- data = xmlDeclaration + '\n' + data;
66
- }
67
- }
68
- return data;
69
- }
70
- }
package/src/index.js DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module html-support
7
- */
8
- export { GeneralHtmlSupport } from './generalhtmlsupport.js';
9
- export { DataFilter } from './datafilter.js';
10
- export { DataSchema } from './dataschema.js';
11
- export { HtmlComment } from './htmlcomment.js';
12
- export { FullPage } from './fullpage.js';
13
- export { HtmlPageDataProcessor } from './htmlpagedataprocessor.js';
14
- export { EmptyBlock } from './emptyblock.js';
15
- export { CodeBlockElementSupport } from './integrations/codeblock.js';
16
- export { CustomElementSupport } from './integrations/customelement.js';
17
- export { ListElementSupport } from './integrations/list.js';
18
- export { DualContentModelElementSupport } from './integrations/dualcontent.js';
19
- export { HeadingElementSupport } from './integrations/heading.js';
20
- export { ImageElementSupport } from './integrations/image.js';
21
- export { MediaEmbedElementSupport } from './integrations/mediaembed.js';
22
- export { ScriptElementSupport } from './integrations/script.js';
23
- export { StyleElementSupport } from './integrations/style.js';
24
- export { TableElementSupport } from './integrations/table.js';
25
- export { IframeElementSupport } from './integrations/iframe.js';
26
- export { HorizontalLineElementSupport } from './integrations/horizontalline.js';
27
- export { viewToModelObjectConverter as _viewToModelObjectContentHtmlSupportConverter, toObjectWidgetConverter as _toObjectWidgetHtmlSupportConverter, createObjectView as _createObjectHtmlSupportView, viewToAttributeInlineConverter as _viewToAttributeInlineHtmlSupportConverter, emptyInlineModelElementToViewConverter as _emptyInlineModelElementToViewHtmlSupportConverter, attributeToViewInlineConverter as _attributeToInlineHtmlSupportConverter, viewToModelBlockAttributeConverter as _viewToModelBlockAttributeHtmlSupportConverter, modelToViewBlockAttributeConverter as _modelToViewBlockAttributeHtmlSupportConverter } from './converters.js';
28
- export { getDescendantElement as _getHtmlSupportDescendantElement } from './integrations/integrationutils.js';
29
- export { defaultConfig as _HTML_SUPPORT_SCHEMA_DEFINITIONS } from './schemadefinitions.js';
30
- export { updateViewAttributes as _updateHtmlSupportViewAttributes, setViewAttributes as _setHtmlSupportViewAttributes, removeViewAttributes as _removeHtmlSupportViewAttributes, mergeViewElementAttributes as _mergeHtmlSupportViewElementAttributes, modifyGhsAttribute as _modifyHtmlSupportGhsAttribute, toPascalCase as _toHtmlSupportPascalCase, getHtmlAttributeName as _getHtmlSupportAttributeName } from './utils.js';
31
- import './augmentation.js';