• 电脑资讯
    电脑资讯

    COMPUTER

  • 电脑资讯
    您现在的位置:首页 > 电脑资讯 > 代码问题 > 为CKEditor开发插入代码的插件

    最新文章

    Latest Articles
    密码保护:EXCEL授权
    2024/04/17 浏览次数:47 评论:0
    2023/11/29 浏览次数:168 评论:0
    2023/08/11 浏览次数:186 评论:0
    2023/05/28 浏览次数:160 评论:0
    2023/05/28 浏览次数:200 评论:0
    【假设检验秒懂指南】假设检验中的第一类错误和第二类错误
    1
    2023/08/11 浏览次数:186 评论:0

    样本推断总体,永远无法100%正确。 由于抽样误差等因素,在零假设为真时,样本检验量也有5%(α= 0.05...

    2
    2023/05/28 浏览次数:160 评论:0

    曲霉菌病是感染曲霉菌引起的一种真菌病,可累及皮肤、黏膜、眼、鼻、支气管、肺、胃肠道、神经系统、骨...

    3
    2023/05/28 浏览次数:200 评论:0

    曲霉菌感染是一种免疫相关性疾病,包括3种主要形式,即:侵袭性曲霉菌病(invasive aspergillosis,IA)、...

    4
    2023/05/01 浏览次数:166 评论:0

    这是一篇受密码保护的文章,您需要提供访问密码: 密码:

    5
    2023/05/01 浏览次数:170 评论:0

    这是一篇受密码保护的文章,您需要提供访问密码: 密码:

    6
    2023/04/30 浏览次数:119 评论:0

    这是一篇受密码保护的文章,您需要提供访问密码: 密码:

    7
    2023/04/30 浏览次数:141 评论:0

    这是一篇受密码保护的文章,您需要提供访问密码: 密码:

    8
    2022/09/21 浏览次数:222 评论:0

    在治疗/检测乙肝病毒的过程中,很多患者在看到结果的时候会有这样的疑问,为什么HBV DNA有时候的单位是...

    9
    2022/08/09 浏览次数:155 评论:0

    这是一篇受密码保护的文章,您需要提供访问密码: 密码:

    10
    2022/08/09 浏览次数:175 评论:0

    这是一篇受密码保护的文章,您需要提供访问密码: 密码:

    IDSA:2016年新版曲霉菌病诊治指南
    1
    2023/05/28 浏览次数:160 评论:0

    曲霉菌病是感染曲霉菌引起的一种真菌病,可累及皮肤、黏膜、眼、鼻、支气管、肺、胃肠道、神经系统、骨...

    2
    2023/05/28 浏览次数:200 评论:0

    曲霉菌感染是一种免疫相关性疾病,包括3种主要形式,即:侵袭性曲霉菌病(invasive aspergillosis,IA)、...

    3
    2022/05/08 浏览次数:285 评论:1

    头孢类是一大类抗菌药物,常用药物超过30种,按照发明年代的先后顺序,以及抗菌谱作用特点的不同,可...

    4
    2017/05/02 浏览次数:646 评论:0

    Geotrichum candidum (yeast/fungus) Ecology: Ubiquitous worldwide distribution. Has...

    5
    2017/04/08 浏览次数:586 评论:0

    Article (PDF Available) in Diagnostic Microbiology and Infectious Disease 54(4):315-7 · May 2006 ...

    6
    2017/02/25 浏览次数:728 评论:0

    整理:杜凤霞(内蒙古包钢医院) 审稿:王玉兰/刘玉岭 这几起医院感染暴发事件是不是耳熟能详?---1...

    7
    2017/02/25 浏览次数:646 评论:0

    Question: Which treatment options for vaginal yeast infections are safe and effective in the preg...

    8
    2017/01/21 浏览次数:541 评论:0

    9
    2017/01/21 浏览次数:1021 评论:0

    10
    2017/01/21 浏览次数:896 评论:0

    专性需氧,在血琼脂平板和巧克力平板上生长良好,先将菌落放在盐水调0.5麦氏浊度的菌液再接种再Blood ...

    IDSA:2016年新版曲霉菌病诊治指南
    1
    2023/05/28 浏览次数:160 评论:0

    曲霉菌病是感染曲霉菌引起的一种真菌病,可累及皮肤、黏膜、眼、鼻、支气管、肺、胃肠道、神经系统、骨...

    2
    2023/05/28 浏览次数:200 评论:0

    曲霉菌感染是一种免疫相关性疾病,包括3种主要形式,即:侵袭性曲霉菌病(invasive aspergillosis,IA)、...

    3
    2017/05/02 浏览次数:646 评论:0

    Geotrichum candidum (yeast/fungus) Ecology: Ubiquitous worldwide distribution. Has...

    4
    2017/02/25 浏览次数:646 评论:0

    Question: Which treatment options for vaginal yeast infections are safe and effective in the preg...

    5
    2017/01/21 浏览次数:1021 评论:0

    6
    2017/01/11 浏览次数:997 评论:0

    真菌孢子是怎么产生的?笔者整理了资料,想就真菌孢子发生来一期科普。 先强调一点,本期所讲的孢子...

    7
    2016/12/22 浏览次数:890 评论:0

    帚霉属以前是归在青霉属里的(Scopulariopsis species previously belong to pencillium species.) ...

    8
    2016/12/21 浏览次数:1051 评论:0

    温度双相性真菌(产红色色素),主要存在于免疫力收损的病人,多见于此类病人的血培养标本...

    9
    2016/12/21 浏览次数:1939 评论:0

    命名由来:耶氏肺孢子菌(Pneumocystis jiroveci)其实就是以前的卡氏肺孢子菌肺炎(Pneumocystis carini...

    10
    2015/07/18 浏览次数:859 评论:0

    致病:侵犯皮肤、指甲、毛发,引起手足癣、体股癣、脓癣,毛发感染时呈发外型,局部...

    为CKEditor开发插入代码的插件

    发布时间:2013/07/01 代码问题 标签:CKEditor开发插件插入代码浏览次数:379 欢迎阅读!

    CKEditor与原来的FCKeditor有太大的不同了,作为开发人员,在做自己的博客的时候总是需要贴代码的,只好给它先做一个插入代码的插件了。高亮代码用的是"SyntaxHighlighter"。

      1、在"ckeditor\plugins\"目录下新建一个"insertcode"目录,然后在"insertcode"目录下新建一个"plugin.js",输入以下代码:

    CKEDITOR.plugins.add('insertcode', {
        requires: ['dialog'],
        init: function(a){
            var b = a.addCommand('insertcode', new CKEDITOR.dialogCommand('insertcode'));
            a.ui.addButton('insertcode', {
                label: a.lang.insertcode.toolbar,
                command: 'insertcode',
                icon: this.path + 'images/code.jpg'
            });
            CKEDITOR.dialog.add('insertcode', this.path + 'dialogs/insertcode.js');
        }
    });

      2、增加"images"目录,放入一个"code.jpg"的图片,当然图片可以从google找一个,16*16大小的就好了。

      3、增加"dialogs"目录,新建一个"insertcode.js",输入如下代码:

    CKEDITOR.dialog.add('insertcode', function(editor){
        var escape = function(value){
            return value;
        };
        return {
            title: 'Insert Code Dialog',
            resizable: CKEDITOR.DIALOG_RESIZE_BOTH,
            minWidth: 720,
            minHeight: 480,
            contents: [{
                id: 'cb',
                name: 'cb',
                label: 'cb',
                title: 'cb',
                elements: [{
                    type: 'select',
                    label: 'Language',
                    id: 'lang',
                    required: true,
                    'default': 'csharp',
                    items: [['ActionScript3', 'as3'], ['Bash/shell', 'bash'], ['C#', 'csharp'], ['C++', 'cpp'], ['CSS', 'css'], ['Delphi', 'delphi'], ['Diff', 'diff'], ['Groovy', 'groovy'], ['Html', 'xhtml'], ['JavaScript', 'js'], ['Java', 'java'], ['JavaFX', 'jfx'], ['Perl', 'perl'], ['PHP', 'php'], ['Plain Text', 'plain'], ['PowerShell', 'ps'], ['Python', 'py'], ['Ruby', 'rails'], ['Scala', 'scala'], ['SQL', 'sql'], ['Visual Basic', 'vb'], ['XML', 'xml']]
                }, {
                    type: 'textarea',
                    style: 'width:700px;height:420px',
                    label: 'Code',
                    id: 'code',
                    rows: 31,
                    'default': ''
                }]
            }],
            onOk: function(){
                code = this.getValueOf('cb', 'code');
                lang = this.getValueOf('cb', 'lang');
                html = '' + escape(code) + '';
                editor.insertHtml("<pre class=\"brush:" + lang + ";\">" + html + "</pre>");
            },
            onLoad: function(){
            }
        };
    });

      我是用"syntaxhighlighter"来做代码高亮的,如果你不喜欢它也可以换成其它的。

      4、接下来就是把插件加入到CKEditor里了,我是直接修改CKEditor插件的核心文件的,因为我是把“插入代码”功能做为一个编辑器必要的功能来使用的。

      找到ckeditor目录下的"ckeditor.js",这里的代码是经过压缩的,我们用CKEditor原来的about插件做参考。查找"about",找到"fullPage:false,height:200,plugins:'about,basicstyles",我们在"about"后面增加",insertcode",这里就变成"plugins:'about,insertcode,basicstyles"。

       继续查找"about",找到

    j.add('about',{init:function(l){var m=l.addCommand('about',new a.dialogCommand('about'));m.modes={wysiwyg:1,source:1};m.canUndo=false;l.ui.addButton('About',{label:l.lang.about.title,command:'about'});a.dialog.add('about',this.path+'dialogs/about.js');}});

      我们在这个分号后面增加

    j.add('insertcode', {requires: ['dialog'],init: function(l){l.addCommand('insertcode', new a.dialogCommand('insertcode'));l.ui.addButton('insertcode', {label: l.lang.insertcode.toolbar,command: 'insertcode',icon: this.path + 'images/code.jpg'});a.dialog.add('insertcode', this.path + 'dialogs/insertcode.js');}});

      接下来查找"i.toolbar_Basic=",这就是CKEditor默认的工具栏了,我们在这里加上",insertcode",你可以加在你想要的位置。比如我的"[‘Maximize’,’ShowBlocks’,’-‘,’insertcode’]"。

      5、进入"ckeditor\lang",分别在"en.js","zh.js","zh-cn.js"中增加",insertcode:'Insert Code'",",insertcode:'插入代碼'",",insertcode:'插入代码'"。

      6、对CKEditor的修改已经OK了,还有最后一步就是在你需要高亮代码的页面引用:

    <link type="text/css" rel="stylesheet" href="http://blog.moozi.net/wp-includes/js/syntaxhighlighter/styles/shCore.css"/>
    <link type="text/css" rel="stylesheet" href="http://blog.moozi.net/wp-includes/js/syntaxhighlighter/styles/shThemeDefault.css"/>
    <script type="text/javascript" src="http://blog.moozi.net/wp-includes/js/syntaxhighlighter/shCore.js"></script>
    <script type="text/javascript" src="http://blog.moozi.net/wp-includes/js/syntaxhighlighter/shBrushes.js"></script>

      最后,还在页面增加这段JS:

    <script type="text/javascript">
        SyntaxHighlighter.config.clipboardSwf = 'http://blog.moozi.net/wp-includes/js/syntaxhighlighter/clipboard.swf';
        SyntaxHighlighter.all();
    </script>

      CKEditor的"插入代码"插件就OK了。

    姓 名:
    邮箱
    留 言:

    147200504@qq.com

    点击这里给我发消息