1、代码高亮工具:syntaxhighlighter
下载地址:http://code.google.com/p/syntaxhighlighter/downloads/list
2、修改的文件
global.asp
classubbcode.asp
styleSyntaxHighlighter.css (新增加的代码高亮CSS文件)
Scripts (新增加的文件夹,里面为相关代码高亮的JS文件)
3、修改方法
首选把syntaxhighlighter下载到本地把里面的Scripts文件夹复制到你的blog根目录下,把styles文件夹下的SyntaxHighlighter.css放到你blog的styles文件夹下。
接下来是修改文件,修改最主要的一个文件是classubbcode.asp
classubbcode.asp改动内容:
复制代码代码如下:
// Bring Back HTML New Line <br /> and Spaces
str=str.replace(/n/g,"<br />");
str=str.replace(/$nbsp$/g,"&nbsp;");
//以上是本身就在的代码段,以下是我新添加的代码段,找对位置添加就可以了
//Break N add///////////////////////////////////////////////////////////2007-7-25 把代码里的换行换成n
str=str.replace(/<CodeBR>/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)>-1 && str.indexOf("[/code]", 0)>-1){
var intStart,intEnd;
var strText="";
var strAuthor="";
var strSource="";
var strResult="";
intStart = str.indexOf("[code=", 0) + 6;
intEnd = str.indexOf("]",intStart);
if(intStart>5 && intEnd>0){
strAuthor = str.substr(intStart, intEnd-intStart);
}
intStart = intStart + strAuthor.length + 1;
intEnd = str.indexOf("[/code]", intStart) ;
if(intEnd<=intStart) intEnd = intStart;
if(intEnd>intStart){
strText = str.substr(intStart, intEnd-intStart);
var strAuthorText = strAuthor.replace(/"/g, "");
strAuthorText = strAuthorText.length>1 ? strAuthorText :"c-sharp";
var strContent = this.encUBB(strText.replace(/^ +/gm," ").replace(/:///g,":")).replace(/n/g,"<CodeBR>")
//response.write(strContent);
strResult = '<pre name="code"+strAuthorText+'">'+ strContent.replace(/<brs/>/ig,'rn') + "</pre>";
//strResult = '<div>'+ this.encUBB(strText.replace(/^ +/gm,"&nbsp;").replace(/:///g,"&#58;//")) + "</div>";
}
intStart = str.indexOf("[code=", 0);
intEnd = str.indexOf("[/code]", intStart) + 7;
if(intEnd<=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, "&#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 src="Scripts/shCore.js"></script>
<script src="Scripts/shBrushCSharp.js"></script>
<script src="Scripts/shBrushPhp.js"></script>
<script src="Scripts/shBrushJScript.js"></script>
<script src="Scripts/shBrushJava.js"></script>
<script src="Scripts/shBrushVb.js"></script>
<script src="Scripts/shBrushSql.js"></script>
<script src="Scripts/shBrushXml.js"></script>
<script src="Scripts/shBrushDelphi.js"></script>
<script src="Scripts/shBrushPython.js"></script>
<script src="Scripts/shBrushRuby.js"></script>
<script src="Scripts/shBrushCss.js"></script>
<script src="Scripts/shBrushCpp.js"></script>
<script>
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 src="Scripts/shCore.js"></script>
<script src="Scripts/shBrushCSharp.js"></script>
<script src="Scripts/shBrushPhp.js"></script>
<script src="Scripts/shBrushJScript.js"></script>
<script src="Scripts/shBrushJava.js"></script>
<script src="Scripts/shBrushVb.js"></script>
<script src="Scripts/shBrushSql.js"></script>
<script src="Scripts/shBrushXml.js"></script>
<script src="Scripts/shBrushDelphi.js"></script>
<script src="Scripts/shBrushPython.js"></script>
<script src="Scripts/shBrushRuby.js"></script>
<script src="Scripts/shBrushCss.js"></script>
<script src="Scripts/shBrushCpp.js"></script>
<script>
dp.SyntaxHighlighter.ClipboardSwf = 'Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
</script>
<>
<div id="footer">
<div id="innerFooter">
<>
<>
Powered by <a href="http:www.voidland.com/" target="_blank">LBS Version <%=blogVersion%></a> © 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
【LBS asp博客系统添加代码高亮插件的方法】相关文章:
★ joomla手动实现后台上传和缩略图入库扩展实现方法分享
★ PJblog3 读取日志出错.3002 : 文件无法被打开
★ mysqlconvert使用示例 转换ACCESS数据库至MYSQL的图文教程