BIT-101 [2003-2017]

My Kindle Authoring Setup Part 2 – now with Markdown!


As I was writing the previous post on my Kindle Authoring Setup, it occurred to me that markdown might be a solution to having to mark everything up with HTML tags. So I wrote a comment in there exactly as it hit my brain. After publishing that post, I went ahead and checked it out and it has worked beyond what I imagined.

First, I located the command line tool, pandoc (again, cross-platform, yay!) and installed that. Then I did some tests and was amazed how much it did. Read up on markdown syntax and was even further amazed. I’d say this writing/publishing flow is now as close to perfect as it can get.

First of all, I changed my concat target in the build.xml to use pandoc instead of ant’s concat.

[php lang=“xml”]










[/php]

Here we specify the output file with -o plus the output file name, then the list of input files. It will concatenate them and convert them from markdown to HTML, using the file extensions to determine the format.

Some brilliant things about markdown that make it perfect for this format:

H1’s can be either:

# This is a header

or

This is a header

Since I’m using H1’s for chapter names, I like the underline format.

H3’s, which I’m using for sections, become:

### This is a section title

All other paragraphs are just plain text. p tags are added automatically.

It automatically does the smart quote replacements.

Surrounding underscores like _this_ become em tags (italicized in the book).

Surrounding asterisks like *this* become strong tags (bolded).

There is also markdown for images, but I’m fine with keeping the HTML image tags in there. Any inline HTML in a markdown doc is automatically preserved, with some caveats as mentioned in the above referenced syntax doc. I’ll switch over to markdown syntax for images though, just to keep everything in one format.

If that were all there was, I’d be thrilled. But it does even more.

Any blocks of text that are indented with at least 4 spaces or 1 tab are surrounded with pre and code tags! Furthermore, any angle brackets in that section are turned into their HTML entity equivalents. So basically I can copy and paste my code as is. All I need to do it tab it over 4 spaces.

Finally, inline code style, like this are accomplished with back quotes `like this`.

Couldn’t be happier with this setup right now. I’m basically writing straight up plain text with straight up plain copy and pasted code and it’s all formatting to a perfect ebook with one click of a button.

« Previous Post
Next Post »