I have a big file that is separated into categories with an underscore beneath each category name. The file is constantly changing and there are 80 categories. It is a plain text file. I would like to make it so that each category name is a separate chapter in an epub file. I would also like to make sure each chapter name is the title of the chapter. Is there a way to do this automatically with Calibre? Maybe some regex magic? For example, I would like the chapter titles for the categories below to be: Fruit, Vegetables, Herbs. And I would like it to be parsed automatically (one way to do this would probably involve recognizing the underscores in a regex expression). How can I do this?
Fruit
________
Apples
Bananas
Vegetables
____________
Cucumbers
Zucchini
Herbs
_____
thyme
cayenne
So your text file is basically an almost
markdownfile (read more). I would convert it tohtmlwith something likepandoc(see here, and note that pandoc supports some extendedmarkdownfeatures, and is very capable (even can generate epub too, but I did not tested that yet)).That way your headers (the underlined lines) would be translated to
<h*>tags.Then you can use for example Calibre's ebook-convert CLI tool (or the gui) to convert it to
mobiorepub, and specify the chapter breaks (thanks to the developers, Calibre has a really good documentation). (And I just noticed, that Calibre/ebook-convert can convert markdown directly to epub/mobi!)Like: