@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,107 +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 { updateViewAttributes } from '../utils.js';
7
- import { DataFilter } from '../datafilter.js';
8
- /**
9
- * Provides the General HTML Support integration with {@link module:code-block/codeblock~CodeBlock Code Block} feature.
10
- */
11
- export class CodeBlockElementSupport extends Plugin {
12
- /**
13
- * @inheritDoc
14
- */
15
- static get requires() {
16
- return [DataFilter];
17
- }
18
- /**
19
- * @inheritDoc
20
- */
21
- static get pluginName() {
22
- return 'CodeBlockElementSupport';
23
- }
24
- /**
25
- * @inheritDoc
26
- */
27
- static get isOfficialPlugin() {
28
- return true;
29
- }
30
- /**
31
- * @inheritDoc
32
- */
33
- init() {
34
- if (!this.editor.plugins.has('CodeBlockEditing')) {
35
- return;
36
- }
37
- const dataFilter = this.editor.plugins.get(DataFilter);
38
- dataFilter.on('register:pre', (evt, definition) => {
39
- if (definition.model !== 'codeBlock') {
40
- return;
41
- }
42
- const editor = this.editor;
43
- const schema = editor.model.schema;
44
- const conversion = editor.conversion;
45
- // Extend codeBlock to allow attributes required by attribute filtration.
46
- schema.extend('codeBlock', {
47
- allowAttributes: ['htmlPreAttributes', 'htmlContentAttributes']
48
- });
49
- conversion.for('upcast').add(viewToModelCodeBlockAttributeConverter(dataFilter));
50
- conversion.for('downcast').add(modelToViewCodeBlockAttributeConverter());
51
- evt.stop();
52
- });
53
- }
54
- }
55
- /**
56
- * View-to-model conversion helper preserving allowed attributes on {@link module:code-block/codeblock~CodeBlock Code Block}
57
- * feature model element.
58
- *
59
- * Attributes are preserved as a value of `html*Attributes` model attribute.
60
- * @param dataFilter
61
- * @returns Returns a conversion callback.
62
- */
63
- function viewToModelCodeBlockAttributeConverter(dataFilter) {
64
- return (dispatcher) => {
65
- dispatcher.on('element:code', (evt, data, conversionApi) => {
66
- const viewCodeElement = data.viewItem;
67
- const viewPreElement = viewCodeElement.parent;
68
- if (!viewPreElement || !viewPreElement.is('element', 'pre')) {
69
- return;
70
- }
71
- preserveElementAttributes(viewPreElement, 'htmlPreAttributes');
72
- preserveElementAttributes(viewCodeElement, 'htmlContentAttributes');
73
- function preserveElementAttributes(viewElement, attributeName) {
74
- const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
75
- if (viewAttributes) {
76
- conversionApi.writer.setAttribute(attributeName, viewAttributes, data.modelRange);
77
- }
78
- }
79
- }, { priority: 'low' });
80
- };
81
- }
82
- /**
83
- * Model-to-view conversion helper applying attributes from {@link module:code-block/codeblock~CodeBlock Code Block}
84
- * feature model element.
85
- * @returns Returns a conversion callback.
86
- */
87
- function modelToViewCodeBlockAttributeConverter() {
88
- return (dispatcher) => {
89
- dispatcher.on('attribute:htmlPreAttributes:codeBlock', (evt, data, conversionApi) => {
90
- if (!conversionApi.consumable.consume(data.item, evt.name)) {
91
- return;
92
- }
93
- const { attributeOldValue, attributeNewValue } = data;
94
- const viewCodeElement = conversionApi.mapper.toViewElement(data.item);
95
- const viewPreElement = viewCodeElement.parent;
96
- updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewPreElement);
97
- });
98
- dispatcher.on('attribute:htmlContentAttributes:codeBlock', (evt, data, conversionApi) => {
99
- if (!conversionApi.consumable.consume(data.item, evt.name)) {
100
- return;
101
- }
102
- const { attributeOldValue, attributeNewValue } = data;
103
- const viewCodeElement = conversionApi.mapper.toViewElement(data.item);
104
- updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewCodeElement);
105
- });
106
- };
107
- }
@@ -1,166 +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/integrations/customelement
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { ViewUpcastWriter } from 'ckeditor5/src/engine.js';
10
- import { DataSchema } from '../dataschema.js';
11
- import { DataFilter } from '../datafilter.js';
12
- import { setViewAttributes } from '../utils.js';
13
- /**
14
- * Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
15
- */
16
- export class CustomElementSupport extends Plugin {
17
- /**
18
- * @inheritDoc
19
- */
20
- static get requires() {
21
- return [DataFilter, DataSchema];
22
- }
23
- /**
24
- * @inheritDoc
25
- */
26
- static get pluginName() {
27
- return 'CustomElementSupport';
28
- }
29
- /**
30
- * @inheritDoc
31
- */
32
- static get isOfficialPlugin() {
33
- return true;
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- init() {
39
- const dataFilter = this.editor.plugins.get(DataFilter);
40
- const dataSchema = this.editor.plugins.get(DataSchema);
41
- dataFilter.on('register:$customElement', (evt, definition) => {
42
- evt.stop();
43
- const editor = this.editor;
44
- const schema = editor.model.schema;
45
- const conversion = editor.conversion;
46
- const unsafeElements = editor.editing.view.domConverter.unsafeElements;
47
- const preLikeElements = editor.data.htmlProcessor.domConverter.preElements;
48
- schema.register(definition.model, definition.modelSchema);
49
- schema.extend(definition.model, {
50
- allowAttributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent'],
51
- isContent: true
52
- });
53
- // For the `<template>` element we use only raw-content because DOM API exposes its content
54
- // only as a document fragment in the `content` property (or innerHTML).
55
- editor.data.htmlProcessor.domConverter.registerRawContentMatcher({ name: 'template' });
56
- // Being executed on the low priority, it will catch all elements that were not caught by other converters.
57
- conversion.for('upcast').elementToElement({
58
- view: /.*/,
59
- model: (viewElement, conversionApi) => {
60
- // Do not try to convert $comment fake element.
61
- if (viewElement.name == '$comment') {
62
- return null;
63
- }
64
- // It is ignored intentionally because CI runs on latest Chrome.
65
- /* istanbul ignore next -- @preserve */
66
- if (!isValidElementName(viewElement.name)) {
67
- return null;
68
- }
69
- // Allow for fallback only if this element is not defined in data schema to make sure
70
- // that this will handle only custom elements not registered in the data schema.
71
- if (dataSchema.getDefinitionsForView(viewElement.name).size) {
72
- return null;
73
- }
74
- // Make sure that this element will not render in the editing view.
75
- if (!unsafeElements.includes(viewElement.name)) {
76
- unsafeElements.push(viewElement.name);
77
- }
78
- // Make sure that whitespaces will not be trimmed or replaced by nbsps while stringify content.
79
- if (!preLikeElements.includes(viewElement.name)) {
80
- preLikeElements.push(viewElement.name);
81
- }
82
- const modelElement = conversionApi.writer.createElement(definition.model, {
83
- htmlElementName: viewElement.name
84
- });
85
- const htmlAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
86
- if (htmlAttributes) {
87
- conversionApi.writer.setAttribute('htmlCustomElementAttributes', htmlAttributes, modelElement);
88
- }
89
- let htmlContent;
90
- // For the `<template>` element we use only raw-content because DOM API exposes its content
91
- // only as a document fragment in the `content` property.
92
- if (viewElement.is('element', 'template') && viewElement.getCustomProperty('$rawContent')) {
93
- htmlContent = viewElement.getCustomProperty('$rawContent');
94
- }
95
- else {
96
- // Store the whole element in the attribute so that ViewDomConverter
97
- // will be able to use the pre like element context.
98
- const viewWriter = new ViewUpcastWriter(viewElement.document);
99
- const documentFragment = viewWriter.createDocumentFragment(viewElement);
100
- const domFragment = editor.data.htmlProcessor.domConverter.viewToDom(documentFragment);
101
- const domElement = domFragment.firstChild;
102
- while (domElement.firstChild) {
103
- domFragment.appendChild(domElement.firstChild);
104
- }
105
- domElement.remove();
106
- htmlContent = editor.data.htmlProcessor.htmlWriter.getHtml(domFragment);
107
- }
108
- conversionApi.writer.setAttribute('htmlContent', htmlContent, modelElement);
109
- // Consume the content of the element.
110
- for (const { item } of editor.editing.view.createRangeIn(viewElement)) {
111
- conversionApi.consumable.consume(item, { name: true });
112
- }
113
- return modelElement;
114
- },
115
- converterPriority: 'low'
116
- });
117
- // Because this element is unsafe (DomConverter#unsafeElements), it will render as a transparent <span> but it must
118
- // be rendered anyway for the mapping between the model and the view to exist.
119
- conversion.for('editingDowncast').elementToElement({
120
- model: {
121
- name: definition.model,
122
- attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
123
- },
124
- view: (modelElement, { writer }) => {
125
- const viewName = modelElement.getAttribute('htmlElementName');
126
- const viewElement = writer.createRawElement(viewName);
127
- if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
128
- setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
129
- }
130
- return viewElement;
131
- }
132
- });
133
- conversion.for('dataDowncast').elementToElement({
134
- model: {
135
- name: definition.model,
136
- attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
137
- },
138
- view: (modelElement, { writer }) => {
139
- const viewName = modelElement.getAttribute('htmlElementName');
140
- const htmlContent = modelElement.getAttribute('htmlContent');
141
- const viewElement = writer.createRawElement(viewName, null, (domElement, domConverter) => {
142
- domConverter.setContentOf(domElement, htmlContent);
143
- });
144
- if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
145
- setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
146
- }
147
- return viewElement;
148
- }
149
- });
150
- });
151
- }
152
- }
153
- /**
154
- * Returns true if name is valid for a DOM element name.
155
- */
156
- function isValidElementName(name) {
157
- try {
158
- document.createElement(name);
159
- }
160
- catch {
161
- // It is ignored intentionally because CI runs on latest Chrome.
162
- /* istanbul ignore next -- @preserve */
163
- return false;
164
- }
165
- return true;
166
- }
@@ -1,126 +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 { priorities } from 'ckeditor5/src/utils.js';
7
- import { modelToViewBlockAttributeConverter, viewToModelBlockAttributeConverter } from '../converters.js';
8
- import { DataFilter } from '../datafilter.js';
9
- import { getHtmlAttributeName } from '../utils.js';
10
- /**
11
- * Provides the General HTML Support integration for elements which can behave like sectioning element (e.g. article) or
12
- * element accepting only inline content (e.g. paragraph).
13
- *
14
- * The distinction between this two content models is important for choosing correct schema model and proper content conversion.
15
- * As an example, it ensures that:
16
- *
17
- * * children elements paragraphing is enabled for sectioning elements only,
18
- * * element and its content can be correctly handled by editing view (splitting and merging elements),
19
- * * model element HTML is semantically correct and easier to work with.
20
- *
21
- * If element contains any block element, it will be treated as a sectioning element and registered using
22
- * {@link module:html-support/dataschema~HtmlSupportDataSchemaDefinition#model} and
23
- * {@link module:html-support/dataschema~HtmlSupportDataSchemaDefinition#modelSchema} in editor schema.
24
- * Otherwise, it will be registered under
25
- * {@link module:html-support/dataschema~HtmlSupportDataSchemaBlockElementDefinition#paragraphLikeModel} model
26
- * name with model schema accepting only inline content (inheriting from `$block`).
27
- */
28
- export class DualContentModelElementSupport extends Plugin {
29
- /**
30
- * @inheritDoc
31
- */
32
- static get requires() {
33
- return [DataFilter];
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- static get pluginName() {
39
- return 'DualContentModelElementSupport';
40
- }
41
- /**
42
- * @inheritDoc
43
- */
44
- static get isOfficialPlugin() {
45
- return true;
46
- }
47
- /**
48
- * @inheritDoc
49
- */
50
- init() {
51
- const dataFilter = this.editor.plugins.get(DataFilter);
52
- dataFilter.on('register', (evt, definition) => {
53
- const blockDefinition = definition;
54
- const editor = this.editor;
55
- const schema = editor.model.schema;
56
- const conversion = editor.conversion;
57
- if (!blockDefinition.paragraphLikeModel) {
58
- return;
59
- }
60
- // Can only apply to newly registered features.
61
- if (schema.isRegistered(blockDefinition.model) || schema.isRegistered(blockDefinition.paragraphLikeModel)) {
62
- return;
63
- }
64
- const paragraphLikeModelDefinition = {
65
- model: blockDefinition.paragraphLikeModel,
66
- view: blockDefinition.view
67
- };
68
- schema.register(blockDefinition.model, blockDefinition.modelSchema);
69
- schema.register(paragraphLikeModelDefinition.model, {
70
- inheritAllFrom: '$block'
71
- });
72
- conversion.for('upcast').elementToElement({
73
- view: blockDefinition.view,
74
- model: (viewElement, { writer }) => {
75
- if (this._hasBlockContent(viewElement)) {
76
- return writer.createElement(blockDefinition.model);
77
- }
78
- return writer.createElement(paragraphLikeModelDefinition.model);
79
- },
80
- // With a `low` priority, `paragraph` plugin auto-paragraphing mechanism is executed. Make sure
81
- // this listener is called before it. If not, some elements will be transformed into a paragraph.
82
- converterPriority: priorities.low + 0.5
83
- });
84
- conversion.for('downcast').elementToElement({
85
- view: blockDefinition.view,
86
- model: blockDefinition.model
87
- });
88
- this._addAttributeConversion(blockDefinition);
89
- conversion.for('downcast').elementToElement({
90
- view: paragraphLikeModelDefinition.view,
91
- model: paragraphLikeModelDefinition.model
92
- });
93
- this._addAttributeConversion(paragraphLikeModelDefinition);
94
- evt.stop();
95
- });
96
- }
97
- /**
98
- * Checks whether the given view element includes any other block element.
99
- */
100
- _hasBlockContent(viewElement) {
101
- const view = this.editor.editing.view;
102
- const blockElements = view.domConverter.blockElements;
103
- // Traversing the viewElement subtree looking for block elements.
104
- // Especially for the cases like <div><a href="#"><p>foo</p></a></div>.
105
- // https://github.com/ckeditor/ckeditor5/issues/11513
106
- for (const viewItem of view.createRangeIn(viewElement).getItems()) {
107
- if (viewItem.is('element') && blockElements.includes(viewItem.name)) {
108
- return true;
109
- }
110
- }
111
- return false;
112
- }
113
- /**
114
- * Adds attribute filtering conversion for the given data schema.
115
- */
116
- _addAttributeConversion(definition) {
117
- const editor = this.editor;
118
- const conversion = editor.conversion;
119
- const dataFilter = editor.plugins.get(DataFilter);
120
- editor.model.schema.extend(definition.model, {
121
- allowAttributes: getHtmlAttributeName(definition.view)
122
- });
123
- conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, dataFilter));
124
- conversion.for('downcast').add(modelToViewBlockAttributeConverter(definition));
125
- }
126
- }
@@ -1,72 +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/integrations/heading
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { Enter } from 'ckeditor5/src/enter.js';
10
- import { DataSchema } from '../dataschema.js';
11
- /**
12
- * Provides the General HTML Support integration with {@link module:heading/heading~Heading Heading} feature.
13
- */
14
- export class HeadingElementSupport extends Plugin {
15
- /**
16
- * @inheritDoc
17
- */
18
- static get requires() {
19
- return [DataSchema, Enter];
20
- }
21
- /**
22
- * @inheritDoc
23
- */
24
- static get pluginName() {
25
- return 'HeadingElementSupport';
26
- }
27
- /**
28
- * @inheritDoc
29
- */
30
- static get isOfficialPlugin() {
31
- return true;
32
- }
33
- /**
34
- * @inheritDoc
35
- */
36
- init() {
37
- const editor = this.editor;
38
- if (!editor.plugins.has('HeadingEditing')) {
39
- return;
40
- }
41
- const options = editor.config.get('heading.options');
42
- this.registerHeadingElements(editor, options);
43
- }
44
- /**
45
- * Registers all elements supported by HeadingEditing to enable custom attributes for those elements.
46
- */
47
- registerHeadingElements(editor, options) {
48
- const dataSchema = editor.plugins.get(DataSchema);
49
- const headerModels = [];
50
- for (const option of options) {
51
- if ('model' in option && 'view' in option) {
52
- dataSchema.registerBlockElement({
53
- view: option.view,
54
- model: option.model
55
- });
56
- headerModels.push(option.model);
57
- }
58
- }
59
- dataSchema.extendBlockElement({
60
- model: 'htmlHgroup',
61
- modelSchema: {
62
- allowChildren: headerModels
63
- }
64
- });
65
- dataSchema.extendBlockElement({
66
- model: 'htmlSummary',
67
- modelSchema: {
68
- allowChildren: headerModels
69
- }
70
- });
71
- }
72
- }
@@ -1,80 +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/integrations/horizontalline
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { DataFilter } from '../datafilter.js';
10
- import { updateViewAttributes } from '../utils.js';
11
- import { getDescendantElement } from './integrationutils.js';
12
- import { viewToModelBlockAttributeConverter } from '../converters.js';
13
- /**
14
- * Provides the General HTML Support integration with the {@link module:horizontal-line/horizontalline~HorizontalLine} feature.
15
- */
16
- export class HorizontalLineElementSupport extends Plugin {
17
- /**
18
- * @inheritDoc
19
- */
20
- static get requires() {
21
- return [DataFilter];
22
- }
23
- /**
24
- * @inheritDoc
25
- */
26
- static get pluginName() {
27
- return 'HorizontalLineElementSupport';
28
- }
29
- /**
30
- * @inheritDoc
31
- */
32
- static get isOfficialPlugin() {
33
- return true;
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- init() {
39
- const editor = this.editor;
40
- if (!editor.plugins.has('HorizontalLineEditing')) {
41
- return;
42
- }
43
- const schema = editor.model.schema;
44
- const conversion = editor.conversion;
45
- const dataFilter = editor.plugins.get(DataFilter);
46
- dataFilter.on('register:hr', (evt, definition) => {
47
- if (definition.model !== 'horizontalLine') {
48
- return;
49
- }
50
- schema.extend('horizontalLine', {
51
- allowAttributes: ['htmlHrAttributes']
52
- });
53
- conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, dataFilter));
54
- conversion.for('downcast').add(modelToViewHorizontalLineAttributeConverter());
55
- evt.stop();
56
- });
57
- }
58
- }
59
- /**
60
- * A model-to-view conversion helper applying attributes from the
61
- * {@link module:horizontal-line/horizontalline~HorizontalLine HorizontalLine} feature.
62
- *
63
- * @returns Returns a conversion callback.
64
- */
65
- function modelToViewHorizontalLineAttributeConverter() {
66
- return (dispatcher) => {
67
- dispatcher.on('attribute:htmlHrAttributes:horizontalLine', (evt, data, conversionApi) => {
68
- if (!conversionApi.consumable.test(data.item, evt.name)) {
69
- return;
70
- }
71
- const { attributeOldValue, attributeNewValue } = data;
72
- const containerElement = conversionApi.mapper.toViewElement(data.item);
73
- const viewElement = getDescendantElement(conversionApi.writer, containerElement, 'hr');
74
- if (viewElement) {
75
- updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewElement);
76
- conversionApi.consumable.consume(data.item, evt.name);
77
- }
78
- }, { priority: 'low' });
79
- };
80
- }
@@ -1,76 +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 { DataFilter } from '../datafilter.js';
7
- /**
8
- * Provides the General HTML Support integration for `iframe` elements with a mandatory sandbox attribute.
9
- */
10
- export class IframeElementSupport extends Plugin {
11
- /**
12
- * @inheritDoc
13
- */
14
- static get requires() {
15
- return [DataFilter];
16
- }
17
- /**
18
- * @inheritDoc
19
- */
20
- static get pluginName() {
21
- return 'IframeElementSupport';
22
- }
23
- /**
24
- * @inheritDoc
25
- */
26
- static get isOfficialPlugin() {
27
- return true;
28
- }
29
- /**
30
- * @inheritDoc
31
- */
32
- init() {
33
- this.editor.config.define('htmlSupport.htmlIframeSandbox', true);
34
- this._setupSandboxConversion();
35
- }
36
- /**
37
- * Sets up the conversion to enforce the sandbox attribute on `iframe` elements.
38
- */
39
- _setupSandboxConversion() {
40
- const { plugins, config, conversion } = this.editor;
41
- const dataFilter = plugins.get(DataFilter);
42
- const iframeSandboxConfig = config.get('htmlSupport.htmlIframeSandbox');
43
- if (iframeSandboxConfig === false) {
44
- return;
45
- }
46
- const allowedSandboxFlags = Array.isArray(iframeSandboxConfig) ? Array.from(iframeSandboxConfig) : [];
47
- dataFilter.on('register:iframe', (_, definition) => {
48
- conversion.for('editingDowncast').add((dispatcher) => {
49
- dispatcher.on(`insert:${definition.model}`, (_, data, conversionApi) => {
50
- const { mapper, writer } = conversionApi;
51
- const viewElement = mapper.toViewElement(data.item);
52
- for (const { item } of writer.createRangeOn(viewElement)) {
53
- if (!item.is('element', 'iframe')) {
54
- continue;
55
- }
56
- if (item.hasAttribute('sandbox')) {
57
- // If there is an existing sandbox attribute, read and filter out disallowed values.
58
- const sandboxValues = new Set();
59
- const existingSandbox = item.getAttribute('sandbox');
60
- for (const value of existingSandbox.trim().split(/\s+/)) {
61
- if (allowedSandboxFlags.includes(value)) {
62
- sandboxValues.add(value);
63
- }
64
- }
65
- writer.setAttribute('sandbox', Array.from(sandboxValues).join(' '), item);
66
- }
67
- else {
68
- // If there was no existing sandbox attribute, just use the configured one.
69
- writer.setAttribute('sandbox', allowedSandboxFlags.join(' '), item);
70
- }
71
- }
72
- }, { priority: 'lowest' });
73
- });
74
- });
75
- }
76
- }