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)
SyntaxHighliter do not work for me on my WordPress blog.
I have found WP-Syntax that did:
http://wordpress.org/extend/plugins/wp-syntax/
(we can control when the lines begin to be numbered)
Good luck with your new project.
IIRC I tried that one as well, but I found SyntaxHilighter to be less intrusive. The problem with the others that are based on <pre> tag extensions was (IIRC) that WP lost the formatting, when you switched back and force between source and design view.
The common most problem with SyntaxHighlighter is, if you copy the examples from the webpage, you will get invalid quotes (due to some unicode conversion). If you really type in the quotes it will work …