![]() |
#1 |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Aug 2023
Device: BOOX Note 5+
|
TXT to EPUB: How to Make Chapter Markers as Titles
Hello there. I have a novel in .txt format and I want to convert it to .epub format. Since there's no tags decorating chapter markers (hashtags or <h2> tag) in the original text, I used regular expression (`//*[re.test(., "<regexp>", "i")]`) in structure detection to find out all the chapters.
The chapters are detected correctly, however, the chapter markers are treated as ordinary text. Is it possible to let Calibrie understand that the detected chapter marker are titles/headers? For example, If I have something like: ``` Chapter 1 Chapter Name some text some text ``` I want it be something like ``` # Chapter 1 Chapter Name some text some text ``` in the .epub output. That is, give the chapter marker/title a different format from ordinary text. |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
txt is internally converted to HTML and that is what the expression applies too. You can see the HTML using the debug section of the conversion dialog.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,745
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
#4 | |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Aug 2023
Device: BOOX Note 5+
|
Quote:
``` ... <p>final sentence of last chapter</p> <p class="whitespace" style="text-align:center; margin-top:0em; margin-bottom:0em">*</p> <p>Chapter X</p> <p>first sentence of current chapter</p> ... ``` After detecting structure, it becomes ``` ... <p>final sentence of last chapter</p> <p class="whitespace" style="text-align:center; margin-top:0em; margin-bottom:0em">*</p> <div style="display: block; page-break-after: always"></div> <p id="calibre_toc_X">Chapter X</p> <p>first sentence of current chapter</p> ... ``` But what I want is something like ``` ... <p>final sentence of last chapter</p> <p class="whitespace" style="text-align:center; margin-top:0em; margin-bottom:0em">*</p> <div style="display: block; page-break-after: always"></div> <h2 id="calibre_toc_X">Chapter X</h2> <p>first sentence of current chapter</p> ... ``` Pay attention to the line of Chapter X, I want it to become a title. Is it possible to achieve this in Calibrie? |
|
![]() |
![]() |
![]() |
#5 |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Aug 2023
Device: BOOX Note 5+
|
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
you want something like
Code:
//h:p[re.test(., '^Chapter.*', 'i')] |
![]() |
![]() |
![]() |
#7 | |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Aug 2023
Device: BOOX Note 5+
|
Quote:
|
|
![]() |
![]() |
![]() |
#8 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You cannot change tags, but using the correct expression will allow you to mark those tags as chapter starts with either a pagebreak or a rule above.
|
![]() |
![]() |
![]() |
#9 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 61
Karma: 582370
Join Date: Apr 2023
Device: Kobo Clara 2E
|
Why not use <b>Search and Replace</b> to change <p> to <h2>?
E.g: search for "<p>(Chapter [0-9]+)</p>" replace with "<h2>\1</h2>" |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Epub to Mobi with apostrophes in chapter titles | Applebaker | Conversion | 4 | 08-04-2017 07:29 AM |
Chapter Markers | jakann86 | Kindle Formats | 5 | 09-01-2013 09:32 AM |
Converting txt to epub, chapter heading contains number | NMinker | Conversion | 2 | 11-01-2011 11:30 AM |
Converting EPUB to MOBI - missing chapter markers | peartree | Amazon Kindle | 10 | 04-01-2011 06:02 PM |
Chapter Markers? | djulian | Calibre | 3 | 11-20-2010 11:15 PM |