admin管理员组

文章数量:1316532

I am using Django CKEditor5 in my admin panel. When I'm trying to insert a html code using "Source Edit" feature,

it doesn't apply any style and transforms automatically after clicking "Source" button again into this:

I already tried the GeneralHtmlSupport from documentation: .html

My ckeditor config looks like this

       ClassicEditor.create(
        editorEl,
        config,
        {
            plugins: [GeneralHtmlSupport, SourceEditing, Undo, Alignment, Image, ImageResizeEditing, ImageResizeHandles],
            htmlSupport: {
                allow: [
                    {
                        name: /.*/,
                        attributes: true,
                        classes: true,
                        styles: true
                    }
                ]
            },
            image: {
                resizeUnit: "%",
                styles: {
                    options: [
                        { name: 'Resize', title: 'Resize', className: 'Resize' },
                    ]
                },
            },
            htmlSupport: true,
            allowedContent: true
        }
    ).then(editor => {
        const textarea = document.querySelector(`#${editorEl.id}`);

        editor.model.document.on('change:data', () => {
            textarea.value = editor.getData();
        });
        if (editor.plugins.has('WordCount')) {
            const wordCountPlugin = editor.plugins.get('WordCount');
            const wordCountWrapper = element.querySelector(`#${script_id}-word-count`);
            wordCountWrapper.innerHTML = '';
            wordCountWrapper.appendChild(wordCountPlugin.wordCountContainer);
        }
        editors[editorEl.id] = editor;
        if (callbacks[editorEl.id]) {
                callbacks[editorEl.id](editor);
            }
    }).catch(error => {
        console.error((error));
    });
    editorEl.setAttribute('data-processed', '1');
});
window.editors = editors;

I am using Django CKEditor5 in my admin panel. When I'm trying to insert a html code using "Source Edit" feature,

it doesn't apply any style and transforms automatically after clicking "Source" button again into this:

I already tried the GeneralHtmlSupport from documentation: https://ckeditor/docs/ckeditor5/latest/features/html/general-html-support.html

My ckeditor config looks like this

       ClassicEditor.create(
        editorEl,
        config,
        {
            plugins: [GeneralHtmlSupport, SourceEditing, Undo, Alignment, Image, ImageResizeEditing, ImageResizeHandles],
            htmlSupport: {
                allow: [
                    {
                        name: /.*/,
                        attributes: true,
                        classes: true,
                        styles: true
                    }
                ]
            },
            image: {
                resizeUnit: "%",
                styles: {
                    options: [
                        { name: 'Resize', title: 'Resize', className: 'Resize' },
                    ]
                },
            },
            htmlSupport: true,
            allowedContent: true
        }
    ).then(editor => {
        const textarea = document.querySelector(`#${editorEl.id}`);

        editor.model.document.on('change:data', () => {
            textarea.value = editor.getData();
        });
        if (editor.plugins.has('WordCount')) {
            const wordCountPlugin = editor.plugins.get('WordCount');
            const wordCountWrapper = element.querySelector(`#${script_id}-word-count`);
            wordCountWrapper.innerHTML = '';
            wordCountWrapper.appendChild(wordCountPlugin.wordCountContainer);
        }
        editors[editorEl.id] = editor;
        if (callbacks[editorEl.id]) {
                callbacks[editorEl.id](editor);
            }
    }).catch(error => {
        console.error((error));
    });
    editorEl.setAttribute('data-processed', '1');
});
window.editors = editors;
Share Improve this question edited Jan 31 at 7:20 neonbones asked Jan 30 at 9:48 neonbonesneonbones 234 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

did you try this in CKEDITOR_5_CONFIGS

...
"extends": {
        ...
        "htmlSupport": {"allow": [{"name": "/.*/", "attributes": True, "classes": True, "styles": True}]},
       ...
}
...

本文标签: ckeditorDjangoCKEditor5 Source Editing Feature Doesn39t WorkStack Overflow