我正在使用CKEDITOR 5与document toolbar进行反应。
当我插入带有媒体嵌入图标的youtube视频时,我可以正确地看到youtube视频,因为html包含一个iframe,但是当我保存它时,html变成如下所示:
<figure class="media">
<oembed url="https://www.youtube.com/watch?v=H08tGjXNHO4"></oembed></figure>上面写着
目前,预览仅适用于CKEditor 5可以预测代码的内容提供者: YouTube、Vimeo、Dailymotion、Spotify等。对于其他提供程序,如Twitter或Instagram,编辑器无法生成代码,而且到目前为止,它不允许从外部oEmbed服务检索此代码。
所以我应该有iframe标签,但它没有。
有什么想法吗?
发布于 2021-01-15 14:14:55
我也有同样的问题。我从CKEDITOR那里得到了嵌入字符串。我使用这个配置解决了这个问题:
editorConfig = {
toolbar: [....],
mediaEmbed: {
previewsInData: true
}
}在本例中,CKEDITOR返回的不是oembed字符串,而是iframe。只需保存它,并显示它的现状。请参阅https://ckeditor.com/docs/ckeditor5/latest/features/media-embed.html#semantic-data-output-default
发布于 2020-03-29 03:01:10
我开始使用reactjs,并且正在使用ckeditor5。目前,这个问题仍然存在。我找不到任何解决办法,但我自己创造了,我希望它能帮助你。
//'embed' code gotten from ckeditor
const embed =
'<figure class="media"><oembed url="https://www.youtube.com/watch?v=N1t6X4p6Q74"></oembed></figure><p>cdcdcd</p><figure class="media"><oembed url="https://www.youtube.com/watch?v=N1t6X4p6Q74"></oembed></figure>';
const stringToHTML = function(str) {
const domContainer = document.createElement("span");
domContainer.innerHTML = str;
return domContainer;
};
const parentEmbed = stringToHTML(embed);
let oldIframe = parentEmbed.querySelectorAll("oembed");
oldIframe = Array.from(oldIframe);
for (const i in oldIframe) {
//Get the url from oembed tag
let url = oldIframe[i].getAttribute("url");
//Replace 'watch?v' with 'embed/'
url = url.replace("watch?v=", "embed/");
//Create a iframe tag
const newIframe = document.createElement("iframe");
newIframe.setAttribute("width", "auto");
newIframe.setAttribute("height", "auto");
newIframe.setAttribute("allowFullScreen", "");
newIframe.setAttribute("frameBorder", 0);
if (url) {
newIframe.setAttribute("src", url);
}
// replace oldIframe with newIframe
oldIframe[i].parentNode.replaceChild(newIframe, oldIframe[i]);
}
const contentToRender = parentEmbed.outerHTML;
return (
<div
key={contentToRender}
dangerouslySetInnerHTML={{ __html: contentToRender }}
/>
);你可以优化代码,但这就是你的想法
//ckeditor内容Ckeditor
//结果内容
https://stackoverflow.com/questions/57490383
复制相似问题