How to use org-mode to write blog

October 10, 2010 at 4:51 am Leave a comment

I begin to write blog recently, naturally I choose org-mode to do this
task. However, org-mode export to html with whole page of html tags with
head and body. While writing to blog, we only need the body part. When I
just copy the body part, I loose its format. If I copy the whole html,
blogspot general some unwanted space, title, etc and I also lost title
link. I read about html and css and realized that if I can
change the template of, add those css, I should be able to
keep the format. Read google’s own online help, and then I changed my
template, done! Only thing left is that I still need manually copy body
part. After a long search, I known that there is a variable
org-export-as-html whose fifth option can be set to body-only
(refer to discuss part in EMACS-FU ). But I known very little about
lisp. A promising setting is from

|   (setq html (org-export-region-as-html beg end t 'string))

I tried substituting the string with body-only, but it’s wrong.
Thanks to Tamas K Papp’s blog, who gives the whole solution. The only
thing I didn’t follow his solution is CSS apart for syntax highlight,
since inline-css works for me. If I choose ccs instead of inline-css,
local html will be generated without syntax hight.

So the whole step is

  1. Copy CSS part of a org-mode generated html into template of blogspot
    (Only part 1 of CSS mentioned in Tamas K Papp’s blog). The first
    line should be removed, since it cause some problem, especially when
    I use them in, it cause <pre> part not overflow
    (scroll bar not shown when space is not enough), i.e.

    html { font-family: Times, serif; font-size: 12pt; }

    The location
    is to add CSS is

     * Varaible definitions apart
      CSS you added
      original CSS setting
  2. add following line into .emacs file

    (defun org-export-body-as-html ()
    (org-export-as-html 3 nil nil "blog" t))
    (add-hook 'org-mode-hook
           (lambda ()
             (local-set-key (quote [?\C-c ?\C-x]) 'org-export-body-as-html)))
  3. Use C-c C-x to generate body part of the blog
  4. Use scribefire to update blog and preview the results. I feel this is
    more convenient than webloger.el. Since webloger.el cannot update
    title and set label, I have to manually change it every time if I use
    this. Need use new version scribefire, old version have bugs, when
    encounter `<‘ and `>’ inside <pre> tags, it convert them into `&lt’,
    and ‘&gt’ respectively. While <pre> tags may have other tags inside
    them, especial for color setting <span>.

  5. If use blogspot to update blog, in post option part, choose Use br tags. Otherwise, unwanted line breaks will be added.

Entry filed under: Emacs.

Hello world! Ssh tunnel for security web access in insecure web connection

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

Recent Posts


Blog Stats

  • 1,262 hits

%d bloggers like this: