The default code highlighter plugin (which is based on AstonishMe code display) bundled with b2evolution is more or less ok. However, I wanted it to be able to highlight something else aside from XML and PHP so I hacked around the code for it to use GeSHi.
The new version is now packaged as a complete plugin.
code_highlight_plugin.zip v 0.3
Follow up:
Its use is exactly like the code highlighter plugin, nothing changed. So if you want to highlight C++ code, do something like this:
HTML:
| <codeblock lang="cpp"> cout << "hello world!";</codeblock> |
Output:
C++:
| cout << "hello world!"; |
More information can be seen in the documentation.
Note that as of v0.3, this is not anymore needed because GeSHi is already bundled.
GeSHi doesn’t handle unknown languages too well. It spits out error messages which you wouldn’t want your visitors to see. You can make the following modification in geshi.php to prevent this:
Go to line 446, in function get_language_name(). And change this line:
PHP:
| return $this->language_data[‘LANG_NAME’]. ‘ (Unknown Language)’; |
to this:
PHP:
| return $this->language. ‘ (Unknown Language)’; |
Then go to line 987 and change this line:
PHP:
| if ( GESHI_MAYBE == $this->language_data[‘STRICT_MODE_APPLIES’]) |
to this:
PHP:
| if ( !empty($this->language_data[‘STRICT_MODE_APPLIES’]) && GESHI_MAYBE == $this->language_data[‘STRICT_MODE_APPLIES’]) |
Feedback would be appreciated.
Trackback URL (right click and copy shortcut/link location)