Syntax Highlighting for Wordpress: What works best for me
I tried several systems for Syntax Highlighting in Wordpress. The two most interesting Systems are dp.SyntaxHighlighter and iG:Syntax Hiliter.
The dp.SyntaxHighlighter looks very nice and its handling is quite good. There is only on critical factor, which makes it unusable for Wordpress Users: The Code inside the Textarea will be reformatted by Wordpress by inserting additional <p> and <br /> Tags. So I went over to iG:Syntax Hiliter.
The iG:Syntax Hiliter looks good as well and has a very nice Wordpress implementation. You just have to surround you code with the appropriate Wordpress-Style Tags. e.g.:
[as]trace(”hello world”);[/as]
gives
-
trace(“hello world”);
That’s it, easy and powerfull. The only problem I ran into was when displaying HTML Syntax including Hyperlinks, the iG:Syntax Hiliter Engine conflicts with displayed HTML Code because of its function to link Sourcecode Keywords to their appropriate Reference (e.g.: the <ul> will automatically be linked to http://december.com/html/4/element/ul.html). The Result was some spaghetticode wich did not validate. As I don’t really like the Reference linking Feature of iG:Syntax Hiliter I just took the geshi.php file and commented the part out which does the job:
-
function add_url_to_keyword ($keyword, $group, $start_or_end)
-
{
-
/*if (isset($this->language_data[’URLS’][$group]) &&
-
$this->language_data[’URLS’][$group] != ” &&
-
substr($keyword, 0, 5) != ‘</’) {
-
// There is a base group for this keyword
-
if ($start_or_end == ‘BEGIN’) {
-
// HTML workaround… not good form ™ but should work for 1.0.X
-
if ($keyword != ”) {
-
// Old system: strtolower
-
//$keyword = ( $this->language_data[’CASE_SENSITIVE’][$group] ) ? $keyword : strtolower($keyword);
-
// New system: get keyword from language file to get correct case
-
foreach ($this->language_data[’KEYWORDS’][$group] as $word) {
-
if (strtolower($word) == strtolower($keyword)) {
-
break;
-
}
-
}
-
$word = ( substr($word, 0, 4) == ‘<’ ) ? substr($word, 4) : $word;
-
$word = ( substr($word, -4) == ‘>’ ) ? substr($word, 0, strlen($word) - 4) : $word;
-
if (!$word) return ”;
-
-
return ‘<|UR1|"’ .
-
str_replace(
-
array(’{FNAME}’, ‘.’),
-
array(@htmlspecialchars($word, ENT_COMPAT, $this->encoding), ‘<dot>’),
-
$this->language_data[’URLS’][$group]
-
) . ‘">’;
-
}
-
return ”;
-
// HTML fix. Again, dirty hackage…
-
} elseif (!($this->language == ‘html4strict’ && ‘>’ == $keyword)) {
-
return ”;
-
}
-
}*/
-
}
Maybe not e very smart way, but everything works fine and I’m happy.



1.
Comment by Erik:Maybe you’d like to give the SyntaxHighlighter for WordPress a try?
It’s built on the dp.SyntaxHighlighter mentioned above, but takes care of all those linebreaks and paragraph inserted by WordPress. Not to mention the nifty administration-options. g
2.
Comment by AltaGid:Hello! Help solve the problem.
Very often try to enter the site, but says that the password is not correct.
Regrettably use of remembering. Give like to be?
Thank you!
3.
Comment by naisioxerloro:Hi.
Good design, who make it?
4.
Comment by m2h3js1h:Hello, how are you?
What is your name?