如何允许CKEditor自定义构建中的所有内容,我想进行内联样式,但未授权

发布于 2025-02-12 21:56:09 字数 2538 浏览 0 评论 0原文

这是我的ckeditor.js文件,

import ClassicEditorBase from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';

import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';

//..

export default class ClassicEditor extends ClassicEditorBase {}

// Plugins to include in the build.
ClassicEditor.builtinPlugins = [
    Essentials,
    UploadAdapter,
    Autoformat,
    Bold,
    //..
    
  PluginProcedure,
  InsertTable
];

// Editor configuration.
ClassicEditor.defaultConfig = {

    toolbar: {
        items: [
            'heading',
            '|',
            'bold',
            'italic',
            'link',
      'table',
      'essentials',
      'procedurePlugin',
      'insertTable'

        ]
    },
    image: {
        toolbar: [
            'imageStyle:inline',
            'imageStyle:block',
            'imageStyle:side',
            '|',
            'toggleImageCaption',
            'imageTextAlternative'
        ]
    },
    table: {
        contentToolbar: [
            'tableColumn',
            'tableRow',
            'mergeTableCells'
        ]
    },

    // This value must be kept in sync with the language defined in webpack.config.js.
    language: 'en'
};

我想使用setData()在自定义插件中添加inline css 但是内联样式或类不起作用

的是我的插件代码:

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import { getPosition, insertData } from './utils';

import TableIcon from './icons/table-icon.svg';
import { data } from './data-procedure';



export default class PluginProcedure extends Plugin {
    init() {
        const editor = this.editor;

        editor.ui.componentFactory.add( 'procedurePlugin', locale => {
            const view = new ButtonView( locale );

            view.set( {
                label: 'Procédure prélèvements ',
                withText: false,
                tooltip: true,
                icon: TableIcon
            } );

            // Callback executed once the image is clicked.
            view.on( 'execute', () => {


                editor.model.change( writer => {

                    editor.setData(" <h1 style="color:red"> <h1>")
                    //not works


                } );
            } );

            return view;
        } );
    }

}

我Google它,我发现需要配置以允许内容

  allowedContent: true
extraAllowedContent: "* [*]",

它仍然无法工作,因为我不知道如何添加配置规则, 我从事自定义构建工作,请提供帮助! 或者如果有榜样。

this is my ckeditor.js file

import ClassicEditorBase from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';

import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';

//..

export default class ClassicEditor extends ClassicEditorBase {}

// Plugins to include in the build.
ClassicEditor.builtinPlugins = [
    Essentials,
    UploadAdapter,
    Autoformat,
    Bold,
    //..
    
  PluginProcedure,
  InsertTable
];

// Editor configuration.
ClassicEditor.defaultConfig = {

    toolbar: {
        items: [
            'heading',
            '|',
            'bold',
            'italic',
            'link',
      'table',
      'essentials',
      'procedurePlugin',
      'insertTable'

        ]
    },
    image: {
        toolbar: [
            'imageStyle:inline',
            'imageStyle:block',
            'imageStyle:side',
            '|',
            'toggleImageCaption',
            'imageTextAlternative'
        ]
    },
    table: {
        contentToolbar: [
            'tableColumn',
            'tableRow',
            'mergeTableCells'
        ]
    },

    // This value must be kept in sync with the language defined in webpack.config.js.
    language: 'en'
};

i want to add inline css in my custom plugin using setData()
but inline styling or classes not works

this is my plugin code :

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import { getPosition, insertData } from './utils';

import TableIcon from './icons/table-icon.svg';
import { data } from './data-procedure';



export default class PluginProcedure extends Plugin {
    init() {
        const editor = this.editor;

        editor.ui.componentFactory.add( 'procedurePlugin', locale => {
            const view = new ButtonView( locale );

            view.set( {
                label: 'Procédure prélèvements ',
                withText: false,
                tooltip: true,
                icon: TableIcon
            } );

            // Callback executed once the image is clicked.
            view.on( 'execute', () => {


                editor.model.change( writer => {

                    editor.setData(" <h1 style="color:red"> <h1>")
                    //not works


                } );
            } );

            return view;
        } );
    }

}

i google it and i find that require a configuration to allow content

  allowedContent: true
extraAllowedContent: "* [*]",

it still not works because i don't know how to add configuration rules ,
i work on custom build , please help !
or if there is exemples .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欢烬 2025-02-19 21:56:09
htmlSupport:  { allow: [
        {
            name: 'iframe',
            attributes: true,
            classes: true,
            styles: true
        }
    ]},
htmlSupport:  { allow: [
        {
            name: 'iframe',
            attributes: true,
            classes: true,
            styles: true
        }
    ]},
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文