CKEditor 5 - How to insert some HTML (aka. where's the source mode)?

前端 未结 2 1146
有刺的猬
有刺的猬 2021-02-12 09:32

I want to be able to switch from WYSIWYG to plain HTML to e.g. insert IFrame with a Youtube video. So far with the standard CKEditor 5 builds there is no documentation on how t

2条回答
  •  鱼传尺愫
    2021-02-12 10:28

    Yes, it's possible to insert html into 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);
      }  
    

提交回复
热议问题