LBS asp博客系统添加代码高亮插件的方法
脚本之家
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 <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" class="'+strAuthorText+'">'+ strContent.replace(/\<br\s\/\>/ig,'\r\n') + "</pre>";
//strResult = '<div class="code">'+ 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 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> © 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
下载地址: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 <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" class="'+strAuthorText+'">'+ strContent.replace(/\<br\s\/\>/ig,'\r\n') + "</pre>";
//strResult = '<div class="code">'+ 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 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> © 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