02-07-2021, 03:45 PM | #1 |
Enthusiast
Posts: 47
Karma: 10
Join Date: Jan 2021
Location: Italy
Device: Kobo Libra 2, Kindle Paperwhite (1st gen)
|
How to combine chapter titles and subtitles
Hello, I have a problem with chapter detection in the calibre editor.
I have a book in which each chapter is defined like this: Code:
<h2>Chapter XX<h2> <h3>Title of the Chapter<h3> Do you have any idea how to do this? Thank you |
02-07-2021, 03:57 PM | #2 |
Resident Curmudgeon
Posts: 75,049
Karma: 131375774
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Save the eBook so you have it as is. Then do a regex search (check the dot all box on the Mode: line) for....
Code:
<h2>(.*)<h2>.<h3>(.*)<h3> Code:
<h2>\1: \2<h2> Last edited by JSWolf; 02-07-2021 at 04:05 PM. |
Advert | |
|
02-07-2021, 04:18 PM | #3 |
Enthusiast
Posts: 47
Karma: 10
Join Date: Jan 2021
Location: Italy
Device: Kobo Libra 2, Kindle Paperwhite (1st gen)
|
It didn't work, but that could actually be my fault, as the code I put in the first post was a simplified example and is not exactly the same. I'll put an actual extract:
Code:
<h2 id="sigil_toc_id_1">CAPITOLO I.</h2> <h3 id="sigil_toc_id_2">Come Candido è allevato in un bel castello e come n'è cacciato via.</h3> |
02-07-2021, 04:52 PM | #4 | |
Bibliophagist
Posts: 37,859
Karma: 150333332
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Quote:
<h2 (.*?)>(.*?)</h2>{add EOL and spaces here}<h3 (.*?)>(.*?)</h3> Replace: <h2 title="\2: \4">\2<br />\4</h2> |
|
02-07-2021, 05:20 PM | #5 |
Enthusiast
Posts: 47
Karma: 10
Join Date: Jan 2021
Location: Italy
Device: Kobo Libra 2, Kindle Paperwhite (1st gen)
|
|
Advert | |
|
02-07-2021, 06:13 PM | #6 |
Bibliophagist
Posts: 37,859
Karma: 150333332
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
|
02-07-2021, 06:48 PM | #7 |
Grand Sorcerer
Posts: 24,905
Karma: 47303822
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
What I frequently do for this is to change to styled paragraphs and a separate heading for the ToC that is not displayed. So, I would have:
Code:
<h2 class="hidden">Chapter XX: Title of the Chapter</h2> <p class="chapterNumber">Chapter XX</p> <p class="chapterTitle">Title of the Chapter</p> Code:
.hidden { display: none } Code:
<h2>Chapter XX <br/><span class="chapterSubtitle">Title of the Chapter<h2> The regex search I would use is: Code:
<h2>(.*?)</h2>\s*<h3>(.*?)</h3> Code:
<h2 class="hidden">\1: \2</h2><p class="chapterNumber">\1</p><p class="chapterTitle">\2</p> Code:
<h2>\1 <br/><span class="chapterSubtitle">\2<h2> And I'll go on record: I think that the method that @JSWolf suggested is a really, really bad idea. |
02-07-2021, 07:31 PM | #8 |
Resident Curmudgeon
Posts: 75,049
Karma: 131375774
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Search and replace out the IDs in <h2> and <h3>. Also search/replace out all blank lines and any space in front of the <h2> and then my search/replace will work.
|
02-08-2021, 09:42 AM | #9 |
Enthusiast
Posts: 47
Karma: 10
Join Date: Jan 2021
Location: Italy
Device: Kobo Libra 2, Kindle Paperwhite (1st gen)
|
First of all, thank you everyone for your help, I feel like I'll never learn how to properly use regex without a starting expression to edit, it's too broad and confusing for me
I found it odd that there wasn't a thread already of someone with this problem, so I'm trying to be detailed in case someone needs this in the future. In the end I took the first idea by Davidfor and modified it a bit to keep as much of the original tagging as possible. Here's the string I used to find (I added the part to detect the ids of the tags): Code:
<h2 id="sigil_toc_id_\d{1,2}">(.*?)</h2>\s*<h3 id="sigil_toc_id_\d{1,2}">(.*?)</h3> Code:
<h2 class="hidden">\1 \2</h2><h2 class="ChapterTitle">\1</h2><h3 class="ChapterSubtitle">\2</h3>
|
02-08-2021, 09:59 AM | #10 |
Enthusiast
Posts: 47
Karma: 10
Join Date: Jan 2021
Location: Italy
Device: Kobo Libra 2, Kindle Paperwhite (1st gen)
|
Ok, now it seems Calibre Viewer doesn't like the new ToC, as those links to the hidden elements don't work. I tried two other viewers (Adobe DE and Google Play Books) and they work without a problem, strange..
|
02-08-2021, 09:19 PM | #11 | |
Grand Sorcerer
Posts: 24,905
Karma: 47303822
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
Edit: The ToC generation is using a the h2 and the hidden class for the second level. It looks like it should work. Can you show use the generated NCX code? And the actual code at the top of the matching chapter. That might give a hint as to what is wrong. And that is an interesting idea. What I do is easy if the chapter heading already use well defined classes. But, if they are bare heading tags, I have to add classes. With that, I could rely on the existing stylesheet a bit more. Last edited by davidfor; 02-08-2021 at 09:25 PM. |
|
02-09-2021, 05:52 AM | #12 | ||
Enthusiast
Posts: 47
Karma: 10
Join Date: Jan 2021
Location: Italy
Device: Kobo Libra 2, Kindle Paperwhite (1st gen)
|
Quote:
Code:
<navPoint id="num_5" playOrder="5"> <navLabel> <text>CAPITOLO I. Come Candido è allevato in un bel castello e come n'è cacciato via.</text> </navLabel> <content src="Text/Section0004.xhtml#toc_1"/> </navPoint> Code:
<h2 class="hidden" id="toc_1">CAPITOLO I. Come Candido è allevato in un bel castello e come n'è cacciato via.</h2> That suggests me that the problem is on how calibre manages the display: none rule, as the link works on the source html, but not on the resulting file. I might be wrong though. Quote:
|
||
02-09-2021, 06:32 AM | #13 | |
Resident Curmudgeon
Posts: 75,049
Karma: 131375774
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
Also, it would be easier to find what's in what file if you renamed your files. So if Section0004.xhtml is chapter one, name it chapter01.xhtml. |
|
02-09-2021, 06:53 AM | #14 | ||
Grand Sorcerer
Posts: 24,905
Karma: 47303822
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
If the book has copyright, you can use the ScrambleBook plugin to produce a version that can be posted here. Quote:
|
||
02-09-2021, 06:56 AM | #15 | ||
Grand Sorcerer
Posts: 24,905
Karma: 47303822
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
Quote:
|
||
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Where do displayed chapter titles come from? | JJ Johnson | ePub | 11 | 10-17-2020 07:15 PM |
Chapter #s or Chapter Titles? | bmcox | Writers' Corner | 33 | 02-01-2013 07:03 AM |
Titles, subtitles & alternative "display" titles | jigme | ePub | 2 | 08-31-2011 05:19 PM |
Ebook chapter titles: with or without chapter number? | amoroso | Writers' Corner | 16 | 06-14-2011 06:35 AM |