Using SyntaxHighlighter on Blogs or Web sites
Posted by Olaf Monien in .NET, Miscellaneous, tags: Delphi, SourceCode, Syntax Highlighting, WordPressIf you have a development realted blog or Web site, then you probably paste source code examples from time to time. Using Alex Gorbatchev’s SyntaxHighlighter makes your snippets look very pretty.
Update: For WordPress there is a SyntaxHighlighter Plus plugin, which is also based on the code below. I’ve updated my posts here on the new WP based blog system to use that plugin.
I just found Alex Gorbatchev’s excellent SyntaxHighlighter on Google Code. It’s JavaScript based and makes it very easy to pretty-print your source code examples. It comes with modules for:
- C#
- C++
- CSS
- Delphi
- Java
- Javascript
- PHP
- Python
- Ruby
- SQL
- VisualBAsic
- XML
It’s completely modular, so if you need Delphi only, then you don’t have to load all other modules. Usage is very easy, just add the following to your HTML template that drives your blog or source code pages:
<script src="/js/shCore.js" type="text/javascript"></script> <script src="/js/shBrushDelphi.js" type="text/javascript"></script> <script type="text/javascript"></script>
shCore.js is about 13KB, the language modules and clipboard.swf are just two KB in average. If you need Delphi and C# then just add shCSharp.js to the list above. To show a piece of source code you insert the raw source inside a <pre></pre> tag pair. The actual formatting will be done by SyntaxHighlighter.
<pre class="delphi"> var s: string; begin s := 'Hello World'; end; </pre>





Entries (RSS)