如何在ckeditor中添加代码片段插件

问题描述 投票:0回答:2

我使用插件 CodeSnippet 创建了 CKEditor 4.20.1 的在线版本。编辑器工作得很好。但是,如果我在 PHP 页面上设置工具栏,则代码片段按钮不会显示在 CKeditor 的工具栏中,而所有其他工具栏按钮都可以正常工作。我在谷歌上搜索过但没有找到任何答案。

<textarea name="text_editor" id="text_editor" ></textarea>
<script>
CKEDITOR.replace( 'text_editor', {                  
toolbar:[['Source','Table','codesnippet']],
height:['350px']
});
</script>

使用上面的代码,“源”和“表”按钮(图标)可见并且工作正常。但代码片段按钮不可见。 但是,如果我没有在页面上定义工具栏(代码如下所示),则 CodeSnippet 按钮可见并且工作正常。 但是我只需要针对特定网页的一些工具和针对其他某些页面的一些其他工具。

<textarea name="text_editor" id="text_editor" ></textarea>
<script>
CKEDITOR.replace( 'text_editor', {                  
height:['350px']
});
</script>

下面我附上了CKeditor的build-config.js,在这里你可以看到CKEditor在线构建器自动添加的codesnippet插件。

/\*\*

* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license/
  \*/

/\*\*

* This file was added automatically by CKEditor builder.
* You may re-use it at any time to build CKEditor again.
* 
* If you would like to build CKEditor online again
* (for example, to upgrade), visit one of the following links:
* 
* (1) https://ckeditor.com/cke4/builder
*     Visit online builder to build CKEditor from scratch.
* 
* (2) https://ckeditor.com/cke4/builder/14bc102b680c88ab211db5638741532b
*     Visit online builder to build CKEditor, starting with the same setup as before.
* 
* (3) https://ckeditor.com/cke4/builder/download/14bc102b680c88ab211db5638741532b
*     Straight download link to the latest version of CKEditor (Optimized) with the same setup as before.
* 
* NOTE:
* This file is not used by CKEditor, you may remove it.
* Changing this file will not change your CKEditor configuration.
  \*/

var CKBUILDER_CONFIG = {
skin: 'moono-dark',
preset: 'full',
ignore: \[
'.DS_Store',
'.bender',
'.editorconfig',
'.gitattributes',
'.gitignore',
'.idea',
'.jscsrc',
'.jshintignore',
'.jshintrc',
'.mailmap',
'.npm',
'.nvmrc',
'.travis.yml',
'bender-err.log',
'bender-out.log',
'bender.ci.js',
'bender.js',
'dev',
'gruntfile.js',
'less',
'node_modules',
'package-lock.json',
'package.json',
'tests'
\],
plugins : {
'basicstyles' : 1,
'bidi' : 1,
'blockquote' : 1,
'clipboard' : 1,
'codesnippet' : 1,
'colorbutton' : 1,
'colordialog' : 1,
'contextmenu' : 1,
'copyformatting' : 1,
'dialogadvtab' : 1,
'div' : 1,
'elementspath' : 1,
'enterkey' : 1,
'filebrowser' : 1,
'find' : 1,
'floatingspace' : 1,
'font' : 1,
'format' : 1,
'forms' : 1,
'horizontalrule' : 1,
'htmlwriter' : 1,
'iframe' : 1,
'image' : 1,
'indentblock' : 1,
'indentlist' : 1,
'justify' : 1,
'language' : 1,
'link' : 1,
'list' : 1,
'liststyle' : 1,
'magicline' : 1,
'maximize' : 1,
'pastefromgdocs' : 1,
'pastefromword' : 1,
'pastetext' : 1,
'pastetools' : 1,
'preview' : 1,
'quicktable' : 1,
'removeformat' : 1,
'resize' : 1,
'scayt' : 1,
'selectall' : 1,
'showblocks' : 1,
'showborders' : 1,
'smiley' : 1,
'sourcearea' : 1,
'specialchar' : 1,
'stylescombo' : 1,
'tab' : 1,
'table' : 1,
'tableresize' : 1,
'tableselection' : 1,
'tabletools' : 1,
'templates' : 1,
'toolbar' : 1,
'undo' : 1,
'wysiwygarea' : 1
},
languages : {
'bn' : 1,
'en' : 1,
'hi' : 1
}
};

一开始我以为在线构建有问题,所以又做了第二次(在线构建),但问题还是一样。

javascript php ckeditor ckeditor4.x
2个回答
0
投票

根据对插件源代码的实际挖掘,工具栏命令区分大小写,并且需要是

CodeSnippet

基于 https://github.com/ckeditor/ckeditor4/blob/master/plugins/codesnippet/plugin.js 中定义的 init 函数

    init: function( editor ) {
        editor.ui.addButton && editor.ui.addButton( 'CodeSnippet', {
            label: editor.lang.codesnippet.button,
            command: 'codeSnippet',
            toolbar: 'insert,10'
        } );
    },

addButton 的第一个参数定义了到底需要什么


0
投票
در هنگام نصب ممکن است نصب دچار خطا شود در این شرایط در قسمت جزئیات چک شود خطا مربوط به چه موردی می باشد به طور مثال اگر خطا در مورد اسکریپت PR رخ داد میتوانید QUERY آن را در دیتا بیس اجرا نمایید اگر انجا هم خطا داد با توجه به متن خطا، قطعه کد زیر در ابتدا اجرا شود سپس مجدد اسکریپت EXECUTE شود.

如果不存在(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[pr].[FileType]') AND 输入 (N'U')) 开始 CREATE TABLE [pr].[FileType]([Id] [int] NOT NULL IDENTITY(1, 1),[Title] nvarchar NOT NULL,CONSTRAINT [PK_FileType_Id] 主键聚集 ([Id] ASC)WITH (PAD_INDEX = OFF、STATISTICS_NORECOMPUTE = OFF、IGNORE_DUP_KEY = OFF、ALLOW_ROW_LOCKS = ON、ALLOW_PAGE_LOCKS = ON、FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY] 结束

© www.soinside.com 2019 - 2024. All rights reserved.