I like to write my ebooks as markdown file. I also don't want to have any publisher lock-in when writing my ebooks.
But I honestly could not find a straight-forward solution to create a nice epub out of a simple markdown file.
So I created a tiny command line application that can do that for you.
- Paul Siegmann's awesome epublib library is used to create an epub
- markdown to html conversion is done using Atlassian's cool commonmark parser
- General coolness is provided by Google's Guava
You have to have some knowledge about java, maven and how to build things (no coding skills needed).
You need the following files (naming is important):
- index.css (Some formatting)
- index.md (Your text with all chapters and sections)
- cover.png (A nice cover image)
- index.properties (Properties that specify author, title description and so on)
Simple. Looks like this:
# Note: This file should be utf-8 !!!
title=My ebook title
authorFirstname=Max E.
authorLastname=Coolman
description=The best book in the world
First of all you have to compile the source code of this repository and run
mvn clean package
This will create a jar file called markdown2epub-1.0-SNAPSHOT-jar-with-dependencies.jar in folder target.
Note: This could be done more user-friendly, but I don't have much time right now. Feel free to improve that :)
Then cd into the directory where your ebook markdown lives. You can check out the example directory and play around with it.
cd example
Then run
java -jar ../target/markdown2epub-1.0-SNAPSHOT-jar-with-dependencies.jar
This will create a file called output.epub in the same folder. That's it. You are done.
- You can use // at the beginning of a file in markdown to mark it as a comment. The line will be removed from the final epub.
- h1, h2 headings will be nicely splitted so that your epub reader can create a nice toc with proper navigation.
- http addresses will be converted automatically into links
- Tables can be created using the github approach: https://docs.github.com/en/github/writing-on-github/organizing-information-with-tables
- Very minimal. There's no support for images right now. I did not need it, so I did not add support...
- Not a single test. Yea. I just wanted to release and document this. So no tests, but that might change :)
I personally use Calibre to improve the epub and also create a mobi for my Kindle. Calibre got a nice command linetool called ebook-conver that I use:
# Add nice inline toc
/Applications/calibre.app/Contents/MacOS/ebook-convert output.epub output_final.epub --epub-inline-toc
# convert epub into mobi for kindle
/Applications/calibre.app/Contents/MacOS/ebook-convert output.epub output_final.mobi