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

前端 未结 2 1885
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-12 09:48

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:34

    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);
      }  
    

提交回复
热议问题