@ckeditor/ckeditor5-html-support 29.1.0 → 31.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/build/translations/de.js +1 -0
- package/build/translations/es.js +1 -0
- package/build/translations/gl.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/nl.js +1 -0
- package/build/translations/pl.js +1 -0
- package/build/translations/pt-br.js +1 -0
- package/build/translations/ru.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/de.po +21 -0
- package/lang/translations/es.po +21 -0
- package/lang/translations/gl.po +21 -0
- package/lang/translations/id.po +21 -0
- package/lang/translations/it.po +21 -0
- 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 +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 +31 -31
- package/src/converters.js +2 -20
- package/src/datafilter.js +5 -21
- package/src/dataschema.js +45 -1
- package/src/generalhtmlsupport.js +9 -3
- package/src/htmlcomment.js +7 -0
- package/src/integrations/codeblock.js +0 -2
- package/src/integrations/dualcontent.js +0 -2
- package/src/integrations/heading.js +61 -0
- package/src/integrations/image.js +193 -0
- package/src/integrations/mediaembed.js +128 -0
- package/src/integrations/table.js +4 -28
- package/src/schemadefinitions.js +25 -24
- package/CHANGELOG.md +0 -4
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. 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/mediaembed
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
+
|
|
12
|
+
import { setViewAttributes } from '../conversionutils.js';
|
|
13
|
+
import DataFilter from '../datafilter';
|
|
14
|
+
import DataSchema from '../dataschema';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Provides the General HTML Support integration with {@link module:media-embed/mediaembed~MediaEmbed Media Embed} feature.
|
|
18
|
+
*
|
|
19
|
+
* @extends module:core/plugin~Plugin
|
|
20
|
+
*/
|
|
21
|
+
export default class MediaEmbedElementSupport extends Plugin {
|
|
22
|
+
static get requires() {
|
|
23
|
+
return [ DataFilter ];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
init() {
|
|
27
|
+
const editor = this.editor;
|
|
28
|
+
|
|
29
|
+
// Stop here if MediaEmbed plugin is not provided or the integrator wants to output markup with previews as
|
|
30
|
+
// we do not support filtering previews.
|
|
31
|
+
if ( !editor.plugins.has( 'MediaEmbed' ) || editor.config.get( 'mediaEmbed.previewsInData' ) ) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const schema = editor.model.schema;
|
|
36
|
+
const conversion = editor.conversion;
|
|
37
|
+
const dataFilter = this.editor.plugins.get( DataFilter );
|
|
38
|
+
const dataSchema = this.editor.plugins.get( DataSchema );
|
|
39
|
+
const mediaElementName = editor.config.get( 'mediaEmbed.elementName' );
|
|
40
|
+
|
|
41
|
+
// Overwrite GHS schema definition for a given elementName.
|
|
42
|
+
dataSchema.registerBlockElement( {
|
|
43
|
+
model: 'media',
|
|
44
|
+
view: mediaElementName
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
dataFilter.on( `register:${ mediaElementName }`, ( evt, definition ) => {
|
|
48
|
+
if ( definition.model !== 'media' ) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
schema.extend( 'media', {
|
|
53
|
+
allowAttributes: [
|
|
54
|
+
'htmlAttributes',
|
|
55
|
+
'htmlFigureAttributes'
|
|
56
|
+
]
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
conversion.for( 'upcast' ).add( viewToModelMediaAttributesConverter( dataFilter, mediaElementName ) );
|
|
60
|
+
conversion.for( 'dataDowncast' ).add( modelToViewMediaAttributeConverter( mediaElementName ) );
|
|
61
|
+
|
|
62
|
+
evt.stop();
|
|
63
|
+
} );
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function viewToModelMediaAttributesConverter( dataFilter, mediaElementName ) {
|
|
68
|
+
return dispatcher => {
|
|
69
|
+
dispatcher.on( `element:${ mediaElementName }`, upcastMedia );
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
function upcastMedia( evt, data, conversionApi ) {
|
|
73
|
+
const viewMediaElement = data.viewItem;
|
|
74
|
+
const viewParent = viewMediaElement.parent;
|
|
75
|
+
|
|
76
|
+
preserveElementAttributes( viewMediaElement, 'htmlAttributes' );
|
|
77
|
+
|
|
78
|
+
if ( viewParent.is( 'element', 'figure' ) && viewParent.hasClass( 'media' ) ) {
|
|
79
|
+
preserveElementAttributes( viewParent, 'htmlFigureAttributes' );
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function preserveElementAttributes( viewElement, attributeName ) {
|
|
83
|
+
const viewAttributes = dataFilter._consumeAllowedAttributes( viewElement, conversionApi );
|
|
84
|
+
|
|
85
|
+
if ( viewAttributes ) {
|
|
86
|
+
conversionApi.writer.setAttribute( attributeName, viewAttributes, data.modelRange );
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function modelToViewMediaAttributeConverter( mediaElementName ) {
|
|
93
|
+
return dispatcher => {
|
|
94
|
+
addAttributeConversionDispatcherHandler( mediaElementName, 'htmlAttributes' );
|
|
95
|
+
addAttributeConversionDispatcherHandler( 'figure', 'htmlFigureAttributes' );
|
|
96
|
+
|
|
97
|
+
function addAttributeConversionDispatcherHandler( elementName, attributeName ) {
|
|
98
|
+
dispatcher.on( `attribute:${ attributeName }:media`, ( evt, data, conversionApi ) => {
|
|
99
|
+
if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const containerElement = conversionApi.mapper.toViewElement( data.item );
|
|
104
|
+
const viewElement = getDescendantElement( conversionApi.writer, containerElement, elementName );
|
|
105
|
+
|
|
106
|
+
setViewAttributes( conversionApi.writer, data.attributeNewValue, viewElement );
|
|
107
|
+
} );
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Returns the first view element descendant matching the given view name.
|
|
113
|
+
// Includes view element itself.
|
|
114
|
+
//
|
|
115
|
+
// @private
|
|
116
|
+
// @param {module:engine/view/downcastwriter~DowncastWriter} writer
|
|
117
|
+
// @param {module:engine/view/element~Element} containerElement
|
|
118
|
+
// @param {String} elementName
|
|
119
|
+
// @returns {module:engine/view/element~Element|null}
|
|
120
|
+
function getDescendantElement( writer, containerElement, elementName ) {
|
|
121
|
+
const range = writer.createRangeOn( containerElement );
|
|
122
|
+
|
|
123
|
+
for ( const { item } of range.getWalker() ) {
|
|
124
|
+
if ( item.is( 'element', elementName ) ) {
|
|
125
|
+
return item;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -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
|
@@ -51,18 +51,6 @@
|
|
|
51
51
|
export default {
|
|
52
52
|
block: [
|
|
53
53
|
// 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
54
|
{
|
|
67
55
|
model: 'codeBlock',
|
|
68
56
|
view: 'pre'
|
|
@@ -111,6 +99,14 @@ export default {
|
|
|
111
99
|
model: 'caption',
|
|
112
100
|
view: 'figcaption'
|
|
113
101
|
},
|
|
102
|
+
{
|
|
103
|
+
model: 'imageBlock',
|
|
104
|
+
view: 'img'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
model: 'imageInline',
|
|
108
|
+
view: 'img'
|
|
109
|
+
},
|
|
114
110
|
|
|
115
111
|
// Compatibility features
|
|
116
112
|
{
|
|
@@ -256,7 +252,7 @@ export default {
|
|
|
256
252
|
}
|
|
257
253
|
},
|
|
258
254
|
{
|
|
259
|
-
model: '
|
|
255
|
+
model: 'htmlSummary',
|
|
260
256
|
view: 'summary',
|
|
261
257
|
modelSchema: {
|
|
262
258
|
allowChildren: '$text',
|
|
@@ -318,15 +314,12 @@ export default {
|
|
|
318
314
|
view: 'hgroup',
|
|
319
315
|
modelSchema: {
|
|
320
316
|
allowChildren: [
|
|
321
|
-
'
|
|
322
|
-
'
|
|
323
|
-
'
|
|
324
|
-
'
|
|
325
|
-
'
|
|
326
|
-
'
|
|
327
|
-
'heading1',
|
|
328
|
-
'heading2',
|
|
329
|
-
'heading3'
|
|
317
|
+
'htmlH1',
|
|
318
|
+
'htmlH2',
|
|
319
|
+
'htmlH3',
|
|
320
|
+
'htmlH4',
|
|
321
|
+
'htmlH5',
|
|
322
|
+
'htmlH6'
|
|
330
323
|
],
|
|
331
324
|
isBlock: true
|
|
332
325
|
}
|
|
@@ -633,7 +626,7 @@ export default {
|
|
|
633
626
|
copyOnEnter: true
|
|
634
627
|
}
|
|
635
628
|
},
|
|
636
|
-
// TODO According to HTML-spec can behave as div-like element,
|
|
629
|
+
// TODO According to HTML-spec can behave as div-like element, although CKE4 only handles it as an inline element.
|
|
637
630
|
{
|
|
638
631
|
model: 'htmlDel',
|
|
639
632
|
view: 'del',
|
|
@@ -641,7 +634,7 @@ export default {
|
|
|
641
634
|
copyOnEnter: true
|
|
642
635
|
}
|
|
643
636
|
},
|
|
644
|
-
// TODO According to HTML-spec can behave as div-like element,
|
|
637
|
+
// TODO According to HTML-spec can behave as div-like element, although CKE4 only handles it as an inline element.
|
|
645
638
|
{
|
|
646
639
|
model: 'htmlIns',
|
|
647
640
|
view: 'ins',
|
|
@@ -788,6 +781,14 @@ export default {
|
|
|
788
781
|
inheritAllFrom: '$htmlObjectInline'
|
|
789
782
|
}
|
|
790
783
|
},
|
|
784
|
+
{
|
|
785
|
+
model: 'htmlOembed',
|
|
786
|
+
view: 'oembed',
|
|
787
|
+
isObject: true,
|
|
788
|
+
modelSchema: {
|
|
789
|
+
inheritAllFrom: '$htmlObjectInline'
|
|
790
|
+
}
|
|
791
|
+
},
|
|
791
792
|
{
|
|
792
793
|
model: 'htmlAudio',
|
|
793
794
|
view: 'audio',
|
package/CHANGELOG.md
DELETED