【问题标题】:highlight.js with CKEditor codesnippethighlight.js 与 CKEditor 代码片段
【发布时间】:2017-04-10 15:43:14
【问题描述】:

我正在尝试将highlight.js 与CKEditor 插件CodeSnippet 一起使用。

我有 CKEditor 工作,包括 CodeSnippet 插件,但我的代码没有被检测到或颜色编码或缩进或任何我所期望的。

阅读highlight.js它说

这将在前置代码标签内找到并突出显示代码;它尝试 自动检测语言。如果没有自动检测 为你工作,你可以在 class 属性中指定语言:

这是我在 HTML 文件中调用 highlight.js 的 JavaScript:

<script src="{% static 'js/ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js' %}"></script>
<script>hljs.initHighlightingOnLoad();</script>

这是我的config.js CKEditor:

CKEDITOR.editorConfig = function( config ) {.
    config.toolbarGroups = [
        { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
        { name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align' ] },
        { name: 'styles' },
        { name: 'colors' },
        { name: 'insert', groups: [ 'codesnippet'] },
    ];


    config.removeButtons = 'Image,Flash,Table,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe';

    config.format_tags = 'p;h1;h2;h3;pre';

    config.removeDialogTabs = 'image:advanced;link:advanced';
};

【问题讨论】:

  • 您的配置看起来不错。您是否在不使用 CKEditor 的情况下检查 highlight.js 是否使用最少的代码? Usage of Highlight.js
  • @Hbat 我最终解决了它,如答案所示(我刚刚添加)

标签: javascript jquery ckeditor highlight.js


【解决方案1】:

这解决了它:

CKEDITOR_CONFIGS = {
    'default': {
        'skin': 'bootstrapck',
        'toolbar': 'Custom',
        'toolbar_Custom': [
            {'name': 'basicstyles', 'items': ['Bold', 'Italic', 'Underline', '-', 'RemoveFormat']},
            {'name': 'paragraph', 'items': ['NumberedList', 'BulletedList']},
            {'name': 'indent', 'items': ['Indent', 'Outdent']},
            {'name': 'codeSnippet', 'items': ['CodeSnippet',]}
        ],
        'codeSnippet_theme': 'school_book',
        'tabSpaces' : 4,
        'extraPlugins': ','.join(
            [
            'codesnippet',
            'widget',
            'dialog',
            ]),
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 2022-10-05
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多