一直感觉自己博客发布的代码比较难看,粘贴进来后连个格式都没有,不利于阅读。也上 zblog官方上看过代码高亮的插件,但是据网上说比较垃圾,所以也就没敢用,今天找了个基于dp.SyntaxHighlighter(一个在google code上的开源项目)开发的fck代码高亮插件,试着安装了一下,感觉用着还是不错的。
安装很简单,下载本文附带的压缩包,解压缩后放到fckediter的plugins目录下,然后修改FCKeditor的配置文件fckconfig.js。
配置其中的FCKConfig.ToolbarSets,添加HighLighter:
FCKConfig.ToolbarSets["review"] = [
['HighLighter','Bold','Italic','Underline','StrikeThrough','Link','Unlink','Image','Rule','Smiley','TextColor','BGColor']
];
这个是放置工具栏按钮的,你也可以放到别的工具栏,配置代码要区分大小写,这里的是大写开头的HighLighter
2、还有一句配置就是注册高亮插件,让fck知道他,如下:
FCKConfig.Plugins.Add( 'highlighter', 'zh-cn,en' ) ;
然后保存配置文件,再打开博客添加文章,哈哈,一个带有"ab"字母,黄底的图标出现在工具栏了,这就是我要的高亮代码的插件按钮了。
点击该按钮,弹出如下对话框,就可以选择要粘贴的代码的语言,并且贴入代码了。

粘贴后确定,保存后的样子嘛,下面就是了。
- public partial class AdminUserList : System.Web.UI.Page
- {
- protected void Page_Load(object sender, System.EventArgs e)
- {
- Business.AdminInfo.CheckAdminLogin();
- if(!Page.IsPostBack)
- {
- SetViewMode(true);
- BindList();
- BindGrid();
- }
- }
- private void BindList(){
- Business.Admin obj=new baby.Business.Admin();
- ddl_role.DataSource=obj.Admin_RoleList();
- ddl_role.DataTextField="RoleName";
- ddl_role.DataValueField="RoleId";
- ddl_role.DataBind();
- }
- private void BindGrid()
- {
- Business.Admin obj=new Business.Admin();
- dg_list.DataSource=obj.Admin_UserList();
- dg_list.DataBind();
- }
- }
应ash 的要求,再粘贴一段asp和php的代码,看看效果。下面是asp的
- Class FCKeditor
- private sBasePath
- private sInstanceName
- private sWidth
- private sHeight
- private sToolbarSet
- private sValue
- private oConfig
- Private Sub Class_Initialize()
- sBasePath = ""
- sWidth = "100%"
- sHeight = "400"
- sToolbarSet = "Default"
- sValue = ""
- Set oConfig = CreateObject("Scripting.Dictionary")
- End Sub
- Public Property Let BasePath( basePathValue )
- sBasePath = basePathValue
- End Property
再来段php的
- <?php
- function RunMagicQuotes(&$str)
- {
- if(!get_magic_quotes_gpc()) {
- if( is_array($str) )
- foreach($str as $key => $val) $str[$key] = RunMagicQuotes($val);
- else
- $str = addslashes($str);
- }
- return $str;
- }
- function gdversion()
- {
- //没启用php.ini函数的情况下如果有GD默认视作2.0以上版本
- if(!function_exists('phpinfo'))
- {
- if(function_exists('imagecreate')) return '2.0';
- else return 0;
- }
- else
- {
- ob_start();
- phpinfo(8);
- $module_info = ob_get_contents();
- ob_end_clean();
- if(preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info,$matches)) { $gdversion_h = $matches[1]; }
- else { $gdversion_h = 0; }
- return $gdversion_h;
- }
- }
下面的连接是该插件的压缩包,喜欢的朋友可以下载安装试试。