HTML "screenshots" from Emacs

2017/10/17 emacs

htmlize, written by Hrvoje Nikšić, is a neat little Emacs package that converts face information from an Emacs buffer (or region) into HTML, effectively allowing the verbatim reproduction of what it looks like.

I found this so useful for blogging that I submitted a PR which saves marked up regions as self-contained <pre> snippets, complete with inline CSS. Hrvoje kindly merged the PR today, so now you can call htmlize-region-save-screenshot and the result will be saved into the kill ring. You can paste this into, say, a blog post written in Markdown or Mmark, such as this one, and get a "screenshot" like

(defun htmlize-region-save-screenshot (beg end)
  "Save the htmlized (see `htmlize-region-for-paste') region in
the kill ring. Uses `inline-css', with style information in
`<pre>' tags, so that the rendering of the marked up text
approximates the buffer as closely as possible."
  (interactive "r")
  (let ((htmlize-pre-style t))
    (kill-new (htmlize-region-for-paste beg end)))
  (deactivate-mark))

which is almost exactly what it looks like on my screen when it comes to colors and font style/weight, but using a different font of course. This allows integration of Emacs "screenshots" into blog posts without resorting to pixel-based formats, which would result from taking actual screenshots.

You can install htmlize from MELPA.

comments powered by Disqus
site not optimized for small screens, math may break