posting code on wordpress

My last post proved useful for someone out there who was trying to get the touchscreen working on their computer. It however brought to my attention that wordpress butchers code formating. This brought to my attention their various different code formating/highlighting plugins. Unfortunately none of these plugins work well. I found that every single one broke the formating in some way. The closest I could get was using the tag with <LANG> set to XML. This half solution presented the code properly formated in a horizontal scrolled box for the long lines, but using the incorrect XML highlighting (oddly both the shell and bash settings broke the code). The other option was to use the <pre> tag to preserve formating, but this provides no hightling and long lines run off the page. Highlighting is nice but not necessary, but incorrect highlighting is, at least in my opinion, the sign of an ugly kludge.

I looked around a bit more and found that emacs has a plugin called htmlize that will output a html formated version of your code for posting on the internet. I have never been a huge fan of emacs, I have found it to be far more complex a tool than I need for my little scripting exercises. But this plugin sounded perfect for this problem, the trouble was getting it to work right. I suppose that if I bothered to read the tutorial I would have found out sooner that M- equals the Alt key and saved a little time. Having figured that out, typing M-x (that is Alt-x) and typing ‘htmlize-buffer’ produced a page of html formated and highlighted correctly code, but with the CSS formating in the html head section. This did me no good at all as worpress doesn’t give you access to custom CSS unless you pay an annual fee. The documentation for htmlize states;

;; htmlize supports three types of HTML output, selected by setting
;; `htmlize-output-type': `css', `inline-css', and `font'.  In `css'
;; mode, htmlize uses cascading style sheets to specify colors; it
;; generates classes that correspond to Emacs faces and uses <span
;;>...</span> to color parts of text.  In this mode, the
;; produced HTML is valid under the 4.01 strict DTD, as confirmed by
;; the W3C validator.  `inline-css' is like `css', except the CSS is
;; put directly in the STYLE attribute of the SPAN element, making it
;; possible to paste the generated HTML to other documents.  In `font'
;; mode, htmlize uses <font color="...">...</font> to colorize HTML,
;; which is not standard-compliant, but works better in older
;; browsers.  `css' mode is the default.

I looked everywhere but could not find ‘htmlize-output-type’ or even ‘htmlize’ in emacs, the command worked but I couldn’t figure out how to change the default settings. I then came across this blog who’s author had the same issue with the htmlize default output, but who much better understands emacs. He writes;

inline-css is the type of output i want. This can be achieved by customizing htmlize-output-type variable with M-x customize htmlize RET or directly modifying dot emacs.

I was not ready to start customizing the dot emacs file, but his directions seemed a little more forward. However ‘M-x (Alt-x) customize’ brought me to a menu that did not include htmlize, and typing further commands into the command line brought the ‘No match’ error.

Having hit another wall with this I took a break, went and had a few beers with a friend. Afterwards It finally occured to me that there are many different emacs variations, they all use the emacs back end but present different interfaces, and the version that I was using, emacs22GTK might not have the same options built into the interface. One of the posts I had read had referencede Xemacs, so I installed it and and typed M-x  (yes I will remind everybody that M is for Alt everytime because most computer have not had a Meta key for decades; Alt-x) ‘customize’ and I was asked to specify a group and entered ‘htmlize’ and up popped the screen to change the settings for htmlize. And of course both Xemacs and emacs22GTK both use the same configuration file, so I can use the same functionality in emacs22GTK which works a little better most of the time.

**Edit
Not long after I wrote this entry I dumped emacs22gtk because it is buggy and apparently has been for years. It turns out that emacs22GTK, which is the default emacs version for gnome, will temporarily lockup the desktop when you remove focus from emacs in gnome. This lockup is temporary it lasts a couple of minutes at most and does not affect the X server. The mouse and keyboard will work but all inputs will be locked out of any client running on the desktop. You can switch to a vt and kill emacs or just wait it out, it will go a way. Then replace it with emacs22X11 or XEmacs.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s