简体   繁体   中英

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

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM