@ckeditor/ckeditor5-html-support 38.0.0 → 38.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/build/html-support.js +1 -1
- package/package.json +2 -45
- package/src/converters.d.ts +3 -3
- package/src/converters.js +9 -8
- package/src/datafilter.d.ts +33 -3
- package/src/datafilter.js +64 -11
- package/src/dataschema.d.ts +2 -2
- package/src/fullpage.d.ts +1 -1
- package/src/generalhtmlsupport.d.ts +1 -1
- package/src/generalhtmlsupport.js +2 -2
- package/src/htmlcomment.d.ts +1 -1
- package/src/htmlcomment.js +59 -27
- package/src/index.d.ts +1 -1
- package/src/integrations/codeblock.d.ts +1 -1
- package/src/integrations/codeblock.js +4 -4
- package/src/integrations/customelement.d.ts +1 -1
- package/src/integrations/customelement.js +8 -8
- package/src/integrations/documentlist.d.ts +1 -1
- package/src/integrations/documentlist.js +56 -23
- package/src/integrations/dualcontent.d.ts +1 -1
- package/src/integrations/dualcontent.js +3 -2
- package/src/integrations/heading.d.ts +1 -5
- package/src/integrations/heading.js +0 -15
- package/src/integrations/image.d.ts +1 -1
- package/src/integrations/image.js +5 -5
- package/src/integrations/mediaembed.d.ts +1 -1
- package/src/integrations/mediaembed.js +4 -4
- package/src/integrations/script.d.ts +1 -1
- package/src/integrations/script.js +1 -1
- package/src/integrations/style.d.ts +1 -1
- package/src/integrations/style.js +1 -1
- package/src/integrations/table.d.ts +1 -1
- package/src/integrations/table.js +3 -3
- package/src/schemadefinitions.js +9 -5
- package/src/utils.d.ts +11 -0
- package/src/utils.js +16 -1
|
@@ -6,6 +6,7 @@ import { Plugin } from 'ckeditor5/src/core';
|
|
|
6
6
|
import { priorities } from 'ckeditor5/src/utils';
|
|
7
7
|
import { modelToViewBlockAttributeConverter, viewToModelBlockAttributeConverter } from '../converters';
|
|
8
8
|
import DataFilter from '../datafilter';
|
|
9
|
+
import { getHtmlAttributeName } from '../utils';
|
|
9
10
|
/**
|
|
10
11
|
* Provides the General HTML Support integration for elements which can behave like sectioning element (e.g. article) or
|
|
11
12
|
* element accepting only inline content (e.g. paragraph).
|
|
@@ -71,7 +72,7 @@ export default class DualContentModelElementSupport extends Plugin {
|
|
|
71
72
|
},
|
|
72
73
|
// With a `low` priority, `paragraph` plugin auto-paragraphing mechanism is executed. Make sure
|
|
73
74
|
// this listener is called before it. If not, some elements will be transformed into a paragraph.
|
|
74
|
-
converterPriority: priorities.
|
|
75
|
+
converterPriority: priorities.low + 0.5
|
|
75
76
|
});
|
|
76
77
|
conversion.for('downcast').elementToElement({
|
|
77
78
|
view: blockDefinition.view,
|
|
@@ -110,7 +111,7 @@ export default class DualContentModelElementSupport extends Plugin {
|
|
|
110
111
|
const conversion = editor.conversion;
|
|
111
112
|
const dataFilter = editor.plugins.get(DataFilter);
|
|
112
113
|
editor.model.schema.extend(definition.model, {
|
|
113
|
-
allowAttributes:
|
|
114
|
+
allowAttributes: getHtmlAttributeName(definition.view)
|
|
114
115
|
});
|
|
115
116
|
conversion.for('upcast').add(viewToModelBlockAttributeConverter(definition, dataFilter));
|
|
116
117
|
conversion.for('downcast').add(modelToViewBlockAttributeConverter(definition));
|
|
@@ -19,7 +19,7 @@ export default class HeadingElementSupport extends Plugin {
|
|
|
19
19
|
/**
|
|
20
20
|
* @inheritDoc
|
|
21
21
|
*/
|
|
22
|
-
static get pluginName():
|
|
22
|
+
static get pluginName(): "HeadingElementSupport";
|
|
23
23
|
/**
|
|
24
24
|
* @inheritDoc
|
|
25
25
|
*/
|
|
@@ -28,8 +28,4 @@ export default class HeadingElementSupport extends Plugin {
|
|
|
28
28
|
* Registers all elements supported by HeadingEditing to enable custom attributes for those elements.
|
|
29
29
|
*/
|
|
30
30
|
private registerHeadingElements;
|
|
31
|
-
/**
|
|
32
|
-
* Removes css classes from "htmlAttributes" of new paragraph created when hitting "enter" in heading.
|
|
33
|
-
*/
|
|
34
|
-
private removeClassesOnEnter;
|
|
35
31
|
}
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
9
9
|
import { Enter } from 'ckeditor5/src/enter';
|
|
10
10
|
import DataSchema from '../dataschema';
|
|
11
|
-
import { modifyGhsAttribute } from '../utils';
|
|
12
11
|
/**
|
|
13
12
|
* Provides the General HTML Support integration with {@link module:heading/heading~Heading Heading} feature.
|
|
14
13
|
*/
|
|
@@ -35,7 +34,6 @@ export default class HeadingElementSupport extends Plugin {
|
|
|
35
34
|
}
|
|
36
35
|
const options = editor.config.get('heading.options');
|
|
37
36
|
this.registerHeadingElements(editor, options);
|
|
38
|
-
this.removeClassesOnEnter(editor, options);
|
|
39
37
|
}
|
|
40
38
|
/**
|
|
41
39
|
* Registers all elements supported by HeadingEditing to enable custom attributes for those elements.
|
|
@@ -59,17 +57,4 @@ export default class HeadingElementSupport extends Plugin {
|
|
|
59
57
|
}
|
|
60
58
|
});
|
|
61
59
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Removes css classes from "htmlAttributes" of new paragraph created when hitting "enter" in heading.
|
|
64
|
-
*/
|
|
65
|
-
removeClassesOnEnter(editor, options) {
|
|
66
|
-
const enterCommand = editor.commands.get('enter');
|
|
67
|
-
this.listenTo(enterCommand, 'afterExecute', (evt, data) => {
|
|
68
|
-
const positionParent = editor.model.document.selection.getFirstPosition().parent;
|
|
69
|
-
const isHeading = options.some(option => positionParent.is('element', option.model));
|
|
70
|
-
if (isHeading && positionParent.childCount === 0) {
|
|
71
|
-
modifyGhsAttribute(data.writer, positionParent, 'htmlAttributes', 'classes', classes => classes.clear());
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
60
|
}
|
|
@@ -47,7 +47,7 @@ export default class ImageElementSupport extends Plugin {
|
|
|
47
47
|
if (schema.isRegistered('imageBlock')) {
|
|
48
48
|
schema.extend('imageBlock', {
|
|
49
49
|
allowAttributes: [
|
|
50
|
-
'
|
|
50
|
+
'htmlImgAttributes',
|
|
51
51
|
// Figure and Link don't have model counterpart.
|
|
52
52
|
// We will preserve attributes on image model element using these attribute keys.
|
|
53
53
|
'htmlFigureAttributes',
|
|
@@ -60,7 +60,7 @@ export default class ImageElementSupport extends Plugin {
|
|
|
60
60
|
allowAttributes: [
|
|
61
61
|
// `htmlA` is needed for standard GHS link integration.
|
|
62
62
|
'htmlA',
|
|
63
|
-
'
|
|
63
|
+
'htmlImgAttributes'
|
|
64
64
|
]
|
|
65
65
|
});
|
|
66
66
|
}
|
|
@@ -84,7 +84,7 @@ function viewToModelImageAttributeConverter(dataFilter) {
|
|
|
84
84
|
}
|
|
85
85
|
const viewImageElement = data.viewItem;
|
|
86
86
|
const viewContainerElement = viewImageElement.parent;
|
|
87
|
-
preserveElementAttributes(viewImageElement, '
|
|
87
|
+
preserveElementAttributes(viewImageElement, 'htmlImgAttributes');
|
|
88
88
|
if (viewContainerElement.is('element', 'a')) {
|
|
89
89
|
preserveLinkAttributes(viewContainerElement);
|
|
90
90
|
}
|
|
@@ -129,8 +129,8 @@ function viewToModelFigureAttributeConverter(dataFilter) {
|
|
|
129
129
|
*/
|
|
130
130
|
function modelToViewImageAttributeConverter() {
|
|
131
131
|
return (dispatcher) => {
|
|
132
|
-
addInlineAttributeConversion('
|
|
133
|
-
addBlockAttributeConversion('img', '
|
|
132
|
+
addInlineAttributeConversion('htmlImgAttributes');
|
|
133
|
+
addBlockAttributeConversion('img', 'htmlImgAttributes');
|
|
134
134
|
addBlockAttributeConversion('figure', 'htmlFigureAttributes');
|
|
135
135
|
addBlockAttributeConversion('a', 'htmlLinkAttributes');
|
|
136
136
|
function addInlineAttributeConversion(attributeName) {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
9
9
|
import DataFilter from '../datafilter';
|
|
10
10
|
import DataSchema from '../dataschema';
|
|
11
|
-
import { updateViewAttributes } from '../utils';
|
|
11
|
+
import { updateViewAttributes, getHtmlAttributeName } from '../utils';
|
|
12
12
|
import { getDescendantElement } from './integrationutils';
|
|
13
13
|
/**
|
|
14
14
|
* Provides the General HTML Support integration with {@link module:media-embed/mediaembed~MediaEmbed Media Embed} feature.
|
|
@@ -55,7 +55,7 @@ export default class MediaEmbedElementSupport extends Plugin {
|
|
|
55
55
|
}
|
|
56
56
|
schema.extend('media', {
|
|
57
57
|
allowAttributes: [
|
|
58
|
-
|
|
58
|
+
getHtmlAttributeName(mediaElementName),
|
|
59
59
|
'htmlFigureAttributes'
|
|
60
60
|
]
|
|
61
61
|
});
|
|
@@ -68,7 +68,7 @@ export default class MediaEmbedElementSupport extends Plugin {
|
|
|
68
68
|
function viewToModelMediaAttributesConverter(dataFilter, mediaElementName) {
|
|
69
69
|
const upcastMedia = (evt, data, conversionApi) => {
|
|
70
70
|
const viewMediaElement = data.viewItem;
|
|
71
|
-
preserveElementAttributes(viewMediaElement,
|
|
71
|
+
preserveElementAttributes(viewMediaElement, getHtmlAttributeName(mediaElementName));
|
|
72
72
|
function preserveElementAttributes(viewElement, attributeName) {
|
|
73
73
|
const viewAttributes = dataFilter.processViewAttributes(viewElement, conversionApi);
|
|
74
74
|
if (viewAttributes) {
|
|
@@ -102,7 +102,7 @@ function viewToModelFigureAttributesConverter(dataFilter) {
|
|
|
102
102
|
}
|
|
103
103
|
function modelToViewMediaAttributeConverter(mediaElementName) {
|
|
104
104
|
return (dispatcher) => {
|
|
105
|
-
addAttributeConversionDispatcherHandler(mediaElementName,
|
|
105
|
+
addAttributeConversionDispatcherHandler(mediaElementName, getHtmlAttributeName(mediaElementName));
|
|
106
106
|
addAttributeConversionDispatcherHandler('figure', 'htmlFigureAttributes');
|
|
107
107
|
function addAttributeConversionDispatcherHandler(elementName, attributeName) {
|
|
108
108
|
dispatcher.on(`attribute:${attributeName}:media`, (evt, data, conversionApi) => {
|
|
@@ -35,7 +35,7 @@ export default class ScriptElementSupport extends Plugin {
|
|
|
35
35
|
const conversion = editor.conversion;
|
|
36
36
|
schema.register('htmlScript', definition.modelSchema);
|
|
37
37
|
schema.extend('htmlScript', {
|
|
38
|
-
allowAttributes: ['
|
|
38
|
+
allowAttributes: ['htmlScriptAttributes', 'htmlContent'],
|
|
39
39
|
isContent: true
|
|
40
40
|
});
|
|
41
41
|
editor.data.registerRawContentMatcher({
|
|
@@ -35,7 +35,7 @@ export default class StyleElementSupport extends Plugin {
|
|
|
35
35
|
const conversion = editor.conversion;
|
|
36
36
|
schema.register('htmlStyle', definition.modelSchema);
|
|
37
37
|
schema.extend('htmlStyle', {
|
|
38
|
-
allowAttributes: ['
|
|
38
|
+
allowAttributes: ['htmlStyleAttributes', 'htmlContent'],
|
|
39
39
|
isContent: true
|
|
40
40
|
});
|
|
41
41
|
editor.data.registerRawContentMatcher({
|
|
@@ -43,7 +43,7 @@ export default class TableElementSupport extends Plugin {
|
|
|
43
43
|
}
|
|
44
44
|
schema.extend('table', {
|
|
45
45
|
allowAttributes: [
|
|
46
|
-
'
|
|
46
|
+
'htmlTableAttributes',
|
|
47
47
|
// Figure, thead and tbody elements don't have model counterparts.
|
|
48
48
|
// We will be preserving attributes on table element using these attribute keys.
|
|
49
49
|
'htmlFigureAttributes', 'htmlTheadAttributes', 'htmlTbodyAttributes'
|
|
@@ -95,7 +95,7 @@ function viewToModelTableAttributeConverter(dataFilter) {
|
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
const viewTableElement = data.viewItem;
|
|
98
|
-
preserveElementAttributes(viewTableElement, '
|
|
98
|
+
preserveElementAttributes(viewTableElement, 'htmlTableAttributes');
|
|
99
99
|
for (const childNode of viewTableElement.getChildren()) {
|
|
100
100
|
if (childNode.is('element', 'thead')) {
|
|
101
101
|
preserveElementAttributes(childNode, 'htmlTheadAttributes');
|
|
@@ -141,7 +141,7 @@ function viewToModelFigureAttributeConverter(dataFilter) {
|
|
|
141
141
|
*/
|
|
142
142
|
function modelToViewTableAttributeConverter() {
|
|
143
143
|
return (dispatcher) => {
|
|
144
|
-
addAttributeConversionDispatcherHandler('table', '
|
|
144
|
+
addAttributeConversionDispatcherHandler('table', 'htmlTableAttributes');
|
|
145
145
|
addAttributeConversionDispatcherHandler('figure', 'htmlFigureAttributes');
|
|
146
146
|
addAttributeConversionDispatcherHandler('thead', 'htmlTheadAttributes');
|
|
147
147
|
addAttributeConversionDispatcherHandler('tbody', 'htmlTbodyAttributes');
|
package/src/schemadefinitions.js
CHANGED
|
@@ -513,17 +513,20 @@ export default {
|
|
|
513
513
|
{
|
|
514
514
|
model: 'htmlLiAttributes',
|
|
515
515
|
view: 'li',
|
|
516
|
-
appliesToBlock: true
|
|
516
|
+
appliesToBlock: true,
|
|
517
|
+
coupledAttribute: 'listItemId'
|
|
517
518
|
},
|
|
518
519
|
{
|
|
519
|
-
model: '
|
|
520
|
+
model: 'htmlOlAttributes',
|
|
520
521
|
view: 'ol',
|
|
521
|
-
appliesToBlock: true
|
|
522
|
+
appliesToBlock: true,
|
|
523
|
+
coupledAttribute: 'listItemId'
|
|
522
524
|
},
|
|
523
525
|
{
|
|
524
|
-
model: '
|
|
526
|
+
model: 'htmlUlAttributes',
|
|
525
527
|
view: 'ul',
|
|
526
|
-
appliesToBlock: true
|
|
528
|
+
appliesToBlock: true,
|
|
529
|
+
coupledAttribute: 'listItemId'
|
|
527
530
|
},
|
|
528
531
|
{
|
|
529
532
|
model: 'htmlFigureAttributes',
|
|
@@ -945,6 +948,7 @@ export default {
|
|
|
945
948
|
view: '$customElement',
|
|
946
949
|
modelSchema: {
|
|
947
950
|
allowWhere: ['$text', '$block'],
|
|
951
|
+
allowAttributesOf: '$inlineObject',
|
|
948
952
|
isInline: true
|
|
949
953
|
}
|
|
950
954
|
}
|
package/src/utils.d.ts
CHANGED
|
@@ -58,4 +58,15 @@ export declare function modifyGhsAttribute(writer: Writer, item: Item | Document
|
|
|
58
58
|
* @param callback That receives a map as an argument and should modify it (add or remove entries).
|
|
59
59
|
*/
|
|
60
60
|
export declare function modifyGhsAttribute(writer: Writer, item: Item | DocumentSelection, ghsAttributeName: string, subject: 'styles', callback: ModifyGhsStylesCallback): void;
|
|
61
|
+
/**
|
|
62
|
+
* Transforms passed string to PascalCase format. Examples:
|
|
63
|
+
* * `div` => `Div`
|
|
64
|
+
* * `h1` => `H1`
|
|
65
|
+
* * `table` => `Table`
|
|
66
|
+
*/
|
|
67
|
+
export declare function toPascalCase(data: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the attribute name of the model element that holds raw HTML attributes.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getHtmlAttributeName(viewElementName: string): string;
|
|
61
72
|
export {};
|
package/src/utils.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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
|
-
import { cloneDeep } from 'lodash-es';
|
|
5
|
+
import { startCase, cloneDeep } from 'lodash-es';
|
|
6
6
|
/**
|
|
7
7
|
* Helper function for the downcast converter. Updates attributes on the given view element.
|
|
8
8
|
*
|
|
@@ -122,3 +122,18 @@ export function modifyGhsAttribute(writer, item, ghsAttributeName, subject, call
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Transforms passed string to PascalCase format. Examples:
|
|
127
|
+
* * `div` => `Div`
|
|
128
|
+
* * `h1` => `H1`
|
|
129
|
+
* * `table` => `Table`
|
|
130
|
+
*/
|
|
131
|
+
export function toPascalCase(data) {
|
|
132
|
+
return startCase(data).replace(/ /g, '');
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Returns the attribute name of the model element that holds raw HTML attributes.
|
|
136
|
+
*/
|
|
137
|
+
export function getHtmlAttributeName(viewElementName) {
|
|
138
|
+
return `html${toPascalCase(viewElementName)}Attributes`;
|
|
139
|
+
}
|