|
|
Thread Tools | Search this Thread |
09-02-2024, 08:00 AM | #1 |
Member
Posts: 10
Karma: 10
Join Date: Sep 2024
Device: none
|
how to use command line to automatically create ToC from all headings?
Hello,
I want to use the command line to convert an html book to epub and select the setting "Generate ToC from all headings." I don't see this option available in the command line interface in the documentation, but it is available in the calibre edit GUI. Currently, I have to drag the html into calibre, convert to epub, click edit on the converted file, open the ToC GUI, delete the auto-generated ToC, then click "Generate ToC from all headings". Can someone tell me how to automate this process from the command line with ebook-convert, ebook-edit, or some other tool? Thank you! |
09-02-2024, 09:07 AM | #2 |
creator of calibre
Posts: 44,542
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
Advert | |
|
09-02-2024, 09:50 AM | #3 |
Member
Posts: 10
Karma: 10
Join Date: Sep 2024
Device: none
|
I looked at that documentation and I don't see an option for exactly what I'm looking for.
Is there a flag for "Generate ToC from all headings"? When I click that button in the GUI, the ToC comes out perfectly. I just don't see a command-line flag for that setting. Can you please point me to it? |
09-02-2024, 10:00 AM | #4 |
Well trained by Cats
Posts: 30,444
Karma: 58055868
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
ebook-convert input_file output_file [options]
Did you scroll down in the Help file? There is a TOC section with options |
09-02-2024, 04:07 PM | #5 |
Member
Posts: 10
Karma: 10
Join Date: Sep 2024
Device: none
|
I do not see any setting described in the help documentation that does what I am asking for. I specifically want a command line option that matches the GUI button for "Generate ToC from all headings"
None of the flags in the documentation that I've found describe that option. Do you know how I could select that setting from the command line? |
Advert | |
|
09-02-2024, 11:45 PM | #6 |
creator of calibre
Posts: 44,542
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
There is no such flag. You need to specify the level1 through level3 settings manually. The button in the GUI does just that under the hood. Read their docs to understand what you need to put there, or look at the conversion log of the GUI conversion to see what values those settings have.
|
09-03-2024, 08:56 AM | #7 |
Member
Posts: 10
Karma: 10
Join Date: Sep 2024
Device: none
|
Alright, thank you for clarifying.
Also, thanks for making Calibre and releasing it for free. I am a big fan of the software. |
09-03-2024, 09:16 AM | #8 |
Member
Posts: 10
Karma: 10
Join Date: Sep 2024
Device: none
|
I hate to keep asking for help but - can you tell me where the conversion logs are stored?
I tried running calibre-debug --gui and calibre-debug --edit-book and those logs didn't contain the ToC conversion commands. And I don't see a reference to conversion logs in the manual: https://manual.calibre-ebook.com/edit.html I tried running calibre in debug mode as suggested here (https://www.mobileread.com/forums/sh...d.php?t=344814) but those logs didn't contain the conversion details. How can I access the conversion logs? Thank you for your help! |
09-03-2024, 10:35 AM | #9 |
Wizard
Posts: 1,082
Karma: 1221485
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
|
09-03-2024, 12:45 PM | #10 |
Well trained by Cats
Posts: 30,444
Karma: 58055868
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
09-03-2024, 03:55 PM | #11 |
Bibliophagist
Posts: 40,536
Karma: 157444380
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
A couple of message back, Kovid Goyal suggested running a GUI conversion and looking at the log from that to see what values the level1 to level3 settings were using.
The problem I see with that is that after the conversion, the OP was opening the ebook in calibre's ebook-editor, deleting the ToC generated in the GUI mode conversion and using the ebook-editor to recreate it with "Generate ToC from all headings" button. I suspect that the OP might be able to do this by playing with the XPath for the levels so any h? tag would be used to create a ToC entry. Something like //*[name()='h1' or name()='h2' or name()='h3' or name()='h4' or name()='h5' or name()='h6'] though I haven't played enough with XPath to feel comfortable making recommendations. Last edited by DNSB; 09-03-2024 at 04:10 PM. |
09-03-2024, 04:35 PM | #12 |
Well trained by Cats
Posts: 30,444
Karma: 58055868
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Me neither
But looking at the CLI, I suspect that xpath needs to be separated into 3 because the CLI has a separate option for each level ebook-convert input_file output_file --level1-toc <xpath> --level2-toc <xpath>--level3-toc <xpath> |
09-03-2024, 05:56 PM | #13 |
Bibliophagist
Posts: 40,536
Karma: 157444380
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
I think what I posted would handle multiple h? headings for testing. The OP might want to split out the various headings for other purposes but for testing, what I posted should work though I haven't tested it.
|
09-04-2024, 02:23 PM | #14 |
Member
Posts: 10
Karma: 10
Join Date: Sep 2024
Device: none
|
Thank you DNSB. I just realized the ToC-setting command that I'm looking for isn't in the conversion logs for exactly the reason you describe - I update the ToC after conversion. If there's a way to access the editor's logs, that would help.
Otherwise, I'll look into this Xpath suggestion. I'm new to Xpath and epub design, but I'm curious why there are only three levels of command-line flags (--level1-toc,--level2-toc,--level3-toc) when the ToC could be nested deeper than that. Does "level 1/2/3" in those flags refer to the nesting depth of a particular element in the ToC? |
09-04-2024, 02:40 PM | #15 |
Member
Posts: 10
Karma: 10
Join Date: Sep 2024
Device: none
|
Thank you DNSB for the suggestion, that was very helpful.
I am so close! I have the Xpath expression I can use in the editor which lets me enter separate XPath expressions for header-depths of 1-5. However, the command-line tool ebook-convert only has flags for levels 1-3 (--level1-toc, --level2-toc, --level3-toc). Is it possible to use the command line tool to generate a toc with levels 4+5? |
Tags |
toc, toc creation |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
create a useable TOC when book uses images for chapter headings | stumped | Sigil | 23 | 06-09-2019 04:12 PM |
How to insert automatically valid id's in ToC headings? | chaot | Editor | 18 | 02-01-2017 07:55 AM |
Generated TOC at beginning of PDF via command line | alexandreaquiles | Conversion | 1 | 10-12-2014 04:24 AM |
HTML to Epub conversion isn't generating TOC through command line | marcosalles | Conversion | 1 | 02-20-2014 11:09 PM |
Calibre Command Line Interface TOC | bcolflesh | Calibre | 3 | 02-04-2010 05:09 PM |