簡體   English   中英

在 CKeditor 的工具欄中添加不間斷空格按鈕

[英]Add a non-breaking space button to the toolbar in CKeditor

我遇到了 CKeditor (V4.17.0) 的問題。 我在 Symfony (V5) 項目中使用它。 我用這個文檔安裝了所見即所得。 然后我下載了不間斷空間插件,我把它放在了路徑public/bundles/fosckeditor/plugins並配置了我的 yaml 文件:

twig:
    form_themes:
        - '@FOSCKEditor/Form/ckeditor_widget.html.twig'

fos_ck_editor:
    default_config: config
    configs:
        config:
            allowedContent: true
            extraPlugins: 'nbsp'
            removePlugins: 'elementspath,exportpdf,image,media, about'
            toolbar:
                - { name: "styles", items: [ 'Bold', 'Italic', 'Strike' ] }
                - { name: "plugins", items: ['insertNbsp'] }
                - { name: "paragraph", items: ['NumberedList'] }
        plugins:
            nbsp:
                path: 'ckeditor/plugins/nbsp/'
                filename: 'plugin.js'

我的 webpack.config.js:

.copyFiles([
        {
            from: './assets/images',
            to: 'images/[path][name].[ext]',
        },
        {
            from: './node_modules/ckeditor4/',
            to: 'ckeditor/[path][name].[ext]',
            pattern: /\.(js|css)$/,
            includeSubdirectories: false,
        },
        {
            from: './node_modules/ckeditor4/adapters',
            to: 'ckeditor/adapters/[path][name].[ext]'
        },
        {
            from: './node_modules/ckeditor4/lang',
            to: 'ckeditor/lang/[path][name].[ext]'
        },
        {
            from: './node_modules/ckeditor4/skins',
            to: 'ckeditor/skins/[path][name].[ext]'
        },
        {
            from: './node_modules/ckeditor4/vendor',
            to: 'ckeditor/vendor/[path][name].[ext]'
        },
        {
            from: './public/bundles/fosckeditor/plugins',
            to: 'ckeditor/plugins/[path][name].[ext]'
        },
     ])

編輯器出現在頁面上,在我的工具欄中,除了不間斷空間插件之外,我已經得到了我所要求的所有內容。

在此處輸入圖像描述

我怎樣才能插入它?

我不認為這個插件是這樣使用的。 如果我沒記錯的話,您不能將其加載到工具欄中。

您是否可以使用此源代碼而不是原始 plugin.js

CKEDITOR.plugins.add( 'nbsp',
{
    init : function( editor )
    {
    editor.ui.addButton('Insert &nbsp', {
        label: 'Insert  ',
        command: 'insertNbsp',
        toolbar: 'insert',
        icon: this.path + 'icons/icon.png'
    });
        // Insert   if Ctrl+Space is pressed:
        editor.addCommand( 'insertNbsp', {
            exec: function( editor ) {
                editor.insertHtml( ' ', 'text' );
            }
        });
        editor.setKeystroke( CKEDITOR.CTRL + 32 /* space */, 'insertNbsp' );
    }

} );

考慮創建一個圖標文件夾以及您選擇的圖標以在工具欄中查看按鈕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM