Mar 08 2007

WordPress + Dean’s Code Highlighter: fixing single quotes inside code block.

Posted by German Rumm in Uncategorized

Installed Dean’s Code Hightlighter plugin today. It uses my favourite Geshi highlighter and very simple to use. Just wrap the code in <pre lang=”php”> </pre> block, and everything gets highlighted automatically.

But there’s a strange bug: single quotes inside the code block are replaced with curly quotes. So, if you decide to copy this code into your IDE, you’ll get a handful of parsing errors. There was a solution posted in a comments: to comment out wptexturize filter in default-filters.php.

I believe that if the plugin doesn’t work correctly, than you first should try to fix plugin, and only then modify core files. So I opened my IDE and coded the following solution

deans_code_highlighter.php, line 71

	// set priority to 10, to execute filter after all other filters.
	add_filter('the_content',array(&$this, 'ch_the_content_filter'),10);

deans_code_highlighter, line 84

	// change $search and $replace, so that they would look like this.
	$search = array("&#038;quot;", "&#038;lt;", "&#038;gt;","&#038;#92;","&#038;#39;","&#038;nbsp;", '&#038;#8217;', '&#038;#8216;', '&#038;#8221;', '&#038;#8220;', "&amp;amp;", '&#038;#038;');
	$replace = array(""",     "<",    ">",   "",   "'",   " ",  "'", "'", '"', '"', "&", '&');

And that should fix it.

2 Responses to “WordPress + Dean’s Code Highlighter: fixing single quotes inside code block.”

  1. GIS Notes Says:

    links from Technoratiphp plsql python qbasic rails reg robots ruby sas scheme sdlbasic smalltalk smarty sql tcl text thinbasic tsql vbnet vb vhdl visualfoxpro winbatch xml xpp z80 Alas, I was able to fix the single quotes problem with the code inside the tags from thispost. I also added the “&” patch especially for my cfm codes. Download the patched version of Dean’s code highligter (deans_code_highlighter1.3.tar.gz) Posted in WordPress |

  2. Doug Steinschneider Says:

    Thanks for this fix – I only needed to change the filter priority to 10. I inspected the search and replace array and it already looked correct in the current version as of today

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

captcha service