代码的高亮一直来都是个问题,很多东西只能凑和着来,就像本文要说的 syntaxhighter 一样,解析真的好慢呀,不过高亮效果却是不错的
。
在ckeditor for wordpress 的基础上添加 syntaxhighter 按钮支持,以方便添加代码,这个可不能少。修改步骤如下:
CKEDITOR.editorConfig = function(config) {
// The minimum editor width, in pixels, when resizing it with the resize handle.
config.resize_minWidth = 450;
// Protect PHP code tags (<?...?>) so CKEditor will not break them when
// switching from Source to WYSIWYG.
config.protectedSource.push(/<\?[\s\S]*?\?>/g);
// Define toolbars, you can remove or add buttons.
// List of all buttons is here: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.toolbar_Full
// WordPress basic toolbar
config.toolbar_WordpressBasic = [ [ 'Bold', 'Italic', '-', 'NumberedList','BulletedList', '-', 'Link', 'Unlink', 'Image' ] ];
// WordPress full toolbar
config.toolbar_WordpressFull = [
['Source'],
['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
'/',
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
['Link','Unlink','Anchor'],
'/',
['Format','Font','FontSize'],
['TextColor','BGColor'],
['Maximize', 'ShowBlocks', 'syntaxhighlight'],['MediaEmbed']
];
config.extraPlugins += (config.extraPlugins ? ',syntaxhighlight' : 'syntaxhighlight' );
CKEDITOR.plugins.addExternal('syntaxhighlight', ckeditorSettings.pluginPath + 'plugins/syntaxhighlight/');
};About the Author
发表评论