if u wanna use it in blogger, do the following steps:
Download and find a place to host the library files for SyntaxHighlighter. A free choice is, of course, google sites
Edit the Blogger template HTML file, add the codes:
<link href='http://[YOUR HOST]/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/> <script src='http://[YOUR HOST]/shCore.js' type='text/javascript'/> <script src='http://[YOUR HOST]/shBrushCpp.js' type='text/javascript'/> <script src='http://[YOUR HOST]/shBrushCSharp.js' type='text/javascript'/> <script src='http://[YOUR HOST]/shBrushCss.js' type='text/javascript'/> <script src='http://[YOUR HOST]/shBrushJava.js' type='text/javascript'/> <script src='http://[YOUR HOST]/shBrushJScript.js' type='text/javascript'/> <script src='http://[YOUR HOST]/shBrushSql.js' type='text/javascript'/> <script src='http://[YOUR HOST]/shBrushXml.js' type='text/javascript'/> <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://[YOUR HOST]/clipboard.swf"; dp.SyntaxHighlighter.HighlightAll("code"); //]]> </script> </body> </html>
Place your code on the page and surround it with <pre> tag. Set name attribute to code and class attribute to one of the language aliases you wish to use.
<pre name="code" class="c-sharp"> ... some code here ...</pre>
Here's a list of supported languages and their aliases:
Language | Aliases |
C++ | cpp, c, c++ |
C# | c#, c-sharp, csharp |
CSS | css |
Delphi | delphi, pascal |
Java | java |
Java Script | js, jscript, javascript |
PHP | php |
Python | py, python |
Ruby | rb, ruby, rails, ror |
Sql | sql |
VB | vb, vb.net |
XML/HTML | xml, html, xhtml, xslt |
Useful links:
http://code.google.com/p/syntaxhighlighter/wiki/Usage
http://code.google.com/p/syntaxhighlighter/wiki/Languages
No comments:
Post a Comment