@ckeditor/ckeditor5-html-support 36.0.0 → 37.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.
- package/build/html-support.js +1 -1
- package/package.json +42 -36
- package/src/conversionutils.d.ts +42 -0
- package/src/conversionutils.js +57 -77
- package/src/converters.d.ts +56 -0
- package/src/converters.js +104 -156
- package/src/datafilter.d.ts +255 -0
- package/src/datafilter.js +566 -782
- package/src/dataschema.d.ts +174 -0
- package/src/dataschema.js +143 -229
- package/src/fullpage.d.ts +26 -0
- package/src/fullpage.js +65 -86
- package/src/generalhtmlsupport.d.ts +93 -0
- package/src/generalhtmlsupport.js +244 -327
- package/src/generalhtmlsupportconfig.d.ts +76 -0
- package/src/generalhtmlsupportconfig.js +5 -0
- package/src/htmlcomment.d.ts +77 -0
- package/src/htmlcomment.js +175 -239
- package/src/htmlpagedataprocessor.d.ts +22 -0
- package/src/htmlpagedataprocessor.js +53 -76
- package/src/index.d.ts +13 -0
- package/src/index.js +0 -2
- package/src/integrations/codeblock.d.ts +27 -0
- package/src/integrations/codeblock.js +87 -115
- package/src/integrations/customelement.d.ts +30 -0
- package/src/integrations/customelement.js +127 -160
- package/src/integrations/documentlist.d.ts +31 -0
- package/src/integrations/documentlist.js +154 -191
- package/src/integrations/dualcontent.d.ts +49 -0
- package/src/integrations/dualcontent.js +92 -128
- package/src/integrations/heading.d.ts +30 -0
- package/src/integrations/heading.js +41 -54
- package/src/integrations/image.d.ts +30 -0
- package/src/integrations/image.js +154 -212
- package/src/integrations/integrationutils.d.ts +15 -0
- package/src/integrations/integrationutils.js +21 -0
- package/src/integrations/mediaembed.d.ts +30 -0
- package/src/integrations/mediaembed.js +101 -147
- package/src/integrations/script.d.ts +30 -0
- package/src/integrations/script.js +45 -67
- package/src/integrations/style.d.ts +30 -0
- package/src/integrations/style.js +45 -67
- package/src/integrations/table.d.ts +27 -0
- package/src/integrations/table.js +113 -160
- package/src/schemadefinitions.d.ts +13 -0
- 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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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,13 @@
|
|
|
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';
|
package/src/index.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
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';
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
23
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
24
|
+
interface PluginsMap {
|
|
25
|
+
[CodeBlockElementSupport.pluginName]: CodeBlockElementSupport;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -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
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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,30 @@
|
|
|
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
|
+
}
|
|
26
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
27
|
+
interface PluginsMap {
|
|
28
|
+
[CustomElementSupport.pluginName]: CustomElementSupport;
|
|
29
|
+
}
|
|
30
|
+
}
|