txt2mobi
is a simple tool for converting txt file to Mobi format for kindle. It's Based on golang package mobi.
Note
: All testing were done on Kindle App for windows and Kindle Paperwhite (10th Gen)
PS: Any html element in text file would make effect.
Get the following packges.
- github.com/766b/mobi
- github.com/BurntSushi/toml
- golang.org/x/text/encoding/simplifiedchinese
support default cover:
- github.com/golang/freetype/truetype
- github.com/nfnt/resize
- golang.org/x/image/font
- github.com/fogleman/gg
Install go-bindata
go get -u github.com/jteeuwen/go-bindata/...
Run the build cmd:
go-bindata -o assets/asset.go -pkg=assets assets/...
go build
-
Prepare the cover,thumbnail and txt file
-
Create a config file witch you can refer to example.toml
-
Run the command:
[linux]$./txt2mobi -f example.toml [- o output_file_name.mobi] [-p]
#for Windows
[windows]$ txt2mobi.exe -f example.toml [- o output_file_name.mobi] [-p]
require:
-config
: config file
or
require:
-f
: input file-title
: book title-author
: book author-cover
: book cover and thumbnail-chapter
: chater title regexp pattern
options:
-subchapter
: subchapter title regexp patterncompress
: is to compress the resultencoding:
: use gb18030 as default
other options:
-o
: output file name-p
: is to use '<p></p>' to pack every paragrahes.-escape
: to disable html escape
title="Example"
author="zhengxin"
file="example.txt"
cover="cover_example.jpg"
thumbnail="cover_example.jpg"
chapter="^Chapter\\.\\d+.*$"
subchapter='^Chapter\\.\\d+\-\\d+ .*$'
compress=false
Note:
title
: If the output_filename is not given, thetitle
would be used as default.chapter
: A regexp pattern to determin the chapter line title.compress
: If it's true, the output would be compressed witch make the file smaller but take mush time to finish.encoding
: Options. Useutf-8
as default. Also supportgb18030
andgbk
.
This tool is ready simple but modifis all need for me. Email me if you really desire it.
The prefixed blank would be ignore because of html decoding.