@ckeditor/ckeditor5-html-support 0.0.0-internal-20241017.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/LICENSE.md +21 -0
- package/README.md +26 -0
- package/build/html-support.js +5 -0
- package/build/translations/ar.js +1 -0
- package/build/translations/bg.js +1 -0
- package/build/translations/bn.js +1 -0
- package/build/translations/ca.js +1 -0
- package/build/translations/cs.js +1 -0
- package/build/translations/da.js +1 -0
- package/build/translations/de.js +1 -0
- package/build/translations/el.js +1 -0
- package/build/translations/en-au.js +1 -0
- package/build/translations/es.js +1 -0
- package/build/translations/et.js +1 -0
- package/build/translations/fi.js +1 -0
- package/build/translations/fr.js +1 -0
- package/build/translations/gl.js +1 -0
- package/build/translations/he.js +1 -0
- package/build/translations/hi.js +1 -0
- package/build/translations/hr.js +1 -0
- package/build/translations/hu.js +1 -0
- package/build/translations/id.js +1 -0
- package/build/translations/it.js +1 -0
- package/build/translations/ja.js +1 -0
- package/build/translations/jv.js +1 -0
- package/build/translations/ko.js +1 -0
- package/build/translations/lt.js +1 -0
- package/build/translations/lv.js +1 -0
- package/build/translations/ms.js +1 -0
- package/build/translations/nl.js +1 -0
- package/build/translations/no.js +1 -0
- package/build/translations/pl.js +1 -0
- package/build/translations/pt-br.js +1 -0
- package/build/translations/pt.js +1 -0
- package/build/translations/ro.js +1 -0
- package/build/translations/ru.js +1 -0
- package/build/translations/sk.js +1 -0
- package/build/translations/sr-latn.js +1 -0
- package/build/translations/sr.js +1 -0
- package/build/translations/sv.js +1 -0
- package/build/translations/th.js +1 -0
- package/build/translations/tr.js +1 -0
- package/build/translations/ug.js +1 -0
- package/build/translations/uk.js +1 -0
- package/build/translations/ur.js +1 -0
- package/build/translations/vi.js +1 -0
- package/build/translations/zh-cn.js +1 -0
- package/build/translations/zh.js +1 -0
- package/ckeditor5-metadata.json +60 -0
- package/dist/augmentation.d.ts +37 -0
- package/dist/converters.d.ts +64 -0
- package/dist/datafilter.d.ts +312 -0
- package/dist/dataschema.d.ts +191 -0
- package/dist/fullpage.d.ts +29 -0
- package/dist/generalhtmlsupport.d.ts +106 -0
- package/dist/generalhtmlsupportconfig.d.ts +81 -0
- package/dist/htmlcomment.d.ts +79 -0
- package/dist/htmlpagedataprocessor.d.ts +26 -0
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +51 -0
- package/dist/index.css +63 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +4040 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/codeblock.d.ts +31 -0
- package/dist/integrations/customelement.d.ts +35 -0
- package/dist/integrations/dualcontent.d.ts +53 -0
- package/dist/integrations/heading.d.ts +39 -0
- package/dist/integrations/image.d.ts +34 -0
- package/dist/integrations/integrationutils.d.ts +19 -0
- package/dist/integrations/list.d.ts +35 -0
- package/dist/integrations/mediaembed.d.ts +34 -0
- package/dist/integrations/script.d.ts +34 -0
- package/dist/integrations/style.d.ts +34 -0
- package/dist/integrations/table.d.ts +31 -0
- package/dist/schemadefinitions.d.ts +17 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/ar.umd.js +11 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bg.umd.js +11 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/bn.umd.js +11 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/ca.umd.js +11 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/cs.umd.js +11 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/da.umd.js +11 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/de.umd.js +11 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/el.umd.js +11 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en-au.umd.js +11 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/en.umd.js +11 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/es.umd.js +11 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/et.umd.js +11 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fi.umd.js +11 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/fr.umd.js +11 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/gl.umd.js +11 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/he.umd.js +11 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hi.umd.js +11 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hr.umd.js +11 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/hu.umd.js +11 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/id.umd.js +11 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/it.umd.js +11 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/ja.umd.js +11 -0
- package/dist/translations/jv.d.ts +8 -0
- package/dist/translations/jv.js +5 -0
- package/dist/translations/jv.umd.js +11 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ko.umd.js +11 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lt.umd.js +11 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/lv.umd.js +11 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/ms.umd.js +11 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/nl.umd.js +11 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/no.umd.js +11 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pl.umd.js +11 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt-br.umd.js +11 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/pt.umd.js +11 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ro.umd.js +11 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/ru.umd.js +11 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sk.umd.js +11 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr-latn.umd.js +11 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sr.umd.js +11 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/sv.umd.js +11 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/th.umd.js +11 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/tr.umd.js +11 -0
- package/dist/translations/ug.d.ts +8 -0
- package/dist/translations/ug.js +5 -0
- package/dist/translations/ug.umd.js +11 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/uk.umd.js +11 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/ur.umd.js +11 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/vi.umd.js +11 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh-cn.umd.js +11 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/translations/zh.umd.js +11 -0
- package/dist/utils.d.ts +76 -0
- package/lang/contexts.json +3 -0
- package/lang/translations/ar.po +22 -0
- package/lang/translations/bg.po +22 -0
- package/lang/translations/bn.po +22 -0
- package/lang/translations/ca.po +22 -0
- package/lang/translations/cs.po +22 -0
- package/lang/translations/da.po +22 -0
- package/lang/translations/de.po +22 -0
- package/lang/translations/el.po +22 -0
- package/lang/translations/en-au.po +22 -0
- package/lang/translations/en.po +22 -0
- package/lang/translations/es.po +22 -0
- package/lang/translations/et.po +22 -0
- package/lang/translations/fi.po +22 -0
- package/lang/translations/fr.po +22 -0
- package/lang/translations/gl.po +22 -0
- package/lang/translations/he.po +22 -0
- package/lang/translations/hi.po +22 -0
- package/lang/translations/hr.po +22 -0
- package/lang/translations/hu.po +22 -0
- package/lang/translations/id.po +22 -0
- package/lang/translations/it.po +22 -0
- package/lang/translations/ja.po +22 -0
- package/lang/translations/jv.po +22 -0
- package/lang/translations/ko.po +22 -0
- package/lang/translations/lt.po +22 -0
- package/lang/translations/lv.po +22 -0
- package/lang/translations/ms.po +22 -0
- package/lang/translations/nl.po +22 -0
- package/lang/translations/no.po +22 -0
- package/lang/translations/pl.po +22 -0
- package/lang/translations/pt-br.po +22 -0
- package/lang/translations/pt.po +22 -0
- package/lang/translations/ro.po +22 -0
- package/lang/translations/ru.po +22 -0
- package/lang/translations/sk.po +22 -0
- package/lang/translations/sr-latn.po +22 -0
- package/lang/translations/sr.po +22 -0
- package/lang/translations/sv.po +22 -0
- package/lang/translations/th.po +22 -0
- package/lang/translations/tr.po +22 -0
- package/lang/translations/ug.po +22 -0
- package/lang/translations/uk.po +22 -0
- package/lang/translations/ur.po +22 -0
- package/lang/translations/vi.po +22 -0
- package/lang/translations/zh-cn.po +22 -0
- package/lang/translations/zh.po +22 -0
- package/package.json +48 -0
- package/src/augmentation.d.ts +33 -0
- package/src/augmentation.js +5 -0
- package/src/converters.d.ts +60 -0
- package/src/converters.js +180 -0
- package/src/datafilter.d.ts +308 -0
- package/src/datafilter.js +755 -0
- package/src/dataschema.d.ts +187 -0
- package/src/dataschema.js +202 -0
- package/src/fullpage.d.ts +25 -0
- package/src/fullpage.js +86 -0
- package/src/generalhtmlsupport.d.ts +102 -0
- package/src/generalhtmlsupport.js +246 -0
- package/src/generalhtmlsupportconfig.d.ts +77 -0
- package/src/generalhtmlsupportconfig.js +5 -0
- package/src/htmlcomment.d.ts +75 -0
- package/src/htmlcomment.js +224 -0
- package/src/htmlpagedataprocessor.d.ts +22 -0
- package/src/htmlpagedataprocessor.js +67 -0
- package/src/index.d.ts +25 -0
- package/src/index.js +14 -0
- package/src/integrations/codeblock.d.ts +27 -0
- package/src/integrations/codeblock.js +107 -0
- package/src/integrations/customelement.d.ts +31 -0
- package/src/integrations/customelement.js +162 -0
- package/src/integrations/dualcontent.d.ts +49 -0
- package/src/integrations/dualcontent.js +125 -0
- package/src/integrations/heading.d.ts +35 -0
- package/src/integrations/heading.js +72 -0
- package/src/integrations/image.d.ts +30 -0
- package/src/integrations/image.js +195 -0
- package/src/integrations/integrationutils.d.ts +15 -0
- package/src/integrations/integrationutils.js +21 -0
- package/src/integrations/list.d.ts +31 -0
- package/src/integrations/list.js +185 -0
- package/src/integrations/mediaembed.d.ts +30 -0
- package/src/integrations/mediaembed.js +125 -0
- package/src/integrations/script.d.ts +30 -0
- package/src/integrations/script.js +65 -0
- package/src/integrations/style.d.ts +30 -0
- package/src/integrations/style.js +65 -0
- package/src/integrations/table.d.ts +27 -0
- package/src/integrations/table.js +169 -0
- package/src/schemadefinitions.d.ts +13 -0
- package/src/schemadefinitions.js +964 -0
- package/src/utils.d.ts +72 -0
- package/src/utils.js +139 -0
- package/theme/datafilter.css +56 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module html-support/htmlpagedataprocessor
|
|
7
|
+
*/
|
|
8
|
+
import { HtmlDataProcessor, UpcastWriter } from 'ckeditor5/src/engine.js';
|
|
9
|
+
/**
|
|
10
|
+
* The full page HTML data processor class.
|
|
11
|
+
* This data processor implementation uses HTML as input and output data.
|
|
12
|
+
*/
|
|
13
|
+
export default class HtmlPageDataProcessor extends HtmlDataProcessor {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
toView(data) {
|
|
18
|
+
// Ignore content that is not a full page source.
|
|
19
|
+
if (!/<(?:html|body|head|meta)(?:\s[^>]*)?>/i.test(data.trim().slice(0, 10000))) {
|
|
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.trim().replace(/<\?xml\s[^?]*\?>/i, match => {
|
|
26
|
+
xmlDeclaration = match;
|
|
27
|
+
return '';
|
|
28
|
+
});
|
|
29
|
+
data = data.trim().replace(/^<!DOCTYPE\s[^>]*?>/i, match => {
|
|
30
|
+
docType = 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
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module html-support
|
|
7
|
+
*/
|
|
8
|
+
export { default as GeneralHtmlSupport } from './generalhtmlsupport.js';
|
|
9
|
+
export { default as DataFilter } from './datafilter.js';
|
|
10
|
+
export { default as DataSchema, type DataSchemaBlockElementDefinition } from './dataschema.js';
|
|
11
|
+
export { default as HtmlComment } from './htmlcomment.js';
|
|
12
|
+
export { default as FullPage } from './fullpage.js';
|
|
13
|
+
export { default as HtmlPageDataProcessor } from './htmlpagedataprocessor.js';
|
|
14
|
+
export type { GeneralHtmlSupportConfig } from './generalhtmlsupportconfig.js';
|
|
15
|
+
export type { default as CodeBlockElementSupport } from './integrations/codeblock.js';
|
|
16
|
+
export type { default as CustomElementSupport } from './integrations/customelement.js';
|
|
17
|
+
export type { default as ListElementSupport } from './integrations/list.js';
|
|
18
|
+
export type { default as DualContentModelElementSupport } from './integrations/dualcontent.js';
|
|
19
|
+
export type { default as HeadingElementSupport } from './integrations/heading.js';
|
|
20
|
+
export type { default as ImageElementSupport } from './integrations/image.js';
|
|
21
|
+
export type { default as MediaEmbedElementSupport } from './integrations/mediaembed.js';
|
|
22
|
+
export type { default as ScriptElementSupport } from './integrations/script.js';
|
|
23
|
+
export type { default as StyleElementSupport } from './integrations/style.js';
|
|
24
|
+
export type { default as TableElementSupport } from './integrations/table.js';
|
|
25
|
+
import './augmentation.js';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module html-support
|
|
7
|
+
*/
|
|
8
|
+
export { default as GeneralHtmlSupport } from './generalhtmlsupport.js';
|
|
9
|
+
export { default as DataFilter } from './datafilter.js';
|
|
10
|
+
export { default as DataSchema } from './dataschema.js';
|
|
11
|
+
export { default as HtmlComment } from './htmlcomment.js';
|
|
12
|
+
export { default as FullPage } from './fullpage.js';
|
|
13
|
+
export { default as HtmlPageDataProcessor } from './htmlpagedataprocessor.js';
|
|
14
|
+
import './augmentation.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
6
|
+
import DataFilter from '../datafilter.js';
|
|
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
|
+
static get isOfficialPlugin(): true;
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
init(): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
6
|
+
import { 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 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
|
+
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
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module html-support/integrations/customelement
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
+
import DataSchema from '../dataschema.js';
|
|
10
|
+
import DataFilter from '../datafilter.js';
|
|
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
|
+
static get isOfficialPlugin(): true;
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
init(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module html-support/integrations/customelement
|
|
7
|
+
*/
|
|
8
|
+
/* globals document */
|
|
9
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
10
|
+
import { UpcastWriter } from 'ckeditor5/src/engine.js';
|
|
11
|
+
import DataSchema from '../dataschema.js';
|
|
12
|
+
import DataFilter from '../datafilter.js';
|
|
13
|
+
import { setViewAttributes } from '../utils.js';
|
|
14
|
+
/**
|
|
15
|
+
* Provides the General HTML Support for custom elements (not registered in the {@link module:html-support/dataschema~DataSchema}).
|
|
16
|
+
*/
|
|
17
|
+
export default class CustomElementSupport extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
static get requires() {
|
|
22
|
+
return [DataFilter, DataSchema];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get pluginName() {
|
|
28
|
+
return 'CustomElementSupport';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
static get isOfficialPlugin() {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @inheritDoc
|
|
38
|
+
*/
|
|
39
|
+
init() {
|
|
40
|
+
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
41
|
+
const dataSchema = this.editor.plugins.get(DataSchema);
|
|
42
|
+
dataFilter.on('register:$customElement', (evt, definition) => {
|
|
43
|
+
evt.stop();
|
|
44
|
+
const editor = this.editor;
|
|
45
|
+
const schema = editor.model.schema;
|
|
46
|
+
const conversion = editor.conversion;
|
|
47
|
+
const unsafeElements = editor.editing.view.domConverter.unsafeElements;
|
|
48
|
+
const preLikeElements = editor.data.htmlProcessor.domConverter.preElements;
|
|
49
|
+
schema.register(definition.model, definition.modelSchema);
|
|
50
|
+
schema.extend(definition.model, {
|
|
51
|
+
allowAttributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent'],
|
|
52
|
+
isContent: true
|
|
53
|
+
});
|
|
54
|
+
// For the `<template>` element we use only raw-content because DOM API exposes its content
|
|
55
|
+
// only as a document fragment in the `content` property (or innerHTML).
|
|
56
|
+
editor.data.htmlProcessor.domConverter.registerRawContentMatcher({ name: 'template' });
|
|
57
|
+
// Being executed on the low priority, it will catch all elements that were not caught by other converters.
|
|
58
|
+
conversion.for('upcast').elementToElement({
|
|
59
|
+
view: /.*/,
|
|
60
|
+
model: (viewElement, conversionApi) => {
|
|
61
|
+
// Do not try to convert $comment fake element.
|
|
62
|
+
if (viewElement.name == '$comment') {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (!isValidElementName(viewElement.name)) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
// Allow for fallback only if this element is not defined in data schema to make sure
|
|
69
|
+
// that this will handle only custom elements not registered in the data schema.
|
|
70
|
+
if (dataSchema.getDefinitionsForView(viewElement.name).size) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
// Make sure that this element will not render in the editing view.
|
|
74
|
+
if (!unsafeElements.includes(viewElement.name)) {
|
|
75
|
+
unsafeElements.push(viewElement.name);
|
|
76
|
+
}
|
|
77
|
+
// Make sure that whitespaces will not be trimmed or replaced by nbsps while stringify content.
|
|
78
|
+
if (!preLikeElements.includes(viewElement.name)) {
|
|
79
|
+
preLikeElements.push(viewElement.name);
|
|
80
|
+
}
|
|
81
|
+
const modelElement = conversionApi.writer.createElement(definition.model, {
|
|
82
|
+
htmlElementName: viewElement.name
|
|
83
|
+
});
|
|
84
|
+
const htmlAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
85
|
+
if (htmlAttributes) {
|
|
86
|
+
conversionApi.writer.setAttribute('htmlCustomElementAttributes', htmlAttributes, modelElement);
|
|
87
|
+
}
|
|
88
|
+
let htmlContent;
|
|
89
|
+
// For the `<template>` element we use only raw-content because DOM API exposes its content
|
|
90
|
+
// only as a document fragment in the `content` property.
|
|
91
|
+
if (viewElement.is('element', 'template') && viewElement.getCustomProperty('$rawContent')) {
|
|
92
|
+
htmlContent = viewElement.getCustomProperty('$rawContent');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Store the whole element in the attribute so that DomConverter will be able to use the pre like element context.
|
|
96
|
+
const viewWriter = new UpcastWriter(viewElement.document);
|
|
97
|
+
const documentFragment = viewWriter.createDocumentFragment(viewElement);
|
|
98
|
+
const domFragment = editor.data.htmlProcessor.domConverter.viewToDom(documentFragment);
|
|
99
|
+
const domElement = domFragment.firstChild;
|
|
100
|
+
while (domElement.firstChild) {
|
|
101
|
+
domFragment.appendChild(domElement.firstChild);
|
|
102
|
+
}
|
|
103
|
+
domElement.remove();
|
|
104
|
+
htmlContent = editor.data.htmlProcessor.htmlWriter.getHtml(domFragment);
|
|
105
|
+
}
|
|
106
|
+
conversionApi.writer.setAttribute('htmlContent', htmlContent, modelElement);
|
|
107
|
+
// Consume the content of the element.
|
|
108
|
+
for (const { item } of editor.editing.view.createRangeIn(viewElement)) {
|
|
109
|
+
conversionApi.consumable.consume(item, { name: true });
|
|
110
|
+
}
|
|
111
|
+
return modelElement;
|
|
112
|
+
},
|
|
113
|
+
converterPriority: 'low'
|
|
114
|
+
});
|
|
115
|
+
// Because this element is unsafe (DomConverter#unsafeElements), it will render as a transparent <span> but it must
|
|
116
|
+
// be rendered anyway for the mapping between the model and the view to exist.
|
|
117
|
+
conversion.for('editingDowncast').elementToElement({
|
|
118
|
+
model: {
|
|
119
|
+
name: definition.model,
|
|
120
|
+
attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
|
|
121
|
+
},
|
|
122
|
+
view: (modelElement, { writer }) => {
|
|
123
|
+
const viewName = modelElement.getAttribute('htmlElementName');
|
|
124
|
+
const viewElement = writer.createRawElement(viewName);
|
|
125
|
+
if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
|
|
126
|
+
setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
|
|
127
|
+
}
|
|
128
|
+
return viewElement;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
conversion.for('dataDowncast').elementToElement({
|
|
132
|
+
model: {
|
|
133
|
+
name: definition.model,
|
|
134
|
+
attributes: ['htmlElementName', 'htmlCustomElementAttributes', 'htmlContent']
|
|
135
|
+
},
|
|
136
|
+
view: (modelElement, { writer }) => {
|
|
137
|
+
const viewName = modelElement.getAttribute('htmlElementName');
|
|
138
|
+
const htmlContent = modelElement.getAttribute('htmlContent');
|
|
139
|
+
const viewElement = writer.createRawElement(viewName, null, (domElement, domConverter) => {
|
|
140
|
+
domConverter.setContentOf(domElement, htmlContent);
|
|
141
|
+
});
|
|
142
|
+
if (modelElement.hasAttribute('htmlCustomElementAttributes')) {
|
|
143
|
+
setViewAttributes(writer, modelElement.getAttribute('htmlCustomElementAttributes'), viewElement);
|
|
144
|
+
}
|
|
145
|
+
return viewElement;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Returns true if name is valid for a DOM element name.
|
|
153
|
+
*/
|
|
154
|
+
function isValidElementName(name) {
|
|
155
|
+
try {
|
|
156
|
+
document.createElement(name);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
6
|
+
import DataFilter from '../datafilter.js';
|
|
7
|
+
/**
|
|
8
|
+
* Provides the General HTML Support integration for elements which can behave like sectioning element (e.g. article) or
|
|
9
|
+
* element accepting only inline content (e.g. paragraph).
|
|
10
|
+
*
|
|
11
|
+
* The distinction between this two content models is important for choosing correct schema model and proper content conversion.
|
|
12
|
+
* As an example, it ensures that:
|
|
13
|
+
*
|
|
14
|
+
* * children elements paragraphing is enabled for sectioning elements only,
|
|
15
|
+
* * element and its content can be correctly handled by editing view (splitting and merging elements),
|
|
16
|
+
* * model element HTML is semantically correct and easier to work with.
|
|
17
|
+
*
|
|
18
|
+
* If element contains any block element, it will be treated as a sectioning element and registered using
|
|
19
|
+
* {@link module:html-support/dataschema~DataSchemaDefinition#model} and
|
|
20
|
+
* {@link module:html-support/dataschema~DataSchemaDefinition#modelSchema} in editor schema.
|
|
21
|
+
* Otherwise, it will be registered under {@link module:html-support/dataschema~DataSchemaBlockElementDefinition#paragraphLikeModel} model
|
|
22
|
+
* name with model schema accepting only inline content (inheriting from `$block`).
|
|
23
|
+
*/
|
|
24
|
+
export default class DualContentModelElementSupport extends Plugin {
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
static get requires(): readonly [typeof DataFilter];
|
|
29
|
+
/**
|
|
30
|
+
* @inheritDoc
|
|
31
|
+
*/
|
|
32
|
+
static get pluginName(): "DualContentModelElementSupport";
|
|
33
|
+
/**
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/
|
|
36
|
+
static get isOfficialPlugin(): true;
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
init(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Checks whether the given view element includes any other block element.
|
|
43
|
+
*/
|
|
44
|
+
private _hasBlockContent;
|
|
45
|
+
/**
|
|
46
|
+
* Adds attribute filtering conversion for the given data schema.
|
|
47
|
+
*/
|
|
48
|
+
private _addAttributeConversion;
|
|
49
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
6
|
+
import { 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~DataSchemaDefinition#model} and
|
|
23
|
+
* {@link module:html-support/dataschema~DataSchemaDefinition#modelSchema} in editor schema.
|
|
24
|
+
* Otherwise, it will be registered under {@link module:html-support/dataschema~DataSchemaBlockElementDefinition#paragraphLikeModel} model
|
|
25
|
+
* name with model schema accepting only inline content (inheriting from `$block`).
|
|
26
|
+
*/
|
|
27
|
+
export default class DualContentModelElementSupport extends Plugin {
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
static get requires() {
|
|
32
|
+
return [DataFilter];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
static get pluginName() {
|
|
38
|
+
return 'DualContentModelElementSupport';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
43
|
+
static get isOfficialPlugin() {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @inheritDoc
|
|
48
|
+
*/
|
|
49
|
+
init() {
|
|
50
|
+
const dataFilter = this.editor.plugins.get(DataFilter);
|
|
51
|
+
dataFilter.on('register', (evt, definition) => {
|
|
52
|
+
const blockDefinition = definition;
|
|
53
|
+
const editor = this.editor;
|
|
54
|
+
const schema = editor.model.schema;
|
|
55
|
+
const conversion = editor.conversion;
|
|
56
|
+
if (!blockDefinition.paragraphLikeModel) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Can only apply to newly registered features.
|
|
60
|
+
if (schema.isRegistered(blockDefinition.model) || schema.isRegistered(blockDefinition.paragraphLikeModel)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const paragraphLikeModelDefinition = {
|
|
64
|
+
model: blockDefinition.paragraphLikeModel,
|
|
65
|
+
view: blockDefinition.view
|
|
66
|
+
};
|
|
67
|
+
schema.register(blockDefinition.model, blockDefinition.modelSchema);
|
|
68
|
+
schema.register(paragraphLikeModelDefinition.model, {
|
|
69
|
+
inheritAllFrom: '$block'
|
|
70
|
+
});
|
|
71
|
+
conversion.for('upcast').elementToElement({
|
|
72
|
+
view: blockDefinition.view,
|
|
73
|
+
model: (viewElement, { writer }) => {
|
|
74
|
+
if (this._hasBlockContent(viewElement)) {
|
|
75
|
+
return writer.createElement(blockDefinition.model);
|
|
76
|
+
}
|
|
77
|
+
return writer.createElement(paragraphLikeModelDefinition.model);
|
|
78
|
+
},
|
|
79
|
+
// With a `low` priority, `paragraph` plugin auto-paragraphing mechanism is executed. Make sure
|
|
80
|
+
// this listener is called before it. If not, some elements will be transformed into a paragraph.
|
|
81
|
+
converterPriority: priorities.low + 0.5
|
|
82
|
+
});
|
|
83
|
+
conversion.for('downcast').elementToElement({
|
|
84
|
+
view: blockDefinition.view,
|
|
85
|
+
model: blockDefinition.model
|
|
86
|
+
});
|
|
87
|
+
this._addAttributeConversion(blockDefinition);
|
|
88
|
+
conversion.for('downcast').elementToElement({
|
|
89
|
+
view: paragraphLikeModelDefinition.view,
|
|
90
|
+
model: paragraphLikeModelDefinition.model
|
|
91
|
+
});
|
|
92
|
+
this._addAttributeConversion(paragraphLikeModelDefinition);
|
|
93
|
+
evt.stop();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Checks whether the given view element includes any other block element.
|
|
98
|
+
*/
|
|
99
|
+
_hasBlockContent(viewElement) {
|
|
100
|
+
const view = this.editor.editing.view;
|
|
101
|
+
const blockElements = view.domConverter.blockElements;
|
|
102
|
+
// Traversing the viewElement subtree looking for block elements.
|
|
103
|
+
// Especially for the cases like <div><a href="#"><p>foo</p></a></div>.
|
|
104
|
+
// https://github.com/ckeditor/ckeditor5/issues/11513
|
|
105
|
+
for (const viewItem of view.createRangeIn(viewElement).getItems()) {
|
|
106
|
+
if (viewItem.is('element') && blockElements.includes(viewItem.name)) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Adds attribute filtering conversion for the given data schema.
|
|
114
|
+
*/
|
|
115
|
+
_addAttributeConversion(definition) {
|
|
116
|
+
const editor = this.editor;
|
|
117
|
+
const conversion = editor.conversion;
|
|
118
|
+
const dataFilter = editor.plugins.get(DataFilter);
|
|
119
|
+
editor.model.schema.extend(definition.model, {
|
|
120
|
+
allowAttributes: getHtmlAttributeName(definition.view)
|
|
121
|
+
});
|
|
122
|
+
conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, dataFilter));
|
|
123
|
+
conversion.for('downcast').add(modelToViewBlockAttributeConverter(definition));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module html-support/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 default class HeadingElementSupport extends Plugin {
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
static get requires(): readonly [typeof DataSchema, typeof Enter];
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get pluginName(): "HeadingElementSupport";
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
static get isOfficialPlugin(): true;
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
init(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Registers all elements supported by HeadingEditing to enable custom attributes for those elements.
|
|
33
|
+
*/
|
|
34
|
+
private registerHeadingElements;
|
|
35
|
+
}
|