Blogging is probably the best way to disseminate information about new
(features in) libraries in the Lisp community—if you are reading
this, you are probably subscribed to Planet Lisp, which nicely
aggregates all Lisp-related blogs that are registered. On the other
hand, blogging about Lisp is—or was—quite a hassle to me. I am
using Google's blogger.com, which has nice features, but I am used to
Emacs and prefer typing text there. Including Lisp code snippets was
a pain in the butt: I had to keep playing with <pre>
tags and it
still didn't look right. But now I had a bit of time to explore the
issue and found a workflow that is
- pretty painless and
- does syntax highlighting.
It uses org-mode, which I already use to manage my agenda. I would like to thank EMACS-FU, Blogistic Reflections, Drew Crampsie, Ross Lonstein, and Jānis Džeriņš for their help and/or blog posts on using org-mode.
Here is what you should do:
-
In Emacs, set
org-export-htmlize-output-type
tocss
. This makesorg-mode
emit formatting with<span>
elements instead of inline style directives, which is the default. -
Open a source file with
org-mode
(egsample.org
). Leave it empty, we just need it to generate some CSS. Use the Emacs functionorg-export
(usuallyC-c C-e
), and extract the CSS part. This is the first part of all the CSS styling you need. -
Generate the second part with
org-export-htmlize-generate-css
. -
Paste both parts into the CSS section served by your blog engine.
For example, on blogger.com you should go to Layout, then Edit HTML, and paste it after the
<Variable name=...>
section where the CSS formatting starts. There will be some overlap between the two parts and possibly your existing template, but it should not matter. Edit colors, fonts, etc to the style you want. All I did was change the colors for the<pre>
tags. -
Turn off auto-conversion of line breaks. On blogger.com, you
can find Convert line breaks in the Settings/Formatting
section. Unless you do this, your blog engine could introduce
unnecessary
<br/>
tags in the HTML.
You are now ready to post. A simple example looks like this in org-mode:
#+TITLE: Sample blog post #+AUTHOR: Your Name #+EMAIL: your@email.address #+LANGUAGE: en #+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:tl creator:nil #+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil tags:not-in-toc author:nil timestamp:nil #+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js Here is some sample source code: #+BEGIN_SRC lisp (defun add2 (x) (+ x 2)) #+END_SRC You can include example output: #+BEGIN_EXAMPLE CL-USER> (add2 3) 5 #+END_EXAMPLE See the [[http://orgmode.org/org.html][Org Manual]] for further details.
You can include formatting options as shown in the example.
I use the following snippet in Emacs for settings and keybindings:
(defun org-export-body-as-html () (interactive) (org-export-as-html 3 nil nil "blog" t)) (add-hook 'org-mode-hook (lambda () (setq org-export-htmlize-output-type 'css) (local-set-key (quote [?\C-c ?\C-x]) 'org-export-body-as-html)))
Wow, very cool!
ReplyDeleteOMG, this is perfect.
ReplyDelete