Highlight Source Pro: Sourcecode Highlighting WordPress-Plugin
April 7th, 2008 |Yeah, there’s that WordPress-Blog we have and there are these tools we develop, and when we blog about our ingeniousity we have to go through all those painful code-markup-problems. I hate that. But fear no more, my furry friends, for this is our path to salvation.
Highlight Source Pro
Based upon this Posting I found on my research I tweaked and improved things a little and here it is, in it’s full glory, flexible, automatic, degrading – amazing.
Download Current Version (from wordpress.org)
Features
- Highlight sources of any language
- automatically, server-side (no javascripts)
- XHTML-Compliant, <div>, <ul> & <span>’s with class-attributes and a css-file are used for styling
- optionally add a heading for every code-block
- optionally specify line-number offset (BREAKS XHTML COMPLIANCE)
- optionally don’t display line-numbers
- set per-codeblock if the code is html_entity_encoded or not
- only parses <pre>-tags with the lang-attribute, thus does not interfere with any regular preformatted contents you might have
- degrades beautifully through <pre>-tags (if you keep the sources clean, that is)
- all settings through logical, valid arguments for the main container
- comes with generic cross-browser (IE5/Mac, IE5.5+, FF, Safari, Opera) default CSS-styles
- see screenshot for preview
How to use
Set your code-blocks as <pre>-tags. If the language is supported by GeSHi (see filelist in the /geshi-directory) use the filename (without extension) as language-attribute. If your code is encoded (html-entities; e.g. < is displayed as < – most likely the case if you write in the visual editor) add the ‘enc__’ – prefix. For example for a php-codeblock you would start as follows:
<pre lang="php">
You can control various things:
- Start of Line-Offset, e.g. for #17:
<pre class="17"> - define entity-encoded blocks, e.g. for php:
lang="enc__php" - Define a title for your code-block that appears inside the block, but above the code lines. Everything in the same line as the opening
<pre>tag will be considered the title, including HTML. Example:<pre lang="php"><strong>This is</strong> an <em>example</em> with a <h3>headline</h3> - disable line numbers by not specifying an offset
Known Issues
- While the plugin is basically XHTML 1.0 Strict compliant there’s just no way of getting the offset-based line-numbering to display without inadequate (ab)use of javascript & css hacks, so be warned that IF you use the line-number offset, your documents will NOT validate because of the forbidden start-attribute for the
<ol>! - Watch out for your ampersands (
&) for HTML-listings: Those little friends ALWAYS have to be encoded (&), even twice (&amp;) if your source is encoded. This is because GeSHi only checks for HTML 4 Strict.
Example #1: HTML
<pre lang="html"> Some Demo-HTML-Markup <body> <h1 class="a_class">What a great afternoon & stuff</h1> <p>Isn't <a href="http://kno.at/">today</a> just "beautiful"?</p> </body> </pre>
-
<body>
-
<h1 class="a_class">What a great afternoon & stuff</h1>
-
<p>Isn't <a href="http://kno.at">today</a> just "beautiful"?</p>
-
</body>
Example #2: PHP
<pre lang="enc__php" class="17"> now <strong>with</strong> headline: <h3>a PHP-Filename</h3>
<?php
/**
* Here is a comment! Weeeeeeeee.
*/
function demonstrate_stuff ( $me_so_horny )
{
$a = 17;
print ( "$a: $me_so_horny". $a * 3 + $this->testvar );
return 'excellent!';
}
?>
</pre>
a PHP-Filename
-
<?php
-
/**
-
* Here is a comment! Weeeeeeeee.
-
*/
-
function demonstrate_stuff ( $me_so_horny )
-
{
-
$a = 17;
-
print ( "$a: $me_so_horny". $a * 3 + $this->testvar);
-
return 'excellent!';
-
}
-
?>
From what I see above, the plugin is not correctly displaying code: see the curly quotes in your PHP snippets, line 25 (return ‘excellent’)
Yep, this is a WordPress “Feature”. They automatically convert Quotes to typographical correct ones, what is annoying in terms of sourcecodes.
I’ll look into that asap, thanks for pointing it out!
[UPDATE] Released V1.1 which handles the quotes correctly (see Examples)
[...] fargekoding av koden slik at det er mye lettere å lese og forstå, slik som vist på denne og denne [...]
[...] Highlight Source Pro [...]
[...] Utilizei o excelente plugin Highlight Source Pro pra mostrar o código como aparece no Flash. Demorei pra achar um plugin WordPress que funcionasse [...]
[...] 9. Highlight Source Pro: Sourcecode Highlighting WordPress-Plugin — blog.kno.at [...]
Hi : ) Thanks for the plug-in; It works on 2.5.1? ’cause I am trying harder to make it work… thanks again for your donation to the community.
[...] Highlight Source Pro [...]
[...] Highlight Source Pro [...]
[...] Highlight Source Pro: Dieses Plugin ersetzt das bisher verwendete Plugin WP_Syntax. Beide Plugins dienen im Grunde dem gleichen Zweck; dem Darstellen von HTML, PHP und anderem Code in einem Beitrag. Ohne Plugin würde WordPress beispielsweise so Dinge wie spitze Klammern herausfiltern und damit das Anzeigen von Code in vielen Programmiersprachen zunichte machen. [...]
[...] considerazione i miei programmi, per rendere tutto cio possibile, ho deciso di utilizzare il plugin Highlight source pro che ci permette la corretta visualizzazione del codice come nell’esempio sottostande di [...]
Compared with other syntax highlighting plugin, this one solved the problem of .
Good work.
[...] Highlight Source Pro [...]
[...] Highlight Source Pro [...]
[...] Highlight Source Pro [...]
[...] Highlight Source Pro [...]
[...] Highlight Source Pro [...]
[...] is an integrated source code formatting system – which I couldn’t get to work. The external Highlight Source Pro plugin works like a charm [...]
[...] Highlight Source Pro (Bir tür kod eklentisi) [...]
[...] Highlight Source Pro [...]
[...] | Author: Christian Knoflach Coloring: #7 of 8 Ease of Install/Use: #5 of 8 Line Numbers: Optional PRE or CODE: PRE Other [...]
Thank you for a decent highlighter plugin, be nice to have the function names linked to the php manual but cannot complain :)
This is like the third or fourth plugin I’ve tried over the last hour and this is the only one that works correctly so far.
[...] 이런 목적으로 다양한 플러그인이 존재하는데 나는 Highlight Source Pro라는 플러그인을 사용하고 있다. 이 플러그인은 코드 하이라이팅 자체는 [...]
[...] Highlight Source Pro (Bir t
[...] Highlight Source Pro [...]
[...] 6) Highlight Source Pro [...]
[...] Highlight Source Pro (Bir tür kod eklentisi) [...]
[...] Highlight Source Pro (Bir tür kod eklentisi) [...]
[...] just got a syntax highlighting plugin: Highlight Source Pro which uses GeSHi. I made a custom plugin for Processing syntax highlighting, using the same colours [...]
1993 toyota celica part dunning toyota ann arbor lithia toyota vacaville jack sherman toyota
2003 toyota matrix xrs findlay toyota las vegas 1993 toyota celica
1992 toyota mr2 colorado springs toyota accessory atlanta toyota bay area toyota dealer
Good plugin, enc___ mode is a real plus as we can keep the wysiwyg this way.
Foud a bug altough.
is converted to <pre class=”1″ lang”html” when switching to the wysiwyg, thus preventing the code from being displayed correctly
Made a quick fix by changing regexp in the plugin, but it needs to be fixed (attrbutes may be in any order)
FYI Fixed regexp :
$code_regex = ‘/[\[\]([ ]*([^\n]+))?\n([\D\S]+?)[\[\]/’;
lol, can’t paste code in the comments of a cde display plugin ^^ …
Please read above : <pre lang=”html” class=”1″ is converted to <pre class=”1″ lang=”html”
Sorry for the typo :)
Wordpress automaticly moves first line after pre tag to the same line, so editing posts with code samples without comment is rather annoying. Maybe it’s possible to add some special char, or stop wordpres from “correcting” html?
Really like your plugin, have tried to use it best I can on my site.
Only feature that’d be really nice (not sure how feasible it is) is some means to list or prompt me with what languages are available. Everytime I put some code up I have to ftp in to remind myself what languages I can chose from. If this was available somewhere in the wordpress admin IDE it would be very convenient.
Thanks all the same, best code plugin I’ve found!
[...] Highlight Source Pro (Bir tür kod eklentisi) [...]
[...] the way, I’d like to thank Christian Knoflach for his excellent source code highlighting plug-in for WordPress. The wonderfully formatted code you see above is the result of applying his [...]
Does somebody know how to tell wordpress do not replace some char sequences like usual quotes to typographical quotes or double-minus to long dash?
[...] Highlight Source Pro [...]
[...] preventing ugly quotes and ‘widows’ and providing CSS hooks to style some special cases.” 9. Highlight Source Pro: Sourcecode Highlighting WordPress-Plugin — blog.kno.at Allows you to highlight any source code within a post. 10. WP-Syntax WP-Syntax provides clean [...]
[...] wp-typogrify is a WordPress plugin that “Prettifies your web typography by preventing ugly quotes and ‘widows’ and providing CSS hooks to style some special cases.” 9. Highlight Source Pro: Sourcecode Highlighting WordPress-Plugin — blog.kno.at [...]
Highlight Source Pro fails to parse certain PHP syntax such as $var– which displays $var-
[...] Site officiel : blog.kno.at [...]
[...] Highlight Source Pro WP Plugin [...]
[...] that use GeSHi to format code snippets and I tried out three of them yesterday: CodeColorer, Highlight Source Pro, and WP-Syntax. At the time, I was writing a tutorial on adding chapter quotes to WordPress posts, [...]
[...] Highlight Source Pro [...]
[...] Highlight Source Pro [...]
[...] Highlight Source Pro [...]
Thanks for this post, I was looking for information like this.
[...] Highlight Source Pro [...]
[...] 除此之外,我还安装了两个插件,一个是Highlight Source Pro,是一款源码高亮插件,感觉挺不错的。还有一个是Google XML Sitemaps,好像是帮助搜索引擎更好地简历博客索引的插件。 [...]
[...] 10 .Highlight Source Pro [...]
I am trying to get the code formatting to work. When I cut-n-paste my code for a new Post, the staggering code formatting is lost. Thus all my code is flat. Is there a way to have the code inside of these PRE blocks gets formatted for readability?
[...] Highlight Source Pro [...]
[...] Highlight Source Pro [...]
[...] 10 .Highlight Source Pro [...]
I want to thank you for yet another great WordPress tutorial. I am always searching for super WordPress tips to suggest to my own readers. Thank you for making this tutorial . It’s exactly what I was looking for. Truly first-class post.
[...] 8. Highlight Source Pro [...]
[...] Highlight Source Pro [...]
[...] Highlight Source Pro (Bir tür kod eklentisi) [...]
[...] Highlight Source Pro [...]
[...] Highlight Source Pro WP Plugin [...]