Wordpress’s Syntax Highlighter Evolved messes up my code


Vinh Nguyen


June 30, 2011

I use email to post entries to my blog. I place code snippets in between "LEFT BRACKET plain RIGHT BRACKET" and "LEFT BRACKET /plain RIGHT BRACKET" with the "div" tag surrounding them. My code gets displayed fine using the Syntax Highlighter Evolved plugin. However, when I edit the entry in wordpress, quotes, ampersands, less than signs, and greater than signs get converted to html code when I save the post and it makes my code unreadable. This also happens if I start writing my post in wordpress. This only happens to text within the code chunk, and not text outside of it. This conversion that happens when saving does not happen when the plugin is disabled. I did not find a fix for this.

To edit my posts with code and not have them messed up when saving, I have to disable the plugin before editing and re-enabling after editing. This is a pain.

For the previous posts that are already messed up, one can execute a sql script to replace the funny html code. For me, I edited each post manually in emacs and made use of this function:

(defun undo-html-char ()
(replace-string "<" "<")
(replace-string ">" ">")
(replace-string "&" "&")
(replace-string """ "\"")