@ckeditor/ckeditor5-html-support 36.0.1 → 37.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +2 -2
  2. package/build/html-support.js +1 -1
  3. package/ckeditor5-metadata.json +2 -2
  4. package/package.json +42 -36
  5. package/src/augmentation.d.ts +33 -0
  6. package/src/augmentation.js +5 -0
  7. package/src/conversionutils.d.ts +42 -0
  8. package/src/conversionutils.js +57 -77
  9. package/src/converters.d.ts +56 -0
  10. package/src/converters.js +104 -156
  11. package/src/datafilter.d.ts +250 -0
  12. package/src/datafilter.js +566 -782
  13. package/src/dataschema.d.ts +169 -0
  14. package/src/dataschema.js +143 -229
  15. package/src/fullpage.d.ts +21 -0
  16. package/src/fullpage.js +65 -86
  17. package/src/generalhtmlsupport.d.ts +88 -0
  18. package/src/generalhtmlsupport.js +244 -327
  19. package/src/generalhtmlsupportconfig.d.ts +67 -0
  20. package/src/generalhtmlsupportconfig.js +5 -0
  21. package/src/htmlcomment.d.ts +72 -0
  22. package/src/htmlcomment.js +175 -239
  23. package/src/htmlpagedataprocessor.d.ts +22 -0
  24. package/src/htmlpagedataprocessor.js +53 -76
  25. package/src/index.d.ts +25 -0
  26. package/src/index.js +1 -2
  27. package/src/integrations/codeblock.d.ts +22 -0
  28. package/src/integrations/codeblock.js +87 -115
  29. package/src/integrations/customelement.d.ts +25 -0
  30. package/src/integrations/customelement.js +127 -160
  31. package/src/integrations/documentlist.d.ts +26 -0
  32. package/src/integrations/documentlist.js +154 -191
  33. package/src/integrations/dualcontent.d.ts +44 -0
  34. package/src/integrations/dualcontent.js +92 -128
  35. package/src/integrations/heading.d.ts +25 -0
  36. package/src/integrations/heading.js +41 -54
  37. package/src/integrations/image.d.ts +25 -0
  38. package/src/integrations/image.js +154 -212
  39. package/src/integrations/integrationutils.d.ts +15 -0
  40. package/src/integrations/integrationutils.js +21 -0
  41. package/src/integrations/mediaembed.d.ts +25 -0
  42. package/src/integrations/mediaembed.js +101 -147
  43. package/src/integrations/script.d.ts +25 -0
  44. package/src/integrations/script.js +45 -67
  45. package/src/integrations/style.d.ts +25 -0
  46. package/src/integrations/style.js +45 -67
  47. package/src/integrations/table.d.ts +22 -0
  48. package/src/integrations/table.js +113 -160
  49. package/src/schemadefinitions.d.ts +13 -0
  50. package/src/schemadefinitions.js +846 -835
@@ -2,89 +2,66 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module html-support/htmlpagedataprocessor
8
7
  */
9
-
10
8
  import { HtmlDataProcessor, UpcastWriter } from 'ckeditor5/src/engine';
11
-
12
9
  /**
13
10
  * The full page HTML data processor class.
14
11
  * This data processor implementation uses HTML as input and output data.
15
- *
16
- * @implements module:engine/dataprocessor/dataprocessor~DataProcessor
17
12
  */
18
13
  export default class HtmlPageDataProcessor extends HtmlDataProcessor {
19
- /**
20
- * @inheritDoc
21
- */
22
- toView( data ) {
23
- // Ignore content that is not a full page source.
24
- if ( !data.match( /<(?:html|body|head|meta)(?:\s[^>]*)?>/i ) ) {
25
- return super.toView( data );
26
- }
27
-
28
- // Store doctype and xml declaration in a separate properties as they can't be stringified later.
29
- let docType = '';
30
- let xmlDeclaration = '';
31
-
32
- data = data.replace( /<!DOCTYPE[^>]*>/i, match => {
33
- docType = match;
34
-
35
- return '';
36
- } );
37
-
38
- data = data.replace( /<\?xml\s[^?]*\?>/i, match => {
39
- xmlDeclaration = match;
40
-
41
- return '';
42
- } );
43
-
44
- // Convert input HTML data to DOM DocumentFragment.
45
- const domFragment = this._toDom( data );
46
-
47
- // Convert DOM DocumentFragment to view DocumentFragment.
48
- const viewFragment = this.domConverter.domToView( domFragment, { skipComments: this.skipComments } );
49
-
50
- const writer = new UpcastWriter( viewFragment.document );
51
-
52
- // Using the DOM document with body content extracted as a skeleton of the page.
53
- writer.setCustomProperty( '$fullPageDocument', domFragment.ownerDocument.documentElement.outerHTML, viewFragment );
54
-
55
- if ( docType ) {
56
- writer.setCustomProperty( '$fullPageDocType', docType, viewFragment );
57
- }
58
-
59
- if ( xmlDeclaration ) {
60
- writer.setCustomProperty( '$fullPageXmlDeclaration', xmlDeclaration, viewFragment );
61
- }
62
-
63
- return viewFragment;
64
- }
65
-
66
- /**
67
- * @inheritDoc
68
- */
69
- toData( viewFragment ) {
70
- let data = super.toData( viewFragment );
71
-
72
- const page = viewFragment.getCustomProperty( '$fullPageDocument' );
73
- const docType = viewFragment.getCustomProperty( '$fullPageDocType' );
74
- const xmlDeclaration = viewFragment.getCustomProperty( '$fullPageXmlDeclaration' );
75
-
76
- if ( page ) {
77
- data = page.replace( /<\/body\s*>/, data + '$&' );
78
-
79
- if ( docType ) {
80
- data = docType + '\n' + data;
81
- }
82
-
83
- if ( xmlDeclaration ) {
84
- data = xmlDeclaration + '\n' + data;
85
- }
86
- }
87
-
88
- return data;
89
- }
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ toView(data) {
18
+ // Ignore content that is not a full page source.
19
+ if (!data.match(/<(?:html|body|head|meta)(?:\s[^>]*)?>/i)) {
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.replace(/<!DOCTYPE[^>]*>/i, match => {
26
+ docType = match;
27
+ return '';
28
+ });
29
+ data = data.replace(/<\?xml\s[^?]*\?>/i, match => {
30
+ xmlDeclaration = 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 UpcastWriter(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
+ if (docType) {
41
+ writer.setCustomProperty('$fullPageDocType', docType, viewFragment);
42
+ }
43
+ if (xmlDeclaration) {
44
+ writer.setCustomProperty('$fullPageXmlDeclaration', xmlDeclaration, viewFragment);
45
+ }
46
+ return viewFragment;
47
+ }
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ toData(viewFragment) {
52
+ let data = super.toData(viewFragment);
53
+ const page = viewFragment.getCustomProperty('$fullPageDocument');
54
+ const docType = viewFragment.getCustomProperty('$fullPageDocType');
55
+ const xmlDeclaration = viewFragment.getCustomProperty('$fullPageXmlDeclaration');
56
+ if (page) {
57
+ data = page.replace(/<\/body\s*>/, data + '$&');
58
+ if (docType) {
59
+ data = docType + '\n' + data;
60
+ }
61
+ if (xmlDeclaration) {
62
+ data = xmlDeclaration + '\n' + data;
63
+ }
64
+ }
65
+ return data;
66
+ }
90
67
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module html-support
7
+ */
8
+ export { default as GeneralHtmlSupport } from './generalhtmlsupport';
9
+ export { default as DataFilter } from './datafilter';
10
+ export { default as DataSchema } from './dataschema';
11
+ export { default as HtmlComment } from './htmlcomment';
12
+ export { default as FullPage } from './fullpage';
13
+ export { default as HtmlPageDataProcessor } from './htmlpagedataprocessor';
14
+ export type { GeneralHtmlSupportConfig } from './generalhtmlsupportconfig';
15
+ export type { default as CodeBlockElementSupport } from './integrations/codeblock';
16
+ export type { default as CustomElementSupport } from './integrations/customelement';
17
+ export type { default as DocumentListElementSupport } from './integrations/documentlist';
18
+ export type { default as DualContentModelElementSupport } from './integrations/dualcontent';
19
+ export type { default as HeadingElementSupport } from './integrations/heading';
20
+ export type { default as ImageElementSupport } from './integrations/image';
21
+ export type { default as MediaEmbedElementSupport } from './integrations/mediaembed';
22
+ export type { default as ScriptElementSupport } from './integrations/script';
23
+ export type { default as StyleElementSupport } from './integrations/style';
24
+ export type { default as TableElementSupport } from './integrations/table';
25
+ import './augmentation';
package/src/index.js CHANGED
@@ -2,14 +2,13 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module html-support
8
7
  */
9
-
10
8
  export { default as GeneralHtmlSupport } from './generalhtmlsupport';
11
9
  export { default as DataFilter } from './datafilter';
12
10
  export { default as DataSchema } from './dataschema';
13
11
  export { default as HtmlComment } from './htmlcomment';
14
12
  export { default as FullPage } from './fullpage';
15
13
  export { default as HtmlPageDataProcessor } from './htmlpagedataprocessor';
14
+ import './augmentation';
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
6
+ /**
7
+ * Provides the General HTML Support integration with {@link module:code-block/codeblock~CodeBlock Code Block} feature.
8
+ */
9
+ export default class CodeBlockElementSupport extends Plugin {
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ static get requires(): PluginDependencies;
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get pluginName(): 'CodeBlockElementSupport';
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ init(): void;
22
+ }
@@ -2,128 +2,100 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
- /**
7
- * @module html-support/integrations/codeblock
8
- */
9
-
10
5
  import { Plugin } from 'ckeditor5/src/core';
11
- import { updateViewAttributes } from '../conversionutils.js';
12
-
6
+ import { updateViewAttributes } from '../conversionutils';
13
7
  import DataFilter from '../datafilter';
14
-
15
8
  /**
16
9
  * Provides the General HTML Support integration with {@link module:code-block/codeblock~CodeBlock Code Block} feature.
17
- *
18
- * @extends module:core/plugin~Plugin
19
10
  */
20
11
  export default class CodeBlockElementSupport extends Plugin {
21
- /**
22
- * @inheritDoc
23
- */
24
- static get requires() {
25
- return [ DataFilter ];
26
- }
27
-
28
- /**
29
- * @inheritDoc
30
- */
31
- static get pluginName() {
32
- return 'CodeBlockElementSupport';
33
- }
34
-
35
- /**
36
- * @inheritDoc
37
- */
38
- init() {
39
- if ( !this.editor.plugins.has( 'CodeBlockEditing' ) ) {
40
- return;
41
- }
42
-
43
- const dataFilter = this.editor.plugins.get( DataFilter );
44
-
45
- dataFilter.on( 'register:pre', ( evt, definition ) => {
46
- if ( definition.model !== 'codeBlock' ) {
47
- return;
48
- }
49
-
50
- const editor = this.editor;
51
- const schema = editor.model.schema;
52
- const conversion = editor.conversion;
53
-
54
- // Extend codeBlock to allow attributes required by attribute filtration.
55
- schema.extend( 'codeBlock', {
56
- allowAttributes: [ 'htmlAttributes', 'htmlContentAttributes' ]
57
- } );
58
-
59
- conversion.for( 'upcast' ).add( viewToModelCodeBlockAttributeConverter( dataFilter ) );
60
- conversion.for( 'downcast' ).add( modelToViewCodeBlockAttributeConverter() );
61
-
62
- evt.stop();
63
- } );
64
- }
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
+ init() {
28
+ if (!this.editor.plugins.has('CodeBlockEditing')) {
29
+ return;
30
+ }
31
+ const dataFilter = this.editor.plugins.get(DataFilter);
32
+ dataFilter.on('register:pre', (evt, definition) => {
33
+ if (definition.model !== 'codeBlock') {
34
+ return;
35
+ }
36
+ const editor = this.editor;
37
+ const schema = editor.model.schema;
38
+ const conversion = editor.conversion;
39
+ // Extend codeBlock to allow attributes required by attribute filtration.
40
+ schema.extend('codeBlock', {
41
+ allowAttributes: ['htmlAttributes', 'htmlContentAttributes']
42
+ });
43
+ conversion.for('upcast').add(viewToModelCodeBlockAttributeConverter(dataFilter));
44
+ conversion.for('downcast').add(modelToViewCodeBlockAttributeConverter());
45
+ evt.stop();
46
+ });
47
+ }
65
48
  }
66
-
67
- // View-to-model conversion helper preserving allowed attributes on {@link module:code-block/codeblock~CodeBlock Code Block}
68
- // feature model element.
69
- //
70
- // Attributes are preserved as a value of `htmlAttributes` model attribute.
71
- //
72
- // @private
73
- // @param {module:html-support/datafilter~DataFilter} dataFilter
74
- // @returns {Function} Returns a conversion callback.
75
- function viewToModelCodeBlockAttributeConverter( dataFilter ) {
76
- return dispatcher => {
77
- dispatcher.on( 'element:code', ( evt, data, conversionApi ) => {
78
- const viewCodeElement = data.viewItem;
79
- const viewPreElement = viewCodeElement.parent;
80
-
81
- if ( !viewPreElement || !viewPreElement.is( 'element', 'pre' ) ) {
82
- return;
83
- }
84
-
85
- preserveElementAttributes( viewPreElement, 'htmlAttributes' );
86
- preserveElementAttributes( viewCodeElement, 'htmlContentAttributes' );
87
-
88
- function preserveElementAttributes( viewElement, attributeName ) {
89
- const viewAttributes = dataFilter.processViewAttributes( viewElement, conversionApi );
90
-
91
- if ( viewAttributes ) {
92
- conversionApi.writer.setAttribute( attributeName, viewAttributes, data.modelRange );
93
- }
94
- }
95
- }, { priority: 'low' } );
96
- };
49
+ /**
50
+ * View-to-model conversion helper preserving allowed attributes on {@link module:code-block/codeblock~CodeBlock Code Block}
51
+ * feature model element.
52
+ *
53
+ * Attributes are preserved as a value of `htmlAttributes` model attribute.
54
+ * @param dataFilter
55
+ * @returns Returns a conversion callback.
56
+ */
57
+ function viewToModelCodeBlockAttributeConverter(dataFilter) {
58
+ return (dispatcher) => {
59
+ dispatcher.on('element:code', (evt, data, conversionApi) => {
60
+ const viewCodeElement = data.viewItem;
61
+ const viewPreElement = viewCodeElement.parent;
62
+ if (!viewPreElement || !viewPreElement.is('element', 'pre')) {
63
+ return;
64
+ }
65
+ preserveElementAttributes(viewPreElement, 'htmlAttributes');
66
+ preserveElementAttributes(viewCodeElement, 'htmlContentAttributes');
67
+ function preserveElementAttributes(viewElement, attributeName) {
68
+ const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
69
+ if (viewAttributes) {
70
+ conversionApi.writer.setAttribute(attributeName, viewAttributes, data.modelRange);
71
+ }
72
+ }
73
+ }, { priority: 'low' });
74
+ };
97
75
  }
98
-
99
- // Model-to-view conversion helper applying attributes from {@link module:code-block/codeblock~CodeBlock Code Block}
100
- // feature model element.
101
- //
102
- // @private
103
- // @returns {Function} Returns a conversion callback.
76
+ /**
77
+ * Model-to-view conversion helper applying attributes from {@link module:code-block/codeblock~CodeBlock Code Block}
78
+ * feature model element.
79
+ * @returns Returns a conversion callback.
80
+ */
104
81
  function modelToViewCodeBlockAttributeConverter() {
105
- return dispatcher => {
106
- dispatcher.on( 'attribute:htmlAttributes:codeBlock', ( evt, data, conversionApi ) => {
107
- if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
108
- return;
109
- }
110
-
111
- const { attributeOldValue, attributeNewValue } = data;
112
- const viewCodeElement = conversionApi.mapper.toViewElement( data.item );
113
- const viewPreElement = viewCodeElement.parent;
114
-
115
- updateViewAttributes( conversionApi.writer, attributeOldValue, attributeNewValue, viewPreElement );
116
- } );
117
-
118
- dispatcher.on( 'attribute:htmlContentAttributes:codeBlock', ( evt, data, conversionApi ) => {
119
- if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
120
- return;
121
- }
122
-
123
- const { attributeOldValue, attributeNewValue } = data;
124
- const viewCodeElement = conversionApi.mapper.toViewElement( data.item );
125
-
126
- updateViewAttributes( conversionApi.writer, attributeOldValue, attributeNewValue, viewCodeElement );
127
- } );
128
- };
82
+ return (dispatcher) => {
83
+ dispatcher.on('attribute:htmlAttributes:codeBlock', (evt, data, conversionApi) => {
84
+ if (!conversionApi.consumable.consume(data.item, evt.name)) {
85
+ return;
86
+ }
87
+ const { attributeOldValue, attributeNewValue } = data;
88
+ const viewCodeElement = conversionApi.mapper.toViewElement(data.item);
89
+ const viewPreElement = viewCodeElement.parent;
90
+ updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewPreElement);
91
+ });
92
+ dispatcher.on('attribute:htmlContentAttributes:codeBlock', (evt, data, conversionApi) => {
93
+ if (!conversionApi.consumable.consume(data.item, evt.name)) {
94
+ return;
95
+ }
96
+ const { attributeOldValue, attributeNewValue } = data;
97
+ const viewCodeElement = conversionApi.mapper.toViewElement(data.item);
98
+ updateViewAttributes(conversionApi.writer, attributeOldValue, attributeNewValue, viewCodeElement);
99
+ });
100
+ };
129
101
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module html-support/integrations/customelement
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
11
+ */
12
+ export default class CustomElementSupport extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get requires(): PluginDependencies;
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName(): 'CustomElementSupport';
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ init(): void;
25
+ }