2009-06-26

Markdown from Emacs to Html (Blogger)

I use emacs to write blog posts for blogger. I write in the markdown syntax, then convert it to html using markdown (markdown mode for emacs, which invokes the perl markdown command).

However, when writing I have hard breaks and 80 column width to make it readable, markdown converts a paragraph to a paragraph tag, but does not remove the line breaks. When inserted into the blogger ("Edit html") it looks crap, random line breaks all over.

I tried to use pandoc, a great alternative to markdown, and it removes the line breaks as it should, but is then too clever for its own good. It makes tags that are syntactically correct but dont work in blogger, because the end tags have a newline embede in its whitespace. Like this:

<atag>helloo</atag
>

To fix this, I use a regular expression replace in Emacs. It is unfortunate that Emacs doesn't have Perl syntax for its regular expressions, but I was glad it hinted to me what I should do. When I wrote \n it suggested what to do:

"Note: \n here doesn't match a newline, try C-q C-j instead"

In the end I made a simple Emacs command for this and put it in my .emacs file. Run with M-x better-markdown. Happy ending!

;; Makes better formatting in a blog
(defun markdown-better ()
(interactive)
(save-excursion
(let ((buffer "*markdown-better*")
(pandoc-strange-end-of-tag "
*>")) ; This is Newline, space, *, >
(shell-command-on-region (point-min)
(point-max)
"pandoc"
buffer)
(switch-to-buffer buffer)
(replace-regexp pandoc-strange-end-of-tag ">"))))

2009-06-14

Ubuntu upgrade problems

The basic reason for running gnu/linux in a virual machine rather than on the hardware directly is that gnu/linux is messier than people pretend it is. Upgrading a distribution has failed more times than it has suceeded for me. With virtualization you can revert, or make a brand new machine and copy over the files instead.

But I still have a workstation which runs Ubuntu Hardy, and I want to update it.

sudo apt-get update
sudo apt-get dist-upgrade

file list for package linux-restricted-modules-common contains empty filename

sudo apt-get remove linux-restricted-modules-common

file list for package linux-restricted-modules-common contains empty filename
dpg: ../..src/packages.c:252 process_queue: Assertion !queuelen failed.

I see no alternative but to reinstall gnu/linux and hope it doesn't wipe my files. I don't enjoy messing with things like this, and want something up fast. I am dead tired of Ubuntu, but I see no good problemfree alternative. I recalled I had problems with Debian too, but I haven't really ran the stable version. So that is my first alternative now.