javascript - CKEditor 5 - 如何插入一些 HTML(也就是源模式在哪里)?

标签 javascript ckeditor ckeditor5

我希望能够从所见即所得切换到纯 HTML,例如插入 IFrame Youtube 视频。到目前为止,对于标准的 CKEditor 5 构建,没有关于如何做到这一点的文档。

有没有等同于Source Editing Area的插件但适用于 CKEditor 5?

最佳答案

是的,可以将 html 插入 CKEditor5:

  insertHTML(html:string) {

    // See: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/faq.html#where-are-the-editorinserthtml-and-editorinserttext-methods-how-to-insert-some-content
    const viewFragment = this.editor.data.processor.toView( html );
    const modelFragment = this.editor.data.toModel( viewFragment );
    this.editor.model.insertContent(modelFragment);
  }  

关于javascript - CKEditor 5 - 如何插入一些 HTML(也就是源模式在哪里)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47729450/

相关文章:

javascript - 异步代码中需要同步

javascript - 如何向 roundSlider 小部件添加启用/禁用按钮?

javascript - CKEDITOR 初始化时没有为任何对话框调用“dialogDefinition”事件?

javascript - ckeditor 5 在线生成器未显示

vue.js - 如何在 Nuxt 中正确配置 ckeditor5?

javascript - 显示警报时在后台运行代码

javascript - 如何检测两个元素是否接触

ckeditor - 有没有办法在ckeditor插件中使用默认 "icons"?

ajax - CKEditor - 将 ckeditor 添加到 ajax 创建的文本区域