LBS asp博客系统添加代码高亮插件的方法
LBS asp博客系统添加代码高亮插件的方法
发布时间:2016-12-23 来源:查字典编辑
摘要:1、代码高亮工具:syntaxhighlighter下载地址:http://code.google.com/p/syntaxhighligh...

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," ");

//以上是本身就在的代码段,以下是我新添加的代码段,找对位置添加就可以了

//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," ").replace(/:///g,"://")) + "</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, "["));

}

}

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> &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

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新其它cms学习
热门其它cms学习
CMS教程子分类