03-31-2022, 02:40 PM | #1 |
Wizard
Posts: 2,243
Karma: 7400001
Join Date: Mar 2009
Location: Circling Earth @ Mach .83
Device: Elipsa 2E, Sage, Forma, Libra 2, Clara 2E, Kindle Oasis3, Voyage
|
Create TOC from page breaks?
Is it possible to create a TOC in the editor when there are no "tags" or individual files present? I have several books that contain only a "Begin Reading" entry with one continuous file containing page breaks as shown below. My limited experience thus far is creating TOCs from files only. I do not want an inline TOC, just one for navigation. Is it possible to do this within Calibre's TOC editor without having to manually split 90+ chapters? Key phrase here: limited experience.
The following appears between "chapters": Code:
<p class="PAGE-BREAK">*</p> <p class="CN">*</p> <p class="CO"> |
03-31-2022, 03:08 PM | #2 |
Zealot
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
|
Use xPath (see screenshot)
But the title of the entry, in the ToC, will be the content of your paragraph, so, in your case, it always will be "*", unless you put by regex an hidden text (with attribute display: none) inside your paragraph. Last edited by lomkiri; 03-31-2022 at 03:19 PM. |
03-31-2022, 03:21 PM | #3 |
Wizard
Posts: 2,243
Karma: 7400001
Join Date: Mar 2009
Location: Circling Earth @ Mach .83
Device: Elipsa 2E, Sage, Forma, Libra 2, Clara 2E, Kindle Oasis3, Voyage
|
Thank you for your reply. Unfortunately, it did not work. The result was one entry in the TOC, (Untitled), which links to the original problem - the same as "Begin Reading".
|
03-31-2022, 03:27 PM | #4 |
Well trained by Cats
Posts: 29,800
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Splitting is easy. Right click in the code: Split Multiple.
Now what? you have files but no value for a title="" even if you change/inserted a <h# tag after each <body... You need some sort of number'er function to use as part of the REGEX adjusting the <h# title="value goes here" tag title= is used to make a TOC entry that does not match the tags visible text (if you use the TOC tool) |
03-31-2022, 03:41 PM | #5 | |
Zealot
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
|
Quote:
You need to create some numeration with a search using a regex-function, put it in an hidden text, as this, for exemple: <p class="PAGE-BREAK">*<span style="display:none"> Chapter 2</span></p> [...] <p class="CN" id="toc_2">*<span style="display:none"> Cn 6</span></p> or better, put your "display:none" in a class in the CSS and <p class="PAGE-BREAK">*<span class="toc_text"> Chapter 2</span></p> [...] <p class="CN" id="toc_2">*<span class="toc_text"> Cn 6</span></p> The regex-function can use the parameter "number" to numerate your entries __________ Edit: oops, I haven't seen Theducks' answer... Last edited by lomkiri; 03-31-2022 at 03:46 PM. |
|
03-31-2022, 04:17 PM | #6 | |
Wizard
Posts: 2,243
Karma: 7400001
Join Date: Mar 2009
Location: Circling Earth @ Mach .83
Device: Elipsa 2E, Sage, Forma, Libra 2, Clara 2E, Kindle Oasis3, Voyage
|
Quote:
As always, @the ducks, thank you very much for your help. |
|
03-31-2022, 04:21 PM | #7 | |
Wizard
Posts: 2,243
Karma: 7400001
Join Date: Mar 2009
Location: Circling Earth @ Mach .83
Device: Elipsa 2E, Sage, Forma, Libra 2, Clara 2E, Kindle Oasis3, Voyage
|
Quote:
|
|
03-31-2022, 04:34 PM | #8 |
Zealot
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
|
Here is an exemple how you can renumber your paragraphs, using "search all"
Change what you want (different titles?) in the regex-function. The numbers wont appears in your book (only in the ToC) if you put in your CSS the class: .toc_text{display: hidden;} I've put (in the function) : " chapter n" for PAGE-BREAK " cn n" for CN " level n" for CO change it to fit your needs _________ Search (select "regex-function"): find: Code:
class="((?:CN)|(?:PAGE-BREAK)|(?:CO))("[^>]*>)([^<]*)</p> Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): if number == 1: data['pg_br'], data['cn'], data['co'] = (0, 0, 0) span_d = '<span class="toc_text">' span_e = '</span>' if match.group(1) == "PAGE-BREAK": data['pg_br'] += 1 n = data['pg_br'] text = f'{span_d} chapter {n}{span_e}' elif match.group(1) == "CN": data['cn'] += 1 n = data['cn'] text = f'{span_d} cn {n}{span_e}' elif match.group(1) == "CO": data['co'] += 1 n = data['co'] text = f'{span_d} level3 {n}{span_e}' return f'class="{match.group(1)}{match.group(2)}{match.group(3)}{text}</p>' I've test the regex-function and the creation of the ToC (with only PAGE-BREAK as H1 and CN as H2), and it's working, here's the result of the test (screenshot) Edit: If you want that CN reinitiate at 1 after every PAGE-BREAK, or something similar, say it, it is easy to integrate this in the code. Last edited by lomkiri; 03-31-2022 at 04:42 PM. |
03-31-2022, 06:33 PM | #9 | |
Well trained by Cats
Posts: 29,800
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
fill in the boxes: Tag type (* is any, but I prefer to narrow it down to p) attribute class value: PAGE-BREAK accept, this creates the xpath Run that |
|
03-31-2022, 08:41 PM | #10 | |
Zealot
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
|
Quote:
That's why I've suggested to add a hidden text inside the <p></p> tags, so it will create one entry for every PAGE-BREAK, CN and CO. That's exactly what is doing the regex-function I wrote for him. ___________ [note 1] I realize just now that there is an option "Do not add duplicate entry [...]", and that unchecking this box solves the problem :-/. Anyway, it's nicer to have some numbers in the ToC than only stars at all levels. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
TOC page breaks problem | e_u | Kindle Formats | 4 | 10-06-2013 10:56 PM |
Sigil Adding Page Breaks in TOC! | jackibar | Sigil | 16 | 10-24-2012 01:20 PM |
How do I Create Page Breaks? | jdanniel | Sigil | 15 | 09-18-2012 06:15 AM |
Converting to PDF help? Bad page breaks and no TOC produced. | Jokerfwb | Conversion | 6 | 07-24-2012 10:36 PM |
Adding page breaks in Calibre breaks ePubcheck validation | bookraft | Conversion | 16 | 03-01-2011 01:23 PM |