Media embed configuration
You can configure the data output format and the list of supported media providers used by the MediaEmbed plugin.
You can configure the data output format of the feature using the config.mediaEmbed.previewsInData option.
This option does not change how the media are displayed inside the editor. The previewable ones will still be displayed with previews. It only affects the output data (see below).
By default, the media embed feature outputs semantic <oembed url="..."> tags for previewable and non-previewable media. That being so, it works best when the application processes (expands) the media on the server side or directly in the frontend, preserving the versatile database representation:
<figure class="media">
<oembed url="https://media-url"></oembed>
</figure>
You can achieve further customization of the semantic data output through the config.mediaEmbed.elementName configuration. As an example, if you set elementName to o-embed:
<figure class="media">
<o-embed url="https://media-url"></o-embed>
</figure>
If elementName is overridden to something other than the default value, the existing <oembed> elements will still be shown for backward compatibility purposes.
Optionally, by setting mediaEmbed.previewsInData to true you can configure the media embed feature to output media in the same way they look in the editor. If the media element is “previewable,” the media preview (HTML) is saved to the database:
<figure class="media">
<div data-oembed-url="https://media-url">
<iframe src="https://media-preview-url"></iframe>
</div>
</figure>
Currently, the preview is only available for content providers for which CKEditor 5 can predict the <iframe> code: YouTube, Vimeo, Dailymotion, Spotify, etc. For other providers like X (Twitter) or Instagram, the editor cannot produce an <iframe> code. It also does not allow retrieving this code from an external oEmbed service. Therefore, for non-previewable media, it produces the default semantic output:
<figure class="media">
<oembed url="https://media-url"></oembed>
</figure>
This means that, unless you limit the list of providers to only those that are previewable, you need to make sure that the media are displayed on your website.
Read more about non-previewable media.
CKEditor 5 comes with several supported media providers that you can extend or alter.
Names of providers with previews:
'dailymotion','spotify','youtube','vimeo'.
Names of providers without previews:
'instagram','twitter','googleMaps','flickr','facebook'.
The default media provider configuration does not support all possible media URLs – only the most common are included. Services like Iframely or Embedly support thousands of media providers. It is up to you to define which you want to allow.
To extend the default list of providers, use config.mediaEmbed.extraProviders.
To remove certain providers, use config.mediaEmbed.removeProviders.
For instance, to leave only the previewable providers, configure this feature as follows:
ClassicEditor
.create( {
// ... Other configuration options ...
mediaEmbed: {
removeProviders: [ 'instagram', 'twitter', 'googleMaps', 'flickr', 'facebook' ]
}
} )
.then( /* ... */ )
.catch( /* ... */ );
To override the default providers, use config.mediaEmbed.providers and define your set according to the provider syntax:
ClassicEditor
.create( {
// ... Other configuration options ...
mediaEmbed: {
providers: [
{
// A URL regular expression or an array of URL regular expressions:
url: /^example\.com\/media\/(\w+)/,
// To be defined only if the media are previewable:
html: match => '...'
},
// More providers.
// ...
]
}
} )
.then( /* ... */ )
.catch( /* ... */ );
You can take inspiration from the default configuration of this feature. You can find it in https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-media-embed/src/mediaembedediting.ts