Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 03-31-2022, 02:40 PM   #1
Skydog
Wizard
Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.
 
Skydog's Avatar
 
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
Question 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">
Skydog is offline   Reply With Quote
Old 03-31-2022, 03:08 PM   #2
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
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.
Attached Thumbnails
Click image for larger version

Name:	2022-03-31_16-00_light.jpg
Views:	88
Size:	76.0 KB
ID:	193019  

Last edited by lomkiri; 03-31-2022 at 03:19 PM.
lomkiri is offline   Reply With Quote
Old 03-31-2022, 03:21 PM   #3
Skydog
Wizard
Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.
 
Skydog's Avatar
 
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:
Originally Posted by lomkiri View Post
Use xPath (see screenshot)

But if the title of the entry, in the ToC, will be the content of your paragraph, so, in your case, it will be always "*", unless you put by regex an hidden text (with attribute display: none)
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".
Skydog is offline   Reply With Quote
Old 03-31-2022, 03:27 PM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
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)
theducks is offline   Reply With Quote
Old 03-31-2022, 03:41 PM   #5
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by Skydog View Post
Unfortunately, it did not work. The result was one entry in the TOC, (Untitled).
It's because the content of all your breaking paragraphs is always "*".
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.
lomkiri is offline   Reply With Quote
Old 03-31-2022, 04:17 PM   #6
Skydog
Wizard
Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.
 
Skydog's Avatar
 
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:
Originally Posted by theducks View Post
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)
Well, easy for some. With no clue what to do when the xPath box popped up, I entered what @lomkiri suggested above. So far so good, TOC populated with files. Everything you wrote after "Split Multiple" is like reading a foreign language to me. With individual chapter files available, I have typically selected them all and chosen rename with "bulk edit" beginning with Chapter 1. Are all the above steps you outline necessary too? None of the associated tutorials have been helpful to me as l am not a programmer.

As always, @the ducks, thank you very much for your help.
Skydog is offline   Reply With Quote
Old 03-31-2022, 04:21 PM   #7
Skydog
Wizard
Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.Skydog ought to be getting tired of karma fortunes by now.
 
Skydog's Avatar
 
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:
Originally Posted by lomkiri View Post
It's because the content of all your breaking paragraphs is always "*".
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...
Thank you again, lomkiri, for your assistance but the above is completely over my head. (As you might have read in my reply above to @theducks)
Skydog is offline   Reply With Quote
Old 03-31-2022, 04:34 PM   #8
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
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>
function:
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>'
It's important to choose "search all", if not, the numbers won't increase
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.
Attached Thumbnails
Click image for larger version

Name:	Screenshot_2022-03-31_17-24-50.png
Views:	70
Size:	6.5 KB
ID:	193020  

Last edited by lomkiri; 03-31-2022 at 04:42 PM.
lomkiri is offline   Reply With Quote
Old 03-31-2022, 06:33 PM   #9
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
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:
Originally Posted by Skydog View Post
Well, easy for some. With no clue what to do when the xPath box popped up, I entered what @lomkiri suggested above. So far so good, TOC populated with files. Everything you wrote after "Split Multiple" is like reading a foreign language to me. With individual chapter files available, I have typically selected them all and chosen rename with "bulk edit" beginning with Chapter 1. Are all the above steps you outline necessary too? None of the associated tutorials have been helpful to me as l am not a programmer.

As always, @the ducks, thank you very much for your help.
After the Xpath box, use the Wizard icon. (it opens another layer)
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
theducks is offline   Reply With Quote
Old 03-31-2022, 08:41 PM   #10
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by theducks View Post
After the Xpath box, use the Wizard icon. (it opens another layer)
fill in the boxes:
Tag type (* is any, but I prefer to narrow it down to p)
[...]
I've explained exactly this in the screenshot of my first message. But it doesn't work since the title of every entry will always be "*", so calibre criate only one entry in the ToC (it doesn't duplicate the entry if the title is the same) [note 1]

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.
lomkiri is offline   Reply With Quote
Reply


Forum Jump

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


All times are GMT -4. The time now is 09:19 PM.


MobileRead.com is a privately owned, operated and funded community.