@ckeditor/ckeditor5-html-support 40.0.0 → 40.1.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/LICENSE.md +4 -4
- package/build/html-support.js +1 -1
- package/package.json +2 -2
- package/src/augmentation.d.ts +33 -33
- package/src/augmentation.js +5 -5
- package/src/converters.d.ts +60 -60
- package/src/converters.js +180 -180
- package/src/datafilter.d.ts +304 -304
- package/src/datafilter.js +720 -720
- package/src/dataschema.d.ts +183 -183
- package/src/dataschema.js +196 -196
- package/src/fullpage.d.ts +21 -21
- package/src/fullpage.js +80 -80
- package/src/generalhtmlsupport.d.ts +98 -98
- package/src/generalhtmlsupport.js +240 -240
- package/src/generalhtmlsupportconfig.d.ts +77 -77
- package/src/generalhtmlsupportconfig.js +5 -5
- package/src/htmlcomment.d.ts +71 -71
- package/src/htmlcomment.js +218 -218
- package/src/htmlpagedataprocessor.d.ts +22 -22
- package/src/htmlpagedataprocessor.js +67 -67
- package/src/index.d.ts +25 -25
- package/src/index.js +14 -14
- package/src/integrations/codeblock.d.ts +23 -23
- package/src/integrations/codeblock.js +101 -101
- package/src/integrations/customelement.d.ts +27 -27
- package/src/integrations/customelement.js +146 -146
- package/src/integrations/documentlist.d.ts +27 -27
- package/src/integrations/documentlist.js +178 -178
- package/src/integrations/dualcontent.d.ts +45 -45
- package/src/integrations/dualcontent.js +119 -119
- package/src/integrations/heading.d.ts +31 -31
- package/src/integrations/heading.js +60 -60
- package/src/integrations/image.d.ts +26 -26
- package/src/integrations/image.js +189 -189
- package/src/integrations/integrationutils.d.ts +15 -15
- package/src/integrations/integrationutils.js +21 -21
- package/src/integrations/mediaembed.d.ts +26 -26
- package/src/integrations/mediaembed.js +119 -119
- package/src/integrations/script.d.ts +26 -26
- package/src/integrations/script.js +59 -59
- package/src/integrations/style.d.ts +26 -26
- package/src/integrations/style.js +59 -59
- package/src/integrations/table.d.ts +23 -23
- package/src/integrations/table.js +163 -163
- package/src/schemadefinitions.d.ts +13 -13
- package/src/schemadefinitions.js +953 -956
- package/src/utils.d.ts +72 -72
- package/src/utils.js +139 -139
- package/build/html-support.js.map +0 -1
|
@@ -1,67 +1,67 @@
|
|
|
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/htmlpagedataprocessor
|
|
7
|
-
*/
|
|
8
|
-
import { HtmlDataProcessor, UpcastWriter } from 'ckeditor5/src/engine';
|
|
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) {
|
|
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
|
-
}
|
|
67
|
-
}
|
|
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/htmlpagedataprocessor
|
|
7
|
+
*/
|
|
8
|
+
import { HtmlDataProcessor, UpcastWriter } from 'ckeditor5/src/engine';
|
|
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) {
|
|
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
|
+
}
|
|
67
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,25 +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, type DataSchemaBlockElementDefinition } 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';
|
|
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, type DataSchemaBlockElementDefinition } 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
|
@@ -1,14 +1,14 @@
|
|
|
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
|
-
import './augmentation';
|
|
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
|
+
import './augmentation';
|
|
@@ -1,23 +1,23 @@
|
|
|
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 } from 'ckeditor5/src/core';
|
|
6
|
-
import DataFilter from '../datafilter';
|
|
7
|
-
/**
|
|
8
|
-
* Provides the General HTML Support integration with {@link module:code-block/codeblock~CodeBlock Code Block} feature.
|
|
9
|
-
*/
|
|
10
|
-
export default class CodeBlockElementSupport extends Plugin {
|
|
11
|
-
/**
|
|
12
|
-
* @inheritDoc
|
|
13
|
-
*/
|
|
14
|
-
static get requires(): readonly [typeof DataFilter];
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
static get pluginName(): "CodeBlockElementSupport";
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
init(): void;
|
|
23
|
-
}
|
|
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 } from 'ckeditor5/src/core';
|
|
6
|
+
import DataFilter from '../datafilter';
|
|
7
|
+
/**
|
|
8
|
+
* Provides the General HTML Support integration with {@link module:code-block/codeblock~CodeBlock Code Block} feature.
|
|
9
|
+
*/
|
|
10
|
+
export default class CodeBlockElementSupport extends Plugin {
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/
|
|
14
|
+
static get requires(): readonly [typeof DataFilter];
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
static get pluginName(): "CodeBlockElementSupport";
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
init(): void;
|
|
23
|
+
}
|
|
@@ -1,101 +1,101 @@
|
|
|
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 } from 'ckeditor5/src/core';
|
|
6
|
-
import { updateViewAttributes } from '../utils';
|
|
7
|
-
import DataFilter from '../datafilter';
|
|
8
|
-
/**
|
|
9
|
-
* Provides the General HTML Support integration with {@link module:code-block/codeblock~CodeBlock Code Block} feature.
|
|
10
|
-
*/
|
|
11
|
-
export default 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
|
-
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: ['htmlPreAttributes', 'htmlContentAttributes']
|
|
42
|
-
});
|
|
43
|
-
conversion.for('upcast').add(viewToModelCodeBlockAttributeConverter(dataFilter));
|
|
44
|
-
conversion.for('downcast').add(modelToViewCodeBlockAttributeConverter());
|
|
45
|
-
evt.stop();
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
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 `html*Attributes` 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, 'htmlPreAttributes');
|
|
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
|
-
};
|
|
75
|
-
}
|
|
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
|
-
*/
|
|
81
|
-
function modelToViewCodeBlockAttributeConverter() {
|
|
82
|
-
return (dispatcher) => {
|
|
83
|
-
dispatcher.on('attribute:htmlPreAttributes: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
|
-
};
|
|
101
|
-
}
|
|
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 } from 'ckeditor5/src/core';
|
|
6
|
+
import { updateViewAttributes } from '../utils';
|
|
7
|
+
import DataFilter from '../datafilter';
|
|
8
|
+
/**
|
|
9
|
+
* Provides the General HTML Support integration with {@link module:code-block/codeblock~CodeBlock Code Block} feature.
|
|
10
|
+
*/
|
|
11
|
+
export default 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
|
+
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: ['htmlPreAttributes', 'htmlContentAttributes']
|
|
42
|
+
});
|
|
43
|
+
conversion.for('upcast').add(viewToModelCodeBlockAttributeConverter(dataFilter));
|
|
44
|
+
conversion.for('downcast').add(modelToViewCodeBlockAttributeConverter());
|
|
45
|
+
evt.stop();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
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 `html*Attributes` 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, 'htmlPreAttributes');
|
|
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
|
+
};
|
|
75
|
+
}
|
|
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
|
+
*/
|
|
81
|
+
function modelToViewCodeBlockAttributeConverter() {
|
|
82
|
+
return (dispatcher) => {
|
|
83
|
+
dispatcher.on('attribute:htmlPreAttributes: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
|
+
};
|
|
101
|
+
}
|
|
@@ -1,27 +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
|
-
/**
|
|
6
|
-
* @module html-support/integrations/customelement
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import DataSchema from '../dataschema';
|
|
10
|
-
import DataFilter from '../datafilter';
|
|
11
|
-
/**
|
|
12
|
-
* Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
|
|
13
|
-
*/
|
|
14
|
-
export default class CustomElementSupport extends Plugin {
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
static get requires(): readonly [typeof DataFilter, typeof DataSchema];
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
static get pluginName(): "CustomElementSupport";
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
init(): void;
|
|
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
|
+
/**
|
|
6
|
+
* @module html-support/integrations/customelement
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import DataSchema from '../dataschema';
|
|
10
|
+
import DataFilter from '../datafilter';
|
|
11
|
+
/**
|
|
12
|
+
* Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
|
|
13
|
+
*/
|
|
14
|
+
export default class CustomElementSupport extends Plugin {
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
static get requires(): readonly [typeof DataFilter, typeof DataSchema];
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get pluginName(): "CustomElementSupport";
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
init(): void;
|
|
27
|
+
}
|