@ckeditor/ckeditor5-html-support 0.0.0-internal-20241017.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 (312) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +26 -0
  4. package/build/html-support.js +5 -0
  5. package/build/translations/ar.js +1 -0
  6. package/build/translations/bg.js +1 -0
  7. package/build/translations/bn.js +1 -0
  8. package/build/translations/ca.js +1 -0
  9. package/build/translations/cs.js +1 -0
  10. package/build/translations/da.js +1 -0
  11. package/build/translations/de.js +1 -0
  12. package/build/translations/el.js +1 -0
  13. package/build/translations/en-au.js +1 -0
  14. package/build/translations/es.js +1 -0
  15. package/build/translations/et.js +1 -0
  16. package/build/translations/fi.js +1 -0
  17. package/build/translations/fr.js +1 -0
  18. package/build/translations/gl.js +1 -0
  19. package/build/translations/he.js +1 -0
  20. package/build/translations/hi.js +1 -0
  21. package/build/translations/hr.js +1 -0
  22. package/build/translations/hu.js +1 -0
  23. package/build/translations/id.js +1 -0
  24. package/build/translations/it.js +1 -0
  25. package/build/translations/ja.js +1 -0
  26. package/build/translations/jv.js +1 -0
  27. package/build/translations/ko.js +1 -0
  28. package/build/translations/lt.js +1 -0
  29. package/build/translations/lv.js +1 -0
  30. package/build/translations/ms.js +1 -0
  31. package/build/translations/nl.js +1 -0
  32. package/build/translations/no.js +1 -0
  33. package/build/translations/pl.js +1 -0
  34. package/build/translations/pt-br.js +1 -0
  35. package/build/translations/pt.js +1 -0
  36. package/build/translations/ro.js +1 -0
  37. package/build/translations/ru.js +1 -0
  38. package/build/translations/sk.js +1 -0
  39. package/build/translations/sr-latn.js +1 -0
  40. package/build/translations/sr.js +1 -0
  41. package/build/translations/sv.js +1 -0
  42. package/build/translations/th.js +1 -0
  43. package/build/translations/tr.js +1 -0
  44. package/build/translations/ug.js +1 -0
  45. package/build/translations/uk.js +1 -0
  46. package/build/translations/ur.js +1 -0
  47. package/build/translations/vi.js +1 -0
  48. package/build/translations/zh-cn.js +1 -0
  49. package/build/translations/zh.js +1 -0
  50. package/ckeditor5-metadata.json +60 -0
  51. package/dist/augmentation.d.ts +37 -0
  52. package/dist/converters.d.ts +64 -0
  53. package/dist/datafilter.d.ts +312 -0
  54. package/dist/dataschema.d.ts +191 -0
  55. package/dist/fullpage.d.ts +29 -0
  56. package/dist/generalhtmlsupport.d.ts +106 -0
  57. package/dist/generalhtmlsupportconfig.d.ts +81 -0
  58. package/dist/htmlcomment.d.ts +79 -0
  59. package/dist/htmlpagedataprocessor.d.ts +26 -0
  60. package/dist/index-content.css +4 -0
  61. package/dist/index-editor.css +51 -0
  62. package/dist/index.css +63 -0
  63. package/dist/index.css.map +1 -0
  64. package/dist/index.d.ts +29 -0
  65. package/dist/index.js +4040 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/integrations/codeblock.d.ts +31 -0
  68. package/dist/integrations/customelement.d.ts +35 -0
  69. package/dist/integrations/dualcontent.d.ts +53 -0
  70. package/dist/integrations/heading.d.ts +39 -0
  71. package/dist/integrations/image.d.ts +34 -0
  72. package/dist/integrations/integrationutils.d.ts +19 -0
  73. package/dist/integrations/list.d.ts +35 -0
  74. package/dist/integrations/mediaembed.d.ts +34 -0
  75. package/dist/integrations/script.d.ts +34 -0
  76. package/dist/integrations/style.d.ts +34 -0
  77. package/dist/integrations/table.d.ts +31 -0
  78. package/dist/schemadefinitions.d.ts +17 -0
  79. package/dist/translations/ar.d.ts +8 -0
  80. package/dist/translations/ar.js +5 -0
  81. package/dist/translations/ar.umd.js +11 -0
  82. package/dist/translations/bg.d.ts +8 -0
  83. package/dist/translations/bg.js +5 -0
  84. package/dist/translations/bg.umd.js +11 -0
  85. package/dist/translations/bn.d.ts +8 -0
  86. package/dist/translations/bn.js +5 -0
  87. package/dist/translations/bn.umd.js +11 -0
  88. package/dist/translations/ca.d.ts +8 -0
  89. package/dist/translations/ca.js +5 -0
  90. package/dist/translations/ca.umd.js +11 -0
  91. package/dist/translations/cs.d.ts +8 -0
  92. package/dist/translations/cs.js +5 -0
  93. package/dist/translations/cs.umd.js +11 -0
  94. package/dist/translations/da.d.ts +8 -0
  95. package/dist/translations/da.js +5 -0
  96. package/dist/translations/da.umd.js +11 -0
  97. package/dist/translations/de.d.ts +8 -0
  98. package/dist/translations/de.js +5 -0
  99. package/dist/translations/de.umd.js +11 -0
  100. package/dist/translations/el.d.ts +8 -0
  101. package/dist/translations/el.js +5 -0
  102. package/dist/translations/el.umd.js +11 -0
  103. package/dist/translations/en-au.d.ts +8 -0
  104. package/dist/translations/en-au.js +5 -0
  105. package/dist/translations/en-au.umd.js +11 -0
  106. package/dist/translations/en.d.ts +8 -0
  107. package/dist/translations/en.js +5 -0
  108. package/dist/translations/en.umd.js +11 -0
  109. package/dist/translations/es.d.ts +8 -0
  110. package/dist/translations/es.js +5 -0
  111. package/dist/translations/es.umd.js +11 -0
  112. package/dist/translations/et.d.ts +8 -0
  113. package/dist/translations/et.js +5 -0
  114. package/dist/translations/et.umd.js +11 -0
  115. package/dist/translations/fi.d.ts +8 -0
  116. package/dist/translations/fi.js +5 -0
  117. package/dist/translations/fi.umd.js +11 -0
  118. package/dist/translations/fr.d.ts +8 -0
  119. package/dist/translations/fr.js +5 -0
  120. package/dist/translations/fr.umd.js +11 -0
  121. package/dist/translations/gl.d.ts +8 -0
  122. package/dist/translations/gl.js +5 -0
  123. package/dist/translations/gl.umd.js +11 -0
  124. package/dist/translations/he.d.ts +8 -0
  125. package/dist/translations/he.js +5 -0
  126. package/dist/translations/he.umd.js +11 -0
  127. package/dist/translations/hi.d.ts +8 -0
  128. package/dist/translations/hi.js +5 -0
  129. package/dist/translations/hi.umd.js +11 -0
  130. package/dist/translations/hr.d.ts +8 -0
  131. package/dist/translations/hr.js +5 -0
  132. package/dist/translations/hr.umd.js +11 -0
  133. package/dist/translations/hu.d.ts +8 -0
  134. package/dist/translations/hu.js +5 -0
  135. package/dist/translations/hu.umd.js +11 -0
  136. package/dist/translations/id.d.ts +8 -0
  137. package/dist/translations/id.js +5 -0
  138. package/dist/translations/id.umd.js +11 -0
  139. package/dist/translations/it.d.ts +8 -0
  140. package/dist/translations/it.js +5 -0
  141. package/dist/translations/it.umd.js +11 -0
  142. package/dist/translations/ja.d.ts +8 -0
  143. package/dist/translations/ja.js +5 -0
  144. package/dist/translations/ja.umd.js +11 -0
  145. package/dist/translations/jv.d.ts +8 -0
  146. package/dist/translations/jv.js +5 -0
  147. package/dist/translations/jv.umd.js +11 -0
  148. package/dist/translations/ko.d.ts +8 -0
  149. package/dist/translations/ko.js +5 -0
  150. package/dist/translations/ko.umd.js +11 -0
  151. package/dist/translations/lt.d.ts +8 -0
  152. package/dist/translations/lt.js +5 -0
  153. package/dist/translations/lt.umd.js +11 -0
  154. package/dist/translations/lv.d.ts +8 -0
  155. package/dist/translations/lv.js +5 -0
  156. package/dist/translations/lv.umd.js +11 -0
  157. package/dist/translations/ms.d.ts +8 -0
  158. package/dist/translations/ms.js +5 -0
  159. package/dist/translations/ms.umd.js +11 -0
  160. package/dist/translations/nl.d.ts +8 -0
  161. package/dist/translations/nl.js +5 -0
  162. package/dist/translations/nl.umd.js +11 -0
  163. package/dist/translations/no.d.ts +8 -0
  164. package/dist/translations/no.js +5 -0
  165. package/dist/translations/no.umd.js +11 -0
  166. package/dist/translations/pl.d.ts +8 -0
  167. package/dist/translations/pl.js +5 -0
  168. package/dist/translations/pl.umd.js +11 -0
  169. package/dist/translations/pt-br.d.ts +8 -0
  170. package/dist/translations/pt-br.js +5 -0
  171. package/dist/translations/pt-br.umd.js +11 -0
  172. package/dist/translations/pt.d.ts +8 -0
  173. package/dist/translations/pt.js +5 -0
  174. package/dist/translations/pt.umd.js +11 -0
  175. package/dist/translations/ro.d.ts +8 -0
  176. package/dist/translations/ro.js +5 -0
  177. package/dist/translations/ro.umd.js +11 -0
  178. package/dist/translations/ru.d.ts +8 -0
  179. package/dist/translations/ru.js +5 -0
  180. package/dist/translations/ru.umd.js +11 -0
  181. package/dist/translations/sk.d.ts +8 -0
  182. package/dist/translations/sk.js +5 -0
  183. package/dist/translations/sk.umd.js +11 -0
  184. package/dist/translations/sr-latn.d.ts +8 -0
  185. package/dist/translations/sr-latn.js +5 -0
  186. package/dist/translations/sr-latn.umd.js +11 -0
  187. package/dist/translations/sr.d.ts +8 -0
  188. package/dist/translations/sr.js +5 -0
  189. package/dist/translations/sr.umd.js +11 -0
  190. package/dist/translations/sv.d.ts +8 -0
  191. package/dist/translations/sv.js +5 -0
  192. package/dist/translations/sv.umd.js +11 -0
  193. package/dist/translations/th.d.ts +8 -0
  194. package/dist/translations/th.js +5 -0
  195. package/dist/translations/th.umd.js +11 -0
  196. package/dist/translations/tr.d.ts +8 -0
  197. package/dist/translations/tr.js +5 -0
  198. package/dist/translations/tr.umd.js +11 -0
  199. package/dist/translations/ug.d.ts +8 -0
  200. package/dist/translations/ug.js +5 -0
  201. package/dist/translations/ug.umd.js +11 -0
  202. package/dist/translations/uk.d.ts +8 -0
  203. package/dist/translations/uk.js +5 -0
  204. package/dist/translations/uk.umd.js +11 -0
  205. package/dist/translations/ur.d.ts +8 -0
  206. package/dist/translations/ur.js +5 -0
  207. package/dist/translations/ur.umd.js +11 -0
  208. package/dist/translations/vi.d.ts +8 -0
  209. package/dist/translations/vi.js +5 -0
  210. package/dist/translations/vi.umd.js +11 -0
  211. package/dist/translations/zh-cn.d.ts +8 -0
  212. package/dist/translations/zh-cn.js +5 -0
  213. package/dist/translations/zh-cn.umd.js +11 -0
  214. package/dist/translations/zh.d.ts +8 -0
  215. package/dist/translations/zh.js +5 -0
  216. package/dist/translations/zh.umd.js +11 -0
  217. package/dist/utils.d.ts +76 -0
  218. package/lang/contexts.json +3 -0
  219. package/lang/translations/ar.po +22 -0
  220. package/lang/translations/bg.po +22 -0
  221. package/lang/translations/bn.po +22 -0
  222. package/lang/translations/ca.po +22 -0
  223. package/lang/translations/cs.po +22 -0
  224. package/lang/translations/da.po +22 -0
  225. package/lang/translations/de.po +22 -0
  226. package/lang/translations/el.po +22 -0
  227. package/lang/translations/en-au.po +22 -0
  228. package/lang/translations/en.po +22 -0
  229. package/lang/translations/es.po +22 -0
  230. package/lang/translations/et.po +22 -0
  231. package/lang/translations/fi.po +22 -0
  232. package/lang/translations/fr.po +22 -0
  233. package/lang/translations/gl.po +22 -0
  234. package/lang/translations/he.po +22 -0
  235. package/lang/translations/hi.po +22 -0
  236. package/lang/translations/hr.po +22 -0
  237. package/lang/translations/hu.po +22 -0
  238. package/lang/translations/id.po +22 -0
  239. package/lang/translations/it.po +22 -0
  240. package/lang/translations/ja.po +22 -0
  241. package/lang/translations/jv.po +22 -0
  242. package/lang/translations/ko.po +22 -0
  243. package/lang/translations/lt.po +22 -0
  244. package/lang/translations/lv.po +22 -0
  245. package/lang/translations/ms.po +22 -0
  246. package/lang/translations/nl.po +22 -0
  247. package/lang/translations/no.po +22 -0
  248. package/lang/translations/pl.po +22 -0
  249. package/lang/translations/pt-br.po +22 -0
  250. package/lang/translations/pt.po +22 -0
  251. package/lang/translations/ro.po +22 -0
  252. package/lang/translations/ru.po +22 -0
  253. package/lang/translations/sk.po +22 -0
  254. package/lang/translations/sr-latn.po +22 -0
  255. package/lang/translations/sr.po +22 -0
  256. package/lang/translations/sv.po +22 -0
  257. package/lang/translations/th.po +22 -0
  258. package/lang/translations/tr.po +22 -0
  259. package/lang/translations/ug.po +22 -0
  260. package/lang/translations/uk.po +22 -0
  261. package/lang/translations/ur.po +22 -0
  262. package/lang/translations/vi.po +22 -0
  263. package/lang/translations/zh-cn.po +22 -0
  264. package/lang/translations/zh.po +22 -0
  265. package/package.json +48 -0
  266. package/src/augmentation.d.ts +33 -0
  267. package/src/augmentation.js +5 -0
  268. package/src/converters.d.ts +60 -0
  269. package/src/converters.js +180 -0
  270. package/src/datafilter.d.ts +308 -0
  271. package/src/datafilter.js +755 -0
  272. package/src/dataschema.d.ts +187 -0
  273. package/src/dataschema.js +202 -0
  274. package/src/fullpage.d.ts +25 -0
  275. package/src/fullpage.js +86 -0
  276. package/src/generalhtmlsupport.d.ts +102 -0
  277. package/src/generalhtmlsupport.js +246 -0
  278. package/src/generalhtmlsupportconfig.d.ts +77 -0
  279. package/src/generalhtmlsupportconfig.js +5 -0
  280. package/src/htmlcomment.d.ts +75 -0
  281. package/src/htmlcomment.js +224 -0
  282. package/src/htmlpagedataprocessor.d.ts +22 -0
  283. package/src/htmlpagedataprocessor.js +67 -0
  284. package/src/index.d.ts +25 -0
  285. package/src/index.js +14 -0
  286. package/src/integrations/codeblock.d.ts +27 -0
  287. package/src/integrations/codeblock.js +107 -0
  288. package/src/integrations/customelement.d.ts +31 -0
  289. package/src/integrations/customelement.js +162 -0
  290. package/src/integrations/dualcontent.d.ts +49 -0
  291. package/src/integrations/dualcontent.js +125 -0
  292. package/src/integrations/heading.d.ts +35 -0
  293. package/src/integrations/heading.js +72 -0
  294. package/src/integrations/image.d.ts +30 -0
  295. package/src/integrations/image.js +195 -0
  296. package/src/integrations/integrationutils.d.ts +15 -0
  297. package/src/integrations/integrationutils.js +21 -0
  298. package/src/integrations/list.d.ts +31 -0
  299. package/src/integrations/list.js +185 -0
  300. package/src/integrations/mediaembed.d.ts +30 -0
  301. package/src/integrations/mediaembed.js +125 -0
  302. package/src/integrations/script.d.ts +30 -0
  303. package/src/integrations/script.js +65 -0
  304. package/src/integrations/style.d.ts +30 -0
  305. package/src/integrations/style.js +65 -0
  306. package/src/integrations/table.d.ts +27 -0
  307. package/src/integrations/table.js +169 -0
  308. package/src/schemadefinitions.d.ts +13 -0
  309. package/src/schemadefinitions.js +964 -0
  310. package/src/utils.d.ts +72 -0
  311. package/src/utils.js +139 -0
  312. package/theme/datafilter.css +56 -0
@@ -0,0 +1,246 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/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 CustomElementSupport from './integrations/customelement.js';
21
+ import { getHtmlAttributeName, modifyGhsAttribute } from './utils.js';
22
+ /**
23
+ * The General HTML Support feature.
24
+ *
25
+ * This is a "glue" plugin which initializes the {@link module:html-support/datafilter~DataFilter data filter} configuration
26
+ * and features integration with the General HTML Support.
27
+ */
28
+ export default class GeneralHtmlSupport extends Plugin {
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get pluginName() {
33
+ return 'GeneralHtmlSupport';
34
+ }
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ static get isOfficialPlugin() {
39
+ return true;
40
+ }
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ static get requires() {
45
+ return [
46
+ DataFilter,
47
+ CodeBlockElementSupport,
48
+ DualContentModelElementSupport,
49
+ HeadingElementSupport,
50
+ ImageElementSupport,
51
+ MediaEmbedElementSupport,
52
+ ScriptElementSupport,
53
+ TableElementSupport,
54
+ StyleElementSupport,
55
+ ListElementSupport,
56
+ CustomElementSupport
57
+ ];
58
+ }
59
+ /**
60
+ * @inheritDoc
61
+ */
62
+ init() {
63
+ const editor = this.editor;
64
+ const dataFilter = editor.plugins.get(DataFilter);
65
+ // Load the allowed empty inline elements' configuration.
66
+ // Note that this modifies DataSchema so must be loaded before registering filtering rules.
67
+ dataFilter.loadAllowedEmptyElementsConfig(editor.config.get('htmlSupport.allowEmpty') || []);
68
+ // Load the filtering configuration.
69
+ dataFilter.loadAllowedConfig(editor.config.get('htmlSupport.allow') || []);
70
+ dataFilter.loadDisallowedConfig(editor.config.get('htmlSupport.disallow') || []);
71
+ }
72
+ /**
73
+ * Returns a GHS model attribute name related to a given view element name.
74
+ *
75
+ * @internal
76
+ * @param viewElementName A view element name.
77
+ */
78
+ getGhsAttributeNameForElement(viewElementName) {
79
+ const dataSchema = this.editor.plugins.get('DataSchema');
80
+ const definitions = Array.from(dataSchema.getDefinitionsForView(viewElementName, false));
81
+ const inlineDefinition = definitions.find(definition => (definition.isInline && !definitions[0].isObject));
82
+ if (inlineDefinition) {
83
+ return inlineDefinition.model;
84
+ }
85
+ return getHtmlAttributeName(viewElementName);
86
+ }
87
+ /**
88
+ * Updates GHS model attribute for a specified view element name, so it includes the given class name.
89
+ *
90
+ * @internal
91
+ * @param viewElementName A view element name.
92
+ * @param className The css class to add.
93
+ * @param selectable The selection or element to update.
94
+ */
95
+ addModelHtmlClass(viewElementName, className, selectable) {
96
+ const model = this.editor.model;
97
+ const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
98
+ model.change(writer => {
99
+ for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
100
+ modifyGhsAttribute(writer, item, ghsAttributeName, 'classes', classes => {
101
+ for (const value of toArray(className)) {
102
+ classes.add(value);
103
+ }
104
+ });
105
+ }
106
+ });
107
+ }
108
+ /**
109
+ * Updates GHS model attribute for a specified view element name, so it does not include the given class name.
110
+ *
111
+ * @internal
112
+ * @param viewElementName A view element name.
113
+ * @param className The css class to remove.
114
+ * @param selectable The selection or element to update.
115
+ */
116
+ removeModelHtmlClass(viewElementName, className, selectable) {
117
+ const model = this.editor.model;
118
+ const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
119
+ model.change(writer => {
120
+ for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
121
+ modifyGhsAttribute(writer, item, ghsAttributeName, 'classes', classes => {
122
+ for (const value of toArray(className)) {
123
+ classes.delete(value);
124
+ }
125
+ });
126
+ }
127
+ });
128
+ }
129
+ /**
130
+ * Updates GHS model attribute for a specified view element name, so it includes the given attribute.
131
+ *
132
+ * @param viewElementName A view element name.
133
+ * @param attributes The object with attributes to set.
134
+ * @param selectable The selection or element to update.
135
+ */
136
+ setModelHtmlAttributes(viewElementName, attributes, selectable) {
137
+ const model = this.editor.model;
138
+ const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
139
+ model.change(writer => {
140
+ for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
141
+ modifyGhsAttribute(writer, item, ghsAttributeName, 'attributes', attributesMap => {
142
+ for (const [key, value] of Object.entries(attributes)) {
143
+ attributesMap.set(key, value);
144
+ }
145
+ });
146
+ }
147
+ });
148
+ }
149
+ /**
150
+ * Updates GHS model attribute for a specified view element name, so it does not include the given attribute.
151
+ *
152
+ * @param viewElementName A view element name.
153
+ * @param attributeName The attribute name (or names) to remove.
154
+ * @param selectable The selection or element to update.
155
+ */
156
+ removeModelHtmlAttributes(viewElementName, attributeName, selectable) {
157
+ const model = this.editor.model;
158
+ const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
159
+ model.change(writer => {
160
+ for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
161
+ modifyGhsAttribute(writer, item, ghsAttributeName, 'attributes', attributesMap => {
162
+ for (const key of toArray(attributeName)) {
163
+ attributesMap.delete(key);
164
+ }
165
+ });
166
+ }
167
+ });
168
+ }
169
+ /**
170
+ * Updates GHS model attribute for a specified view element name, so it includes a given style.
171
+ *
172
+ * @param viewElementName A view element name.
173
+ * @param styles The object with styles to set.
174
+ * @param selectable The selection or element to update.
175
+ */
176
+ setModelHtmlStyles(viewElementName, styles, selectable) {
177
+ const model = this.editor.model;
178
+ const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
179
+ model.change(writer => {
180
+ for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
181
+ modifyGhsAttribute(writer, item, ghsAttributeName, 'styles', stylesMap => {
182
+ for (const [key, value] of Object.entries(styles)) {
183
+ stylesMap.set(key, value);
184
+ }
185
+ });
186
+ }
187
+ });
188
+ }
189
+ /**
190
+ * Updates GHS model attribute for a specified view element name, so it does not include a given style.
191
+ *
192
+ * @param viewElementName A view element name.
193
+ * @param properties The style (or styles list) to remove.
194
+ * @param selectable The selection or element to update.
195
+ */
196
+ removeModelHtmlStyles(viewElementName, properties, selectable) {
197
+ const model = this.editor.model;
198
+ const ghsAttributeName = this.getGhsAttributeNameForElement(viewElementName);
199
+ model.change(writer => {
200
+ for (const item of getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName)) {
201
+ modifyGhsAttribute(writer, item, ghsAttributeName, 'styles', stylesMap => {
202
+ for (const key of toArray(properties)) {
203
+ stylesMap.delete(key);
204
+ }
205
+ });
206
+ }
207
+ });
208
+ }
209
+ }
210
+ /**
211
+ * Returns an iterator over an items in the selectable that accept given GHS attribute.
212
+ */
213
+ function* getItemsToUpdateGhsAttribute(model, selectable, ghsAttributeName) {
214
+ if (!selectable) {
215
+ return;
216
+ }
217
+ if (!(Symbol.iterator in selectable) && selectable.is('documentSelection') && selectable.isCollapsed) {
218
+ if (model.schema.checkAttributeInSelection(selectable, ghsAttributeName)) {
219
+ yield selectable;
220
+ }
221
+ }
222
+ else {
223
+ for (const range of getValidRangesForSelectable(model, selectable, ghsAttributeName)) {
224
+ yield* range.getItems({ shallow: true });
225
+ }
226
+ }
227
+ }
228
+ /**
229
+ * Translates a given selectable to an iterable of ranges.
230
+ */
231
+ function getValidRangesForSelectable(model, selectable, ghsAttributeName) {
232
+ if (!(Symbol.iterator in selectable) &&
233
+ (selectable.is('node') ||
234
+ selectable.is('$text') ||
235
+ selectable.is('$textProxy'))) {
236
+ if (model.schema.checkAttribute(selectable, ghsAttributeName)) {
237
+ return [model.createRangeOn(selectable)];
238
+ }
239
+ else {
240
+ return [];
241
+ }
242
+ }
243
+ else {
244
+ return model.schema.getValidRanges(model.createSelection(selectable).getRanges(), ghsAttributeName);
245
+ }
246
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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 { MatcherObjectPattern } from 'ckeditor5/src/engine.js';
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<MatcherObjectPattern>;
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<MatcherObjectPattern>;
67
+ /**
68
+ * The configuration of allowed empty inline elements that should not be removed.
69
+ *
70
+ * Note that you should also add an appropriate entry to {@link #allow} list.
71
+ *
72
+ * ```ts
73
+ * const htmlSupportConfig.allowEmpty = [ 'i', 'span' ];
74
+ * ```
75
+ */
76
+ allowEmpty?: Array<string>;
77
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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 {};
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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.js';
9
+ import { Plugin } from 'ckeditor5/src/core.js';
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
+ static get isOfficialPlugin(): true;
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ init(): void;
28
+ /**
29
+ * Creates an HTML comment on the specified position and returns its ID.
30
+ *
31
+ * *Note*: If two comments are created at the same position, the second comment will be inserted before the first one.
32
+ *
33
+ * @returns Comment ID. This ID can be later used to e.g. remove the comment from the content.
34
+ */
35
+ createHtmlComment(position: Position, content: string): string;
36
+ /**
37
+ * Removes an HTML comment with the given comment ID.
38
+ *
39
+ * It does nothing and returns `false` if the comment with the given ID does not exist.
40
+ * Otherwise it removes the comment and returns `true`.
41
+ *
42
+ * Note that a comment can be removed also by removing the content around the comment.
43
+ *
44
+ * @param commentID The ID of the comment to be removed.
45
+ * @returns `true` when the comment with the given ID was removed, `false` otherwise.
46
+ */
47
+ removeHtmlComment(commentID: string): boolean;
48
+ /**
49
+ * Gets the HTML comment data for the comment with a given ID.
50
+ *
51
+ * Returns `null` if the comment does not exist.
52
+ */
53
+ getHtmlCommentData(commentID: string): HtmlCommentData | null;
54
+ /**
55
+ * Gets all HTML comments in the given range.
56
+ *
57
+ * By default, it includes comments at the range boundaries.
58
+ *
59
+ * @param range
60
+ * @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
61
+ * @returns HTML comment IDs
62
+ */
63
+ getHtmlCommentsInRange(range: Range, { skipBoundaries }?: {
64
+ skipBoundaries?: boolean | undefined;
65
+ }): Array<string>;
66
+ }
67
+ /**
68
+ * An interface for the HTML comments data.
69
+ *
70
+ * It consists of the {@link module:engine/model/position~Position `position`} and `content`.
71
+ */
72
+ export interface HtmlCommentData {
73
+ position: Position;
74
+ content: string;
75
+ }
@@ -0,0 +1,224 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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.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 default 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
209
+ * @param options.skipBoundaries When set to `true` the range boundaries will be skipped.
210
+ * @returns HTML comment IDs
211
+ */
212
+ getHtmlCommentsInRange(range, { skipBoundaries = false } = {}) {
213
+ const includeBoundaries = !skipBoundaries;
214
+ // Unfortunately, MarkerCollection#getMarkersAtPosition() filters out collapsed markers.
215
+ return Array.from(this.editor.model.markers.getMarkersGroup('$comment'))
216
+ .filter(marker => isCommentMarkerInRange(marker, range))
217
+ .map(marker => marker.name);
218
+ function isCommentMarkerInRange(commentMarker, range) {
219
+ const position = commentMarker.getRange().start;
220
+ return ((position.isAfter(range.start) || (includeBoundaries && position.isEqual(range.start))) &&
221
+ (position.isBefore(range.end) || (includeBoundaries && position.isEqual(range.end))));
222
+ }
223
+ }
224
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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.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 default class HtmlPageDataProcessor extends HtmlDataProcessor {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ toView(data: string): ViewDocumentFragment;
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ toData(viewFragment: ViewDocumentFragment): string;
22
+ }