WordPress Code Highlight Plugin
Post syntax highlighted code, or simply post code that is not affected by the WordPress text replacement features.
Note: This plugin does not work correctly with WP 2.0. I’ve tried to get it to work, but the new WYSIWYG editor is causing a lot of trouble. I’m leaving the download up for anyone who wants to give it a try (re-release if it you wish. I will link to you from this post if you do). I am working on a new plugin that will let you post code, but in a different manner. I am trying to get something together so at least old posts will still display correctly.
You can Download what I’ve done so far and work from that. The problem is something to do with HTML cleanup, I believe. TinyMCE (or a plugin) cleans up invalid code — I’ve tried to fix it by converting HTML into entities, but the cleanup takes place before my TinyMCE plugin can work on it.
Requirements
- The following PEAR packages are used:
- Whatever packages are not installed on your system, download them from the PEAR website and place them into the PEAR/ directory included with the plugin. PEAR and XML_Parser are two common packages, so the download here only includes the less common Text_Highlighter package.
Release Notes
- 1.0 Beta 3.1.1:
- Fixed security issue that would allow a malicious user to inject SQL into the insert/update queries used for editing/creating new comments/posts.
- This was the only change from Beta 3.1, no bugs have been addressed in this release.
- 1.0 Beta 3.1:
- Added Java to acceptable lang
- 1.0 Beta 3:
- Notes:
- Took out the PEAR base class from the package, now only the Text_Highlighter is included. Since PEAR and the other classes Text_Highlighter relies on are common, I’ve decided to only include the less common Text_Highlighter.
- Updated Text_Highlighter to newest release (now with Java support)
- Fixed XHTML validation bugs.
- Fixed bug with invalid path separator on Mac OSX.
- Fixed bug when posting one line of code, the code is hidden by padding (now forces a height to one-liners).
- Notes:
- 1.0 Beta 2:
- Added filters for comments and excerpts too
- Added filters for *_pre (Input->database) to combat some issues people might have with the balanceTags function
- Fixed the issue with slashes being stripped.
- 1.0 Beta 1: The first release
Note: This plugin is unsupported and does not have any set release schedule. The author (me!) releases it with no guarantees. If lack of support and irregular updates is a problem for you, then you shouldn’t install this plugin. It’s released simply because I like to share my works.
Using 1.0 Beta 3.1 but get no color here. My configuration:
php 5.0.4
PEAR 1.3.6
XML_Parser 1.2.4
And I did copy the content of add_css.css to my themes css.
Actually it’s not ‘no color’. It’s all default color. If I view the HTML source from my browser, I only see hl-default and hl-main, no other classes. And I got no errer, like missing PEAR/Parser functions etc, when loading the page.
Does anybody have similar experience?
Sorry for the last comment. My bad. Actually I enclosed a slice of php code without so that the parser doesn’t recognize it. But this plugin can recognize it. :(
When I tried to activate the plugin it failed to run, because it was unable to find the PEAR.php file. Please include it along with the distribution for the people without PEAR.
Chris, thanks so much for your great tool!
I created a simple quicktag to make inserting the code lang=”" tags easier. I hope it will be beneficial to the users of your plugin.
kem: I receive a very similar error. Did you ever get this working?
On my local installation the plugin works fine with all the PEAR packages descibe at the top of this page, but I use a shared server for my online web blog and some php function have been disabled for obscur security reasons such as the ini_set function.
This function is used to add the PEAR path to the php include_path, in the “CodeHighlight.php” file :
::HLIGHT_BLOCK_1::
So the activation of the “code hilight” plugin generates error.
To correct the problem, I try to specify the real path of the PEAR folder, everywhere it’s needed :
- in CodeHighlight.php
- in Highlighter.php
And the activation of the plugin works fine.
The problem now is that the “highligth” function generate an error like “Call to undefined function: highlight()” in the “CodeHighlight.php” file at line 145 :
::HLIGHT_BLOCK_2::
How could I do to make the highlight function visible ?
Regarding the problem with unnecessary vertical scroll bars in with code that shouldn’t be long enough to trigger the vertical scroll. This seems to be triggered by lines of code which are sufficiently long to trigger the horizontal scroll bar. When the horizontal scroll bar is triggered, the vertical scroll bar it triggered too.
The workaround it to avoid having long lines of code that trigger the horizontal scrollbar.
Hope this helps somebody. I’m no CSS expert but is there don’t seem to be separate vertical/horizontal settings for the overflow attribute in h1-surround.
Hope this helps somebody!
Hello Chris. My name is Minkoo Seo, and I’ve found some important security problem. Could you email me? I can’t find your email address, so I’m writing to you using comment.
Ah, I forgot to mention that the problem is related to CodeHighlight which I love very much.
Hello Chris,
I just installed your tool on my website. Unlikly it seems not to work.
I added a
[code lang="php"][/code]
to an static page. The frame and the code appears… even there’s nothing highlighted. Insted of ‘
ups.. Sorry…. at “I added a” I entered a code-tag with >?php echo “some php code”& ?<..
Just the code disappears on your site, too.
After “Instead” (sorry for misspelling…) I wrote: Instead of highlightning the source a blank appears between > and ? so your parser will not longer detect propper php-code, I asume. Is that correct?
What do you think, which other plugin will fire in front of yours?
reg.
Arno
I’m having a problem with escape characters (the backslash n) and what not, any way to fix that? love the plugin otherwise, its just makin me adapt my code to a plugin. know what i mean? get back to me.. thnx!!! :-D
love the plugin btw..
and of course the second i open my mouth, it works.. :: inserts foot ::
Well…. That’s what I understand by supporting your own tools! Great work, Chris! I think the next place your tool will see at my PC ist the Trashcan.
regards
Arno
Arno: I just tried that PHP code here and it works fine. Code in comments is buggy (as you could have figured from reading previous commenters). I will fix bugs when I have spare time, which is little, especially at this time of year. Note to anyone: this plugin is GPL’ed. Anyone can take what I have done and add features/bug fixes to it as they wish. It’s a relatively small plugin, the bulk of the functionality resides in the PEAR packages.
The plugin is released simply because some people might find it useful. You must understand that, as pointed out in the blog post, the plugin is unsupported and does not follow a release schedule. If it does not work for you or you have a problem with these “terms”, then obviously this is not something you should use.
I’m sorry I don’t have unlimited time to support and update things that I have unconditionally released for public use. I have a life, a job and things of greater importance. If you think my time and efforts, which I give away freely without asking for anything in return, belong in your trashcan: so be it. But I do ask a simple favor: do not come to my site and mock me.