Epub to markdown (or gempub) converter
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sloum ca08d18235 Updates gpubs to support links 3 months ago
.gitignore Updates gpub parsing to take hgroups into account in a special way 3 months ago
README.md Updates gpubs to support links 3 months ago
go.mod Adds word wrap via an optional flag 3 months ago
go.sum Adds word wrap via an optional flag 3 months ago
gpub.go Updates gpubs to support links 3 months ago
main.go Updates readme and corrects some markdown rendering and adds a nocover option 3 months ago

README.md

epub-to-md

The slightly misnamed, but grandfathered in, epub-to-md can convert an epub to a markdown file or a gempub file.

There are a few caveats to the generated content:

  1. Links are removed and only their inner text remains
  • This is not true for gpub documents, they retain links which are set up as reference links (a number next to the link) and the actual link is found at the end of each chapter next to the given reference number. This allows for gemtext style link lines
  • When generating a gpub gemtext links are also used for the table of contents
  1. Images and svg elements are removed
  • Cover images are retained in gpub documents unless the -nocover flag is passed

Both of the above are done in order to retain a self-sufficient file containing the content of the text. The goal of this converter is to convert novels and other works of fiction, which do not generally require many links or images. It may not be the best tool for all types of written work.

The converter can also wrap markdown text at arbitrary widths greater than zero.

When greating a gpub file the converter still converts to markdown. As such any bold or italics in the text will have markdown style formatting that may not render as formatting in gempub readers. At present there are few readers for the format. The two that I know of are: lagrange and gpr. Both are able to read gempub files generated by epub-to-md. Unlike the conversion to markdown, converting to gempub does retain the cover image as a part of the gempub file output. To save on file size, especially in text only environments, the cover can be omitted from the gpub file with the -nocover flag. If a cover is included and an svg is used in the original epub file, epub-to-md will attempt to call out to inkscape to convert the file to a png. If inkscape is not present, building the cover will fail since svg is not a valid filetype for a gempub cover. Lastly, since gemtext uses * at the beginning of a line to denote a list item, the markdown that is generated for the gpub will follow suit. To avoid confusion both italics and bold will use their underscore form rather than the form involving asterisks.

Usage

epub-to-md [options] [[path]]

 -h    display help
 -gpub
       Generate a gpub file from an epub input
 -nocover
       Do not include a cover when generating a gpub 
 -o string
       Output file location (default "stdout")
 -w int
       Wrap text to the given width

 
 The path can be omitted to use the current directory
 as if it were an uncompressed epub file.

 If a path is given, it should be a path to an epub
 file or a path to a directory representing an epub
 (it will have a 'content.opf' file in it somewhere).

 If the -gpub flag is given, the -w option will have
 no effect.

 Examples:

  epub-to-md -w 80 -o book.md ./book.epub
  epub-to-md       -o book.md ./my-book-project/
  epub-to-md       -o book.md
  epub-to-md -gpub -o book.gpub ./book.epub
  epub-to-md -gpub -nocover     ./book.epub