My dear coding addict, once you've made some code snippet you'd like to share. You've posted it, and saw that formatting is crap. Literally, there's no formatting. Thanks G-d, you've read W3C papers and know, that there is a <pre> tag, so you wrap your beloved snippet with tags, look at result and see that there's no highlights. Now it's time to google.
Google will show you several results, which you could even like and use. But the point is that most popular solutions for this task require some massive JavaScript code and serious regular expression job to be done at client side, to replace monotone text with all that fancy coloured pieces. Don't know what about you, but I don't like such solutions.
There's also several specific off-line libraries to do highlighting for you, which I don't like either.
What to do? The answer is simple: DRY, why repeat job already been done with your favourite text editor? Go on and install htmlize.el (for me, Debian addict, it worked by typing sudo apt-get install emacs-goodies-el). This piece of magic extracts current colour scheme from your system and creates an HTML code with appropriate highlights. Having a code snippet in buffer, just type M-x htmlize-buffer (or htmlize-region if you want to htmlize just a piece of buffer) and Emacs will pop up a buffer with 100% pure, ready-to-use HTML code, with separate CSS and all that fancy things. If you, just as I do, plan to paste lots of code, simply put code styles to your blog template and that's it. After that you'll just need to copy-and-paste HTML.
God bless Emacs!
Wednesday, November 12, 2008
Subscribe to:
Post Comments (Atom)

Any decent editor can do that.
ReplyDeleteLooking at amount of external solutions, I came to conclusion that people doesn't use 'decent' editors, or this feature is not obvious at all.
ReplyDeleteThat depends on what you're calling external solution. Does script/plugin count as external solution? I guess no, which leaves us with only two decent editors, just like it was for ages =)
ReplyDeleteBy 'external' i mean this. Plugins for editors are awesome, but looks like noone really uses them.
ReplyDeleteI wouldn't go as far as saying that nobody uses them =).
ReplyDeleteHow do I get rid of your captcha? It's annoying.
Turned if off globally. I'm not that popular to hide from spambots :D
ReplyDelete