View Full Version : How to automatically create chapter titles and breaks in an epub file?


memenow
11-26-2012, 02:08 PM
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

Doitsu
11-26-2012, 04:35 PM
Since your souce file is a text file, you could simply use Markdown (http://en.wikipedia.org/wiki/Markdown) to mark headings and convert the text file with Calibre to an ePub before editing it with Sigil.

(Select Convert books > TXT Input > Formatting Style: markdown before you convert the text file to an ePub file.)

mzmm
12-06-2012, 02:01 PM
bit late, but you could replace

(^\w+[^\n]+)(\s+(_)\3[^\n]+)

with

<h1>\1</h1>\2

and then generate the toc in sigil