Are there any example of creating emptyElement()?

46 Views Asked by At

I created my plugin with the createAttributeElement() method. But, it should not wrap the text. For that I think I have to use createEmptyElement(). So I want to know are there any examples or anything I can refer to?

And I have already saw the image plugin example it is very complicated and the command of image plugin is different from my usage. The image plugin command uses insertContent() or insertObject() method which will remove the selected content from the editor and my requirement is different from that. I want to keep the selected content.

const schema = this.editor.model.schema

        schema.extend('$text', {
            allowAttributes: ['info']
        })

    conversion.attributeToAttribute({
                model: 'info',
                view: 'data-info'
            })
    
    conversion.for('upcast').elementToAttribute({
                view: {
                    name: 'primary',
                    attributes: ['data-info']
                },
                model: {
                    key: 'info',
                    value: (viewElement, conversionApi)=>{
                        const value = viewElement.getAttribute('info')
                        return value;
                    }
                }
            })
            conversion.for('downcast').attributeToElement({
                model: {
                    key: 'info'
                },
                view: (value, {writer})=>{
                    const attributeEl = {}
                    attributeEl['data-info'] = value
    
                    return writer.createAttributeElement('primary', attributeEl)
                },
                converterPriority: 'high'
            })

This is working fine. But, when I do createEmptyElement() in the downcast. It showing view-writer-wrap-invalid-attribute. What should be the way to create the emptyElement?

0

There are 0 best solutions below