htmlize.el by HrvojeNiksic is a package for exporting the contents of an Emacs buffer to HTML while respecting display properties such as colors, fonts, underlining, invisibility, etc. Get it from:

The conversion is quite sophisticated, it understands non-ascii characters, looks up colours in the X11 RGB database, and can generate either css or old style font bits.

Its typical usage is to export fontified (syntax-highlighted) source code as HTML, but it can be used for any Emacs buffer, such as Gnus or org-mode buffers. The resulting HTML can be used by other tools, published on the web, printing, etc.

The following packages use or extend htmlize,

See also HtmlFontify which does similar things. However, HtmlFontify appears not to support converting a region which is really practical for publishing small snippets on blogs.

Converting a region is supported in hfyview.el (which uses htmlfontify.el).

You can use this package to render code snippets with syntax highlighting when exporting Org-mode files to HTML., see manual “Literal Examples”, 6.26 d, Chapter 12, p. 102, footnote1. – StefanVollmar

See also by Volkan YAZICI which is a small shell script wrapped around htmlize.el with some syntax highligting enhancements for particular emacs modes. Moreover, has an extensible syntax recognition enhancement module that you can introduce new functionalities relatively easily; e.g., it provides CLHS and MOP symbol linking capabities for lisp-mode. (See README file for details.)

htmlize.el has some conflicts with rainbow-delimiters-mode, functions such as htmlize-buffer will report an error: htmlize-make-face-map: Wrong type argument: listp, "rainbow-delimiters-depth-1-face", so I do a small hack to overcome this by using the elisp’s defadvice utility.

Here’s the code:

(defadvice htmlize-buffer-1 (around ome-htmlize-buffer-1 disable)
  (rainbow-delimiters-mode -1)
  (rainbow-delimiters-mode t))

(defun ome-htmlize-setup ()
  (if (el-get-read-package-status 'rainbow-delimiters)
        (ad-enable-advice 'htmlize-buffer-1 'around 'ome-htmlize-buffer-1)
        (ad-activate 'htmlize-buffer-1))))

CategoryFaces CategoryHypermedia