@ckeditor/ckeditor5-html-support 29.2.0 → 32.0.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 +2 -2
- package/build/html-support.js +3 -3
- package/build/translations/cs.js +1 -0
- package/build/translations/es.js +1 -0
- package/build/translations/id.js +1 -0
- package/build/translations/nl.js +1 -0
- package/build/translations/pl.js +1 -0
- package/build/translations/pt-br.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/zh.js +1 -0
- package/lang/translations/cs.po +21 -0
- package/lang/translations/de.po +1 -1
- package/lang/translations/en.po +1 -1
- package/lang/translations/es.po +21 -0
- package/lang/translations/gl.po +1 -1
- package/lang/translations/hu.po +1 -1
- package/lang/translations/id.po +21 -0
- package/lang/translations/it.po +1 -1
- package/lang/translations/nl.po +21 -0
- package/lang/translations/pl.po +21 -0
- package/lang/translations/pt-br.po +21 -0
- package/lang/translations/ru.po +1 -1
- package/lang/translations/sk.po +21 -0
- package/lang/translations/sr-latn.po +21 -0
- package/lang/translations/sr.po +21 -0
- package/lang/translations/zh.po +21 -0
- package/package.json +34 -34
- package/src/conversionutils.js +1 -1
- package/src/converters.js +3 -21
- package/src/datafilter.js +6 -22
- package/src/dataschema.js +46 -2
- package/src/generalhtmlsupport.js +11 -5
- package/src/htmlcomment.js +1 -1
- package/src/index.js +1 -1
- package/src/integrations/codeblock.js +1 -3
- package/src/integrations/dualcontent.js +1 -3
- package/src/integrations/heading.js +61 -0
- package/src/integrations/image.js +193 -0
- package/src/integrations/mediaembed.js +11 -43
- package/src/integrations/script.js +73 -0
- package/src/integrations/table.js +5 -29
- package/src/schemadefinitions.js +26 -26
- package/CHANGELOG.md +0 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, 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
5
|
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
11
|
|
|
12
|
-
import { disallowedAttributesConverter } from '../converters';
|
|
13
12
|
import { setViewAttributes } from '../conversionutils.js';
|
|
14
13
|
import DataFilter from '../datafilter';
|
|
15
14
|
import DataSchema from '../dataschema';
|
|
@@ -57,7 +56,6 @@ export default class MediaEmbedElementSupport extends Plugin {
|
|
|
57
56
|
]
|
|
58
57
|
} );
|
|
59
58
|
|
|
60
|
-
conversion.for( 'upcast' ).add( disallowedAttributesConverter( definition, dataFilter ) );
|
|
61
59
|
conversion.for( 'upcast' ).add( viewToModelMediaAttributesConverter( dataFilter, mediaElementName ) );
|
|
62
60
|
conversion.for( 'dataDowncast' ).add( modelToViewMediaAttributeConverter( mediaElementName ) );
|
|
63
61
|
|
|
@@ -68,39 +66,18 @@ export default class MediaEmbedElementSupport extends Plugin {
|
|
|
68
66
|
|
|
69
67
|
function viewToModelMediaAttributesConverter( dataFilter, mediaElementName ) {
|
|
70
68
|
return dispatcher => {
|
|
71
|
-
// Here we want to be the first to convert (and consume) the figure element, otherwise GHS can pick it up and
|
|
72
|
-
// convert it to generic `htmlFigure`.
|
|
73
|
-
dispatcher.on( 'element:figure', upcastFigure, { priority: 'high' } );
|
|
74
|
-
|
|
75
|
-
// Handle media elements without `<figure>` container.
|
|
76
69
|
dispatcher.on( `element:${ mediaElementName }`, upcastMedia );
|
|
77
70
|
};
|
|
78
71
|
|
|
79
|
-
function
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
// Convert only "media figure" elements.
|
|
83
|
-
if ( !conversionApi.consumable.test( viewFigureElement, { name: true, classes: 'media' } ) ) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Find media element.
|
|
88
|
-
const viewMediaElement = Array.from( viewFigureElement.getChildren() )
|
|
89
|
-
.find( item => item.is( 'element', mediaElementName ) );
|
|
90
|
-
|
|
91
|
-
// Do not convert if media element is absent.
|
|
92
|
-
if ( !viewMediaElement ) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Convert just the media element.
|
|
97
|
-
Object.assign( data, conversionApi.convertItem( viewMediaElement, data.modelCursor ) );
|
|
72
|
+
function upcastMedia( evt, data, conversionApi ) {
|
|
73
|
+
const viewMediaElement = data.viewItem;
|
|
74
|
+
const viewParent = viewMediaElement.parent;
|
|
98
75
|
|
|
99
76
|
preserveElementAttributes( viewMediaElement, 'htmlAttributes' );
|
|
100
|
-
preserveElementAttributes( viewFigureElement, 'htmlFigureAttributes' );
|
|
101
77
|
|
|
102
|
-
|
|
103
|
-
|
|
78
|
+
if ( viewParent.is( 'element', 'figure' ) && viewParent.hasClass( 'media' ) ) {
|
|
79
|
+
preserveElementAttributes( viewParent, 'htmlFigureAttributes' );
|
|
80
|
+
}
|
|
104
81
|
|
|
105
82
|
function preserveElementAttributes( viewElement, attributeName ) {
|
|
106
83
|
const viewAttributes = dataFilter._consumeAllowedAttributes( viewElement, conversionApi );
|
|
@@ -110,15 +87,6 @@ function viewToModelMediaAttributesConverter( dataFilter, mediaElementName ) {
|
|
|
110
87
|
}
|
|
111
88
|
}
|
|
112
89
|
}
|
|
113
|
-
|
|
114
|
-
function upcastMedia( evt, data, conversionApi ) {
|
|
115
|
-
const viewMediaElement = data.viewItem;
|
|
116
|
-
const viewAttributes = dataFilter._consumeAllowedAttributes( viewMediaElement, conversionApi );
|
|
117
|
-
|
|
118
|
-
if ( viewAttributes ) {
|
|
119
|
-
conversionApi.writer.setAttribute( 'htmlAttributes', viewAttributes, data.modelRange );
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
90
|
}
|
|
123
91
|
|
|
124
92
|
function modelToViewMediaAttributeConverter( mediaElementName ) {
|
|
@@ -133,7 +101,7 @@ function modelToViewMediaAttributeConverter( mediaElementName ) {
|
|
|
133
101
|
}
|
|
134
102
|
|
|
135
103
|
const containerElement = conversionApi.mapper.toViewElement( data.item );
|
|
136
|
-
const viewElement = getDescendantElement( conversionApi, containerElement, elementName );
|
|
104
|
+
const viewElement = getDescendantElement( conversionApi.writer, containerElement, elementName );
|
|
137
105
|
|
|
138
106
|
setViewAttributes( conversionApi.writer, data.attributeNewValue, viewElement );
|
|
139
107
|
} );
|
|
@@ -145,12 +113,12 @@ function modelToViewMediaAttributeConverter( mediaElementName ) {
|
|
|
145
113
|
// Includes view element itself.
|
|
146
114
|
//
|
|
147
115
|
// @private
|
|
148
|
-
// @param {module:engine/
|
|
116
|
+
// @param {module:engine/view/downcastwriter~DowncastWriter} writer
|
|
149
117
|
// @param {module:engine/view/element~Element} containerElement
|
|
150
118
|
// @param {String} elementName
|
|
151
119
|
// @returns {module:engine/view/element~Element|null}
|
|
152
|
-
function getDescendantElement(
|
|
153
|
-
const range =
|
|
120
|
+
function getDescendantElement( writer, containerElement, elementName ) {
|
|
121
|
+
const range = writer.createRangeOn( containerElement );
|
|
154
122
|
|
|
155
123
|
for ( const { item } of range.getWalker() ) {
|
|
156
124
|
if ( item.is( 'element', elementName ) ) {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2022, 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
|
+
/**
|
|
7
|
+
* @module html-support/integrations/script
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
+
import {
|
|
12
|
+
createObjectView,
|
|
13
|
+
modelToViewBlockAttributeConverter,
|
|
14
|
+
viewToModelBlockAttributeConverter,
|
|
15
|
+
viewToModelObjectConverter
|
|
16
|
+
} from '../converters.js';
|
|
17
|
+
|
|
18
|
+
import DataFilter from '../datafilter';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Provides the General HTML Support for `script` elements.
|
|
22
|
+
*
|
|
23
|
+
* @extends module:core/plugin~Plugin
|
|
24
|
+
*/
|
|
25
|
+
export default class ScriptElementSupport extends Plugin {
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
static get requires() {
|
|
30
|
+
return [ DataFilter ];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/
|
|
36
|
+
init() {
|
|
37
|
+
const dataFilter = this.editor.plugins.get( DataFilter );
|
|
38
|
+
|
|
39
|
+
dataFilter.on( 'register:script', ( evt, definition ) => {
|
|
40
|
+
const editor = this.editor;
|
|
41
|
+
const schema = editor.model.schema;
|
|
42
|
+
const conversion = editor.conversion;
|
|
43
|
+
|
|
44
|
+
schema.register( 'htmlScript', definition.modelSchema );
|
|
45
|
+
|
|
46
|
+
schema.extend( 'htmlScript', {
|
|
47
|
+
allowAttributes: [ 'htmlAttributes', 'htmlContent' ]
|
|
48
|
+
} );
|
|
49
|
+
|
|
50
|
+
editor.data.registerRawContentMatcher( {
|
|
51
|
+
name: 'script'
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
conversion.for( 'upcast' ).elementToElement( {
|
|
55
|
+
view: 'script',
|
|
56
|
+
model: viewToModelObjectConverter( definition )
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
conversion.for( 'upcast' ).add( viewToModelBlockAttributeConverter( definition, dataFilter ) );
|
|
60
|
+
|
|
61
|
+
conversion.for( 'downcast' ).elementToElement( {
|
|
62
|
+
model: 'htmlScript',
|
|
63
|
+
view: ( modelElement, { writer } ) => {
|
|
64
|
+
return createObjectView( 'script', modelElement, writer );
|
|
65
|
+
}
|
|
66
|
+
} );
|
|
67
|
+
|
|
68
|
+
conversion.for( 'downcast' ).add( modelToViewBlockAttributeConverter( definition ) );
|
|
69
|
+
|
|
70
|
+
evt.stop();
|
|
71
|
+
} );
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, 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
5
|
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
-
import { disallowedAttributesConverter } from '../converters';
|
|
12
11
|
import { setViewAttributes } from '../conversionutils.js';
|
|
13
12
|
|
|
14
13
|
import DataFilter from '../datafilter';
|
|
@@ -54,16 +53,11 @@ export default class TableElementSupport extends Plugin {
|
|
|
54
53
|
]
|
|
55
54
|
} );
|
|
56
55
|
|
|
57
|
-
conversion.for( 'upcast' ).add( disallowedAttributesConverter( definition, dataFilter ) );
|
|
58
56
|
conversion.for( 'upcast' ).add( viewToModelTableAttributeConverter( dataFilter ) );
|
|
59
57
|
conversion.for( 'downcast' ).add( modelToViewTableAttributeConverter() );
|
|
60
58
|
|
|
61
59
|
evt.stop();
|
|
62
60
|
} );
|
|
63
|
-
|
|
64
|
-
dataFilter.on( 'register:figure', () => {
|
|
65
|
-
conversion.for( 'upcast' ).add( consumeTableFigureConverter() );
|
|
66
|
-
} );
|
|
67
61
|
}
|
|
68
62
|
}
|
|
69
63
|
|
|
@@ -125,7 +119,7 @@ function modelToViewTableAttributeConverter() {
|
|
|
125
119
|
}
|
|
126
120
|
|
|
127
121
|
const containerElement = conversionApi.mapper.toViewElement( data.item );
|
|
128
|
-
const viewElement = getDescendantElement( conversionApi, containerElement, elementName );
|
|
122
|
+
const viewElement = getDescendantElement( conversionApi.writer, containerElement, elementName );
|
|
129
123
|
|
|
130
124
|
setViewAttributes( conversionApi.writer, data.attributeNewValue, viewElement );
|
|
131
125
|
} );
|
|
@@ -137,12 +131,12 @@ function modelToViewTableAttributeConverter() {
|
|
|
137
131
|
// Includes view element itself.
|
|
138
132
|
//
|
|
139
133
|
// @private
|
|
140
|
-
// @param {module:engine/
|
|
134
|
+
// @param {module:engine/view/downcastwriter~DowncastWriter} writer
|
|
141
135
|
// @param {module:engine/view/element~Element} containerElement
|
|
142
136
|
// @param {String} elementName
|
|
143
137
|
// @returns {module:engine/view/element~Element|null}
|
|
144
|
-
function getDescendantElement(
|
|
145
|
-
const range =
|
|
138
|
+
function getDescendantElement( writer, containerElement, elementName ) {
|
|
139
|
+
const range = writer.createRangeOn( containerElement );
|
|
146
140
|
|
|
147
141
|
for ( const { item } of range.getWalker() ) {
|
|
148
142
|
if ( item.is( 'element', elementName ) ) {
|
|
@@ -150,21 +144,3 @@ function getDescendantElement( conversionApi, containerElement, elementName ) {
|
|
|
150
144
|
}
|
|
151
145
|
}
|
|
152
146
|
}
|
|
153
|
-
|
|
154
|
-
// Conversion helper consuming figure element if it's a part of the Table feature
|
|
155
|
-
// to avoid elementToElement conversion for figure with that context.
|
|
156
|
-
//
|
|
157
|
-
// @private
|
|
158
|
-
// @returns {Function} Returns a conversion callback.
|
|
159
|
-
function consumeTableFigureConverter() {
|
|
160
|
-
return dispatcher => {
|
|
161
|
-
dispatcher.on( 'element:figure', ( evt, data, conversionApi ) => {
|
|
162
|
-
for ( const childNode of data.viewItem.getChildren() ) {
|
|
163
|
-
if ( childNode.is( 'element', 'table' ) ) {
|
|
164
|
-
conversionApi.consumable.consume( data.viewItem, { name: true } );
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
} );
|
|
169
|
-
};
|
|
170
|
-
}
|
package/src/schemadefinitions.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, 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
5
|
|
|
@@ -46,23 +46,10 @@
|
|
|
46
46
|
//
|
|
47
47
|
// Skipped hidden elements:
|
|
48
48
|
// noscript
|
|
49
|
-
// script
|
|
50
49
|
|
|
51
50
|
export default {
|
|
52
51
|
block: [
|
|
53
52
|
// Existing features
|
|
54
|
-
{
|
|
55
|
-
model: 'heading1',
|
|
56
|
-
view: 'h2'
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
model: 'heading2',
|
|
60
|
-
view: 'h3'
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
model: 'heading3',
|
|
64
|
-
view: 'h4'
|
|
65
|
-
},
|
|
66
53
|
{
|
|
67
54
|
model: 'codeBlock',
|
|
68
55
|
view: 'pre'
|
|
@@ -111,6 +98,14 @@ export default {
|
|
|
111
98
|
model: 'caption',
|
|
112
99
|
view: 'figcaption'
|
|
113
100
|
},
|
|
101
|
+
{
|
|
102
|
+
model: 'imageBlock',
|
|
103
|
+
view: 'img'
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
model: 'imageInline',
|
|
107
|
+
view: 'img'
|
|
108
|
+
},
|
|
114
109
|
|
|
115
110
|
// Compatibility features
|
|
116
111
|
{
|
|
@@ -256,7 +251,7 @@ export default {
|
|
|
256
251
|
}
|
|
257
252
|
},
|
|
258
253
|
{
|
|
259
|
-
model: '
|
|
254
|
+
model: 'htmlSummary',
|
|
260
255
|
view: 'summary',
|
|
261
256
|
modelSchema: {
|
|
262
257
|
allowChildren: '$text',
|
|
@@ -318,15 +313,12 @@ export default {
|
|
|
318
313
|
view: 'hgroup',
|
|
319
314
|
modelSchema: {
|
|
320
315
|
allowChildren: [
|
|
321
|
-
'
|
|
322
|
-
'
|
|
323
|
-
'
|
|
324
|
-
'
|
|
325
|
-
'
|
|
326
|
-
'
|
|
327
|
-
'heading1',
|
|
328
|
-
'heading2',
|
|
329
|
-
'heading3'
|
|
316
|
+
'htmlH1',
|
|
317
|
+
'htmlH2',
|
|
318
|
+
'htmlH3',
|
|
319
|
+
'htmlH4',
|
|
320
|
+
'htmlH5',
|
|
321
|
+
'htmlH6'
|
|
330
322
|
],
|
|
331
323
|
isBlock: true
|
|
332
324
|
}
|
|
@@ -633,7 +625,7 @@ export default {
|
|
|
633
625
|
copyOnEnter: true
|
|
634
626
|
}
|
|
635
627
|
},
|
|
636
|
-
// TODO According to HTML-spec can behave as div-like element,
|
|
628
|
+
// TODO According to HTML-spec can behave as div-like element, although CKE4 only handles it as an inline element.
|
|
637
629
|
{
|
|
638
630
|
model: 'htmlDel',
|
|
639
631
|
view: 'del',
|
|
@@ -641,7 +633,7 @@ export default {
|
|
|
641
633
|
copyOnEnter: true
|
|
642
634
|
}
|
|
643
635
|
},
|
|
644
|
-
// TODO According to HTML-spec can behave as div-like element,
|
|
636
|
+
// TODO According to HTML-spec can behave as div-like element, although CKE4 only handles it as an inline element.
|
|
645
637
|
{
|
|
646
638
|
model: 'htmlIns',
|
|
647
639
|
view: 'ins',
|
|
@@ -839,6 +831,14 @@ export default {
|
|
|
839
831
|
modelSchema: {
|
|
840
832
|
inheritAllFrom: '$htmlObjectInline'
|
|
841
833
|
}
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
model: 'htmlScript',
|
|
837
|
+
view: 'script',
|
|
838
|
+
modelSchema: {
|
|
839
|
+
allowWhere: [ '$text', '$block' ],
|
|
840
|
+
isInline: true
|
|
841
|
+
}
|
|
842
842
|
}
|
|
843
843
|
]
|
|
844
844
|
};
|
package/CHANGELOG.md
DELETED