CKEditor Code Snippet plugin does not do syntax highlighting in yii2 framework

限于喜欢 提交于 2019-12-10 17:37:42

问题


I am using CKEditor and its Code Snippet plugin in yii2 php framework application. I would like to get syntax highlighting when I write some code using CKEditor, but whatever I do I can not make it work. I have tried everything from the guide like including css and highlight.js in the head but I get nothing... Declaring asset bundle also do not help, yii2 will load files, but highlighting still do not work.

public $css = [
    'css/site.css',
    'highlight/styles/default.css'
];

public $js = [
    'js/site.js',
    'highlight/highlight.pack.js'
];

I am using this widget to install CKEditor in my yii2 site: https://github.com/2amigos/yii2-ckeditor-widget

Can someone help me out with this ? What do I have to do to make syntax highlighting work ?

EDIT: highlighting is working inside the editor, but I need it for my page where code is posted.


回答1:


I have solved my problem, I had to include hljs.initHighlightingOnLoad(); after highlight.pack.js is loaded on my page. There are few ways to do so, I did it like this:

I have included hljs.initHighlightingOnLoad(); as a part of my site.js script, and I have loaded site.js file after the highlight.pack.js. So I had to update my Asset bundle like this:

public $js = [
    'highlight/highlight.pack.js',
    'js/site.js'
];

I had troubles for few hours and didn't realized that solution is that simple. Must be a brain freeze...



来源:https://stackoverflow.com/questions/27432332/ckeditor-code-snippet-plugin-does-not-do-syntax-highlighting-in-yii2-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!