title_body: How can I create an ebook from existing HTML files? I will be writing software that allows me to select stretching exercises, put them in order, and then create an ebook, one per page, and then use it on my kindle.  I was hoping that my software could produce the final ebook, e.g., mobi, but that seems unlikely (I can't find the spec for the file format).
  
  So my next idea is to produce a set of HTML files, a table of contents file, and manually use Calibre to convert it to mobi/azw and upload it to my kindle.
  
  I did the HTML part once years ago by creating the HTML files by hand so it should work.  But I was wondering if there is a better way?
upvoted_answer: You could also use Pandoc in conjunction with the kindlegen command-line tool.
  
  Converting your HTML files to Markdown files is not necessary but if done will allow (easier) conversion to other formats should the need arise later on.
  
  The table of contents can be automatically generated using Pandoc. Pandoc can export to the epub format which in turn can be converted to mobi using the kindlegen tool. It's possible to write a bash script to automate the process.
  
  Sample command using Pandoc to export to epub:
  
  pandoc -o myBook.epub myBook.md --toc \
  --epub-cover-image=cover.jpg \
  --epub-stylesheet=myStylesheet.css \
  --number-sections