CKEDITOR.plugins.codesnippet.highlighter
class
since 4.4.0
inherited
A Code Snippet highlighter. It can be set as a default highlighter using CKEDITOR.plugins.codesnippet.setHighlighter, for example:
// Create a new plugin which registers a custom code highlighter
// based on customEngine in order to replace the one that comes
// with the Code Snippet plugin.
CKEDITOR.plugins.add( 'myCustomHighlighter', {
afterInit: function( editor ) {
// Create a new instance of the highlighter.
var myHighlighter = new CKEDITOR.plugins.codesnippet.highlighter( {
init: function( ready ) {
// Asynchronous code to load resources and libraries for customEngine.
customEngine.loadResources( function() {
// Let the editor know that everything is ready.
ready();
} );
},
highlighter: function( code, language, callback ) {
// Let the customEngine highlight the code.
customEngine.highlight( code, language, function() {
callback( highlightedCode );
} );
}
} );
// Check how it performs.
myHighlighter.highlight( 'foo()', 'javascript', function( highlightedCode ) {
console.log( highlightedCode ); // -> <span class="pretty">foo()</span>
} );
// From now on, myHighlighter will be used as a Code Snippet
// highlighter, overwriting the default engine.
editor.plugins.codesnippet.setHighlighter( myHighlighter );
}
} );