如何在 CKEditor 5

问题描述

我已经注册了以下模型:

const schema = this.editor.model.schema
const conversion = this.editor.conversion

schema.register('cms:gallery',{
    allowWhere: '$block',isObject: true,})

conversion.for('upcast').elementtoElement({
    model: 'cms:gallery',view: {
        name: 'section',classes: 'cms-gallery'
    },})

conversion.for('dataDowncast').elementtoElement({
    model: 'cms:gallery',})
conversion.for('editingDowncast').elementtoElement({
    model: 'cms:gallery',view: (modelElement,{ writer: viewWriter }) => {
        const section = viewWriter.createContainerElement('section',{class: 'cms-gallery'})

        return toWidget(section,viewWriter,{ label: 'gallery widget' })
    }
})

例如,在初始化时,编辑器的内容是:

<section class="cms-gallery"></section>

我可以将模型作为这样的字符串获取

const stringModel = editor.data.processor.toData(editor.data.parse(editor.data.get())) // Result: '<cms:gallery></cms:gallery>'

但是如何从字符串中设置编辑器模型的值?

const stringModel = '<cms:gallery></cms:gallery>' // How convert this in CKeditor view???

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)