C
C
cadaver2019-11-17 02:49:23
CKEditor
cadaver, 2019-11-17 02:49:23

How to save inserted tag in CKEDITOR5?

I'm trying to do it according to the manual.

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import Widget from '@ckeditor/ckeditor5-widget/src/widget';
import InsertTooltipCommand from './inserttooltipcommand';
import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils';

export default class TooltipEditing extends Plugin {
    static get requires() {
        return [ Widget ];
    }

    init() {
        this._defineSchema();
        this._defineConverters();

        this.editor.commands.add('insertTooltip', new InsertTooltipCommand(this.editor));
    }
    
    

    _defineSchema() {
        const schema = this.editor.model.schema;

        schema.register('tooltip', {
            // Behaves like a self-contained object (e.g. an image).
            isObject: true,
            isInline: true,
            allowIn: 'paragraph',
            allowAttributes: [ 'class', 'content' ]
        });
    }

    _defineConverters() {
        const conversion = this.editor.conversion;
        
        
        conversion.for('editingDowncast').elementToElement({
            model: 'tooltip',
            view: (modelElement, downcastWriter) => {
                const title = prompt( 'Текст' );
                const header = prompt( 'Заголовок' );
                const content = prompt( 'Содержание' );
                
                const div = downcastWriter.createContainerElement('span', { class: 'p-post__tooltip', content: '<button class="b-button _plain" type="button" > <span class="b-icon _close"></span> </button> <h3>'+header+'</h3><p>'+content+'</p>' });
                const text = downcastWriter.createText(title);
                downcastWriter.insert(downcastWriter.createPositionAt(div, 0), text);
                return toWidget(div, downcastWriter, { label: 'tooltip widget' });
            }
        });
    }
}

https://pix.my/FoyQ3J is inserted into the content body itself, but after saving there is nothing.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question