首页 > 网络知识 » 正文

LBS asp博客系统添加代码高亮插件的方法

 70 ℃
1、代码高亮工具:syntaxhighlighter
  下载地址:http://code.google.com/p/syntaxhighlighter/downloads/list

  2、修改的文件
   global.asp
   class\ubbcode.asp
   style\SyntaxHighlighter.css (新增加的代码高亮CSS文件)
   Scripts\ (新增加的文件夹,里面为相关代码高亮的JS文件)

  3、修改方法
  首选把syntaxhighlighter下载到本地把里面的Scripts文件夹复制到你的blog根目录下,把styles文件夹下的SyntaxHighlighter.css放到你blog的styles文件夹下。
  接下来是修改文件,修改最主要的一个文件是class\ubbcode.asp
  class\ubbcode.asp改动内容:

复制代码代码如下:
// Bring Back HTML New Line lt;br /gt; and Spaces
str=str.replace(/\n/g,"lt;br /gt;");
str=str.replace(/\$nbsp\$/g,"amp;nbsp;");
//以上是本身就在的代码段,以下是我新添加的代码段,找对位置添加就可以了
//Break N add///////////////////////////////////////////////////////////2007-7-25 把代码里的换行换成\n
str=str.replace(/\lt;CodeBR\gt;/g,"\n");

此文件还有一处改动,找到// Process [code] tag,这个是code UBB代码的解析方法,替换为以下内容:
  注意:为避免解析,我把[]换成全角了

复制代码代码如下:
// Process [code=] tag ///////////////////////////////////////////////////////Break N Edit 2007-7-25
this.formatCode=function(str){
str=str.replace(/\[code\]/ig,"[code=]");
// Clean up string
str=str.replace(/\[code=/ig,"[code=");
str=str.replace(/\[\/code\]/ig,"[/code]");
str=str.replace(/\n*\[code=/ig,"[code=");
str=str.replace(/\n*\[\/code\]/ig,"[/code]");
str=str.replace(/\[code=([^]]*)]\n*/ig,"[code=$1]");
str=str.replace(/\[\/code\]\n*/ig,"[/code]");
while(str.indexOf("[code=", 0)gt;-1 amp;amp; str.indexOf("[/code]", 0)gt;-1){
var intStart,intEnd;
var strText="";
nbsp;nbsp; var strAuthor="";
nbsp;nbsp; var strSource="";
nbsp;nbsp; var strResult="";
intStart = str.indexOf("[code=", 0) + 6;
nbsp;nbsp; intEnd = str.indexOf("]",intStart);
if(intStartgt;5 amp;amp; intEndgt;0){
strAuthor = str.substr(intStart, intEnd-intStart);
}
intStart = intStart + strAuthor.length + 1;
intEnd = str.indexOf("[/code]", intStart) ;
if(intEndlt;=intStart) intEnd = intStart;
if(intEndgt;intStart){
strText = str.substr(intStart, intEnd-intStart);
nbsp;nbsp;nbsp;nbsp;var strAuthorText = strAuthor.replace(/\"/g, "");
nbsp;nbsp;nbsp;nbsp;strAuthorText = strAuthorText.lengthgt;1 ? strAuthorText :"c-sharp";
nbsp;nbsp;nbsp;nbsp;var strContent = this.encUBB(strText.replace(/^ +/gm," ").replace(/\:\/\//g,":")).replace(/\n/g,"lt;CodeBRgt;")
nbsp;nbsp;nbsp;nbsp;//response.write(strContent);
nbsp;nbsp;nbsp;nbsp;strResult = 'lt;pre name="code" class="'+strAuthorText+'"gt;'+ strContent.replace(/\lt;br\s\/\gt;/ig,'\r\n') + "lt;/pregt;";
//strResult = 'lt;div class="code"gt;'+ this.encUBB(strText.replace(/^ +/gm,"amp;nbsp;").replace(/\:\/\//g,"amp;#58;//")) + "lt;/divgt;";
}
intStart = str.indexOf("[code=", 0);
intEnd = str.indexOf("[/code]", intStart) + 7;
if(intEndlt;=intStart+6) intEnd = intStart + 7;
strSource = str.substr(intStart, intEnd-intStart);
if(strResult!=""){
str = str.replace(strSource, strResult);
}else{
str = str.replace(strSource, strSource.replace(/\[/g, "amp;#91;"));
}
}
return str;
}

修改global.asp文件

复制代码代码如下:
link rel="stylesheet" type="text/css" href="%=theCache.settings["styleSheet"]%" /
!--找到以上代码段,以下面添加如下代码即可。下面的代码段为新添加内容 --
link type="text/css" rel="stylesheet" href="Styles/SyntaxHighlighter.css"/link

把以下内容放在function pageFooter()中:

复制代码代码如下:
script class="javascript" src="Scripts/shCore.js"/script
script class="javascript" src="Scripts/shBrushCSharp.js"/script
script class="javascript" src="Scripts/shBrushPhp.js"/script
script class="javascript" src="Scripts/shBrushJScript.js"/script
script class="javascript" src="Scripts/shBrushJava.js"/script
script class="javascript" src="Scripts/shBrushVb.js"/script
script class="javascript" src="Scripts/shBrushSql.js"/script
script class="javascript" src="Scripts/shBrushXml.js"/script
script class="javascript" src="Scripts/shBrushDelphi.js"/script
script class="javascript" src="Scripts/shBrushPython.js"/script
script class="javascript" src="Scripts/shBrushRuby.js"/script
script class="javascript" src="Scripts/shBrushCss.js"/script
script class="javascript" src="Scripts/shBrushCpp.js"/script
script class="javascript"
dp.SyntaxHighlighter.ClipboardSwf = 'Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
/script

Foot部分完整的代码添加效果示例

复制代码代码如下:
// Page footer //////////////////////////////////////////////////////////////
function pageFooter(){
// Caculate Execution Time
processTime = Number(new Date()) - processTime;
%
!--高亮 --
script class="javascript" src="Scripts/shCore.js"/script
script class="javascript" src="Scripts/shBrushCSharp.js"/script
script class="javascript" src="Scripts/shBrushPhp.js"/script
script class="javascript" src="Scripts/shBrushJScript.js"/script
script class="javascript" src="Scripts/shBrushJava.js"/script
script class="javascript" src="Scripts/shBrushVb.js"/script
script class="javascript" src="Scripts/shBrushSql.js"/script
script class="javascript" src="Scripts/shBrushXml.js"/script
script class="javascript" src="Scripts/shBrushDelphi.js"/script
script class="javascript" src="Scripts/shBrushPython.js"/script
script class="javascript" src="Scripts/shBrushRuby.js"/script
script class="javascript" src="Scripts/shBrushCss.js"/script
script class="javascript" src="Scripts/shBrushCpp.js"/script
script class="javascript"
dp.SyntaxHighlighter.ClipboardSwf = 'Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
/script
!-- 高亮 /end --
div id="footer"
div id="innerFooter"
!-- REMOVAL OF THIS COPYRIGHT WITHOUT PERMISSION FROM THE AUTHOR WILL VIOLATE THE LICENCE YOU AGREED TO WHEN DOWNLOADING THIS SOFTWARE. --
!-- Copyright Start --
Powered by a href="http:www.voidland.com/" target="_blank"LBS Version %=blogVersion%/a copy; 2003-2005 a href="http:www.breakN.net"Break N/a

/div
/div
/div
/div
/body
/html
%
connBlog.close();
SessionSession.CodePage = Session("OldCodePage");
if(inDebug) showSQL();
}
%

最后保存文件,上传到服务器就搞定了。

4、如何使用
  为避免解析,我把[]换成全角了
HTML=[code=html]
XML=[code=xml]
C#=[code=C#]
Javascript=[code=js]
CSS=[code=css]
Java=[code=java]
C++=[code=c]
Delphi=[code=delphi]
PHP=[code=php]
Python=[code=python]
Ruby=[code=ruby]
SQL=[code=sql]
Visual Basic=[code=vb]
转自: http://blog.breakn.net/article.asp?id=349
mysqlconvert使用示例 转换ACCESS数据库至MYSQL的图文教程
初次安装Magento商城 后台报错的解决方法