清心博客圈,祝你圣诞节快乐

2008年12月20日星期六

Google SyntaxHighlighter

Just now I performed a search that I found something that is very useful for me to place the coding here. This is the syntaxhighlighter from Google code.

For me, I have uploaded the syntaxhighlighter to my web server, and place the code in blogger by edit the templates.

I added the code before


</body></html>


with




<link href="http://web.qxinnet.com/syntaxhighlighter/SyntaxHighlighter.css" rel="stylesheet" type="text/css"/>
<script src="http://web.qxinnet.com/syntaxhighlighter/shCore.js" type="text/javascript"></script>
<script src="http://web.qxinnet.com/syntaxhighlighter/shBrushCpp.js" type="text/javascript"></script>
<script src="http://web.qxinnet.com/syntaxhighlighter/shBrushCSharp.js" type="text/javascript"></script>
<script src="http://web.qxinnet.com/syntaxhighlighter/shBrushCss.js" type='text/javascript'></script>
<script src="http://web.qxinnet.com/syntaxhighlighter/shBrushJava.js" type="text/javascript"></script>
<script src="http://web.qxinnet.com/syntaxhighlighter/shBrushJScript.js" type="text/javascript"></script>
<script src="http://web.qxinnet.com/syntaxhighlighter/shBrushSql.js" type="text/javascript"></script>
<script src="http://web.qxinnet.com/syntaxhighlighter/shBrushXml.js" type="text/javascript"></script>
<script class='javascript'>
//<![CDATA[
function FindTagsByName(container, name, Tag){
var elements = document.getElementsByTagName(Tag);
for (var i = 0; i < elements.length; i++){
if (elements[i].getAttribute("name") == name) {
container.push(elements[i]);
}
}
}
var elements = [];
FindTagsByName(elements, "code", "pre");
FindTagsByName(elements, "code", "textarea");
for(var i=0; i < elements.length; i++) {
if(elements[i].nodeName.toUpperCase() == "TEXTAREA") {
var childNode = elements[i].childNodes[0];
var newNode = document.createTextNode(childNode.nodeValue.replace(/<br\s*\/?>/gi,'\n'));
elements[i].replaceChild(newNode, childNode);
} else if(elements[i].nodeName.toUpperCase() == "PRE") {
brs = elements[i].getElementsByTagName("br");
for(var j = 0, brLength = brs.length; j < brLength; j++) {
var newNode = document.createTextNode("\n");
elements[i].replaceChild(newNode, brs[0]);
}
}
}
//clipboard does not work well, no line breaks
// dp.SyntaxHighlighter.ClipboardSwf =
//"http://web.qxinnet.com/syntaxhighlighter/clipboard.swf";
dp.SyntaxHighlighter.HighlightAll("code");
//]]>
</script>


And I have following up with the website: http://yehhou.blogspot.com/2007/06/blogger-dpsyntaxhighlighter.html

没有评论: