07-21-2023, 09:02 AM | #1 |
Wizard
Posts: 3,305
Karma: 10259306
Join Date: May 2016
Device: kobo forma, Kobo Libra, Huawei media Tab, fire HD10, PW3 HDX8.9,
|
is there an elegant solution to add hidden chapter numbers
i have a Wilbyyr Smith novel, which like many of his books has no actual chapters. the whole story is one big section...
but every so often there is a nifty egyptian heiroglyph image that starts each new " chapter". but its the same nifty image every time code starts like this <p class="textbreak"><img src="../images/00003.jpeg" alt="" or <p class="textfirst"><img src="../images/00003.jpeg" alt="" what I'd like to do within my own reading copy is have a hidden number at each of these locations which would appear in a generated toc as 1, 2, 3 ... like chapter numbers so if i select "chapter" 3 in the toc i get taken to the 3rd nifty heiroglyph.. i think sigil has some relevant tools but would welcome hints or even a full solution |
07-21-2023, 10:50 AM | #2 |
Guru
Posts: 692
Karma: 2180740
Join Date: Jan 2017
Location: Poland
Device: Misc
|
Your problem is relatively easy to fix. It all depends on the book code (i.e., that further part after alt="").
Here's the solution, which you may have to adapt to your actual code. 1. [Very important] Make yourself a copy of the EPUB file, just in case. 2. [Just in case] Check the file with the EpubCheck plugin. 3. Run the Access-Aide plugin, where all your Egyptian hieroglyphics + all other images in the book will be displayed. Yes, where there are hieroglyphs on the right insert manually numbering 1, 2, 3 etc. This will change the alt attribute (specifies an alternate text for an image). 4. Now just do the replacement Code:
<p class="(.+?)"><img src="../images/00003.jpeg" alt="(\d+)"/> Code:
<h1 title="\2"></h1><p class="\1"><img src="../images/00003.jpeg" alt="\2"/> 6. [Optional] Generate HTML table of contents. Check your image code and adapt it to your book, as my solution is more educational (maybe useful to someone) than definitive. |
Advert | |
|
07-24-2023, 07:55 AM | #3 |
the rook, bossing Never.
Posts: 11,166
Karma: 85874891
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
|
Dune and many Discworld novels have no named chapters. At a minimum you can simply add a bookmark at each "logical" chapter mark. Maybe even the start of the first paragraph as TOC text. A global edit can do that too.
|
07-24-2023, 09:00 AM | #4 |
A Hairy Wizard
Posts: 3,095
Karma: 18727053
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
I use the same basic procedure as BeckyEbook. However, I use the ReworkChapterHeads plug-in. That will automatically insert incremental IDs into a header tag.
Then, run a regex to incorporate the image into the header: Code:
With: <h3>1 (2, 3, 4, etc)</h3> <p class="textbreak"><img src="../images/00003.jpeg" alt="" /></p> Find: <h3>(\d+)</h3>\s*<p class="textbreak"><img src="../images/00003.jpeg" alt="" /></p> Replace: <h3 title="\1"><img src="../images/00003.jpeg" alt="" /></h3> If your reading device is at all modern, and supports CSS, then you could even trim that down with: Code:
Replace: <h3 title="\1"></h3> For example: Code:
h3 { display: block; background-image: url("../Images/img_ChHd.jpg"); background-size:2em 1em; width:2em; height:1em; margin:1em auto; content:""} * set sizes as needed for the image Last edited by Turtle91; 07-24-2023 at 10:04 AM. |
07-25-2023, 01:26 AM | #5 |
Wizard
Posts: 3,305
Karma: 10259306
Join Date: May 2016
Device: kobo forma, Kobo Libra, Huawei media Tab, fire HD10, PW3 HDX8.9,
|
thanks all
after much searching, i mostly did it manually folliowng this 2014 post. use regex to get numbers from ID tags... ( i skipped trying to hide chapter numbers behind a picture and instead i replaced the pictures with numbers [QUOTE=Doitsu;2933379]Unfortunately, Sigil only adds ids to heading tags, if there are multiple heading tags in a file. @Keeth: You'll have to outsmart Sigil and make it add sequential ids to each heading tag. Assuming that each chapter is a separate .html file and contains only one heading tag at the beginning of the file, for example <h3>Chapter</h3> do the following: 1. Replace all <h3>Chapter</h3> with <h3>Chapter</h3><h4>Chapter</h4>. 2. Regenerate the TOC. You should end up with: <h3>Chapter</h3><h4 id="sigil_toc_id_1">Chapter</h4> for the first chapter. 3. Replace all <h3>Chapter</h3> with nothing. I.e. delete them. |
Advert | |
|
07-25-2023, 01:42 AM | #6 | |
Wizard
Posts: 1,103
Karma: 4911876
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
So if you delete <h3>Chapter</h3>, then doesn't that still leave you with <h4 id="sigil_toc_id_1">Chapter</h4> at the start of each chapter? I thought you only wanted to see the icon/hieroglyph?
How does that then achieve what you first asked for?... Quote:
When I read the Dune series, the chapters numbers from most books were omitted. I simply added them and I didn't worry about keeping them hidden. Last edited by Karellen; 07-25-2023 at 01:46 AM. |
|
07-25-2023, 02:51 AM | #7 |
Wizard
Posts: 3,305
Karma: 10259306
Join Date: May 2016
Device: kobo forma, Kobo Libra, Huawei media Tab, fire HD10, PW3 HDX8.9,
|
if you locate the full post from 2014 it explains how to do it. when you regen the toc, each h4 gets an incremental toc-Id. so the toc ids now correspond to chapter numbers. regex does the rest.
you creat all the H4, generate the toc, delete all the H3, use regex to copy from incremental toc IDs in H4 to make chapter numbers i decided the picture was superfluous as it was same for each section - added no value. so I dropped the how to hide a number behind a citure ( the elegant bit) , as no one proffered an elegant (non manual ) way to do it now that the plug in has been mentioned, I could have probably done it with that. may try to in other wilbur smith books. pretty sure I had that plug in years ago, but lost it when changing computers, tehn failed to find it again. |
07-25-2023, 03:29 AM | #8 |
Wizard
Posts: 1,103
Karma: 4911876
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
I don't know what post from 2014 you are referring to, so I have no chance of finding it.
I thought @BeckyEbook gave you the solution to hide chapter titles. You don't need to hide it behind an image, it just remains invisible. The title="" makes the chapter number available to the TOC generator, but the empty value between the opening and closing h2 tags means nothing is displayed. <h2 title="Chapter 1"></h2> FWIW, when I come across a book with missing chapter numbers I add them using... Find: <body> Replace: <body>\n\n <h2>mm</h2> The above adds the header tags. Of course you need to be careful that you select the correct xhtml pages. Next I run a Regex-Function (in Calibre) to replace the mm with incrementing numbers. |
07-25-2023, 04:28 AM | #9 |
Wizard
Posts: 3,305
Karma: 10259306
Join Date: May 2016
Device: kobo forma, Kobo Libra, Huawei media Tab, fire HD10, PW3 HDX8.9,
|
ok
here's the sigil find replace steps i used after choosing NOT to preserve the picture. could be tweaked to preserve it i will try the title="" idea when i do another book replace the code for picture with H2 tags, carefully negotiating the neste spans find <p class="textbreak"><span class="dropcap"><span><img src="../images/00003.jpeg" alt="" class="calibre7"/> replace <h2>xchapter</h2><p class="calibre8"><span><span> find /h2> replace /h2><h3>xChapter </h3> .. then regenerate TOC then remove H2 .. find <h2 class="calibre7">xchapter</h2> replace blank the book code will now have incremental sigil id tags, one per chapter |
07-25-2023, 05:24 AM | #10 | |
Wizard
Posts: 1,103
Karma: 4911876
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
Quote:
You add a h2 tag, then you add a h3 tag, then you delete the h2 tag. What is the reason for adding <h2> and <h3> tags together? Why don't you add the h3 tag at step 1 if that is what you are wanting? |
|
07-25-2023, 07:20 AM | #11 |
A Hairy Wizard
Posts: 3,095
Karma: 18727053
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
|
07-25-2023, 08:25 AM | #12 |
A Hairy Wizard
Posts: 3,095
Karma: 18727053
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
If anyone else out there can see my posts...
As Karellen mentioned the title="" is the trick. Sigil will normally create a TOC using whatever is in the header tags...unless you put a title="{something}" into the header tag itself. Then Sigil uses that when creating the TOC. Super easy steps that take only a few seconds: Quote:
|
07-25-2023, 04:25 PM | #13 |
Wizard
Posts: 1,103
Karma: 4911876
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
I wonder if @Turtle91 would like to comment. Haven't seen him around for a while...
|
07-25-2023, 04:32 PM | #14 | |
Grand Sorcerer
Posts: 27,552
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
There are very few situations where Sigil itself will add ids to any tag. And none of those situations are predicated on there being more than one heading tag in a file. Last edited by DiapDealer; 07-25-2023 at 04:38 PM. |
|
07-25-2023, 04:47 PM | #15 |
Guru
Posts: 692
Karma: 2180740
Join Date: Jan 2017
Location: Poland
Device: Misc
|
@DiapDealer.
Surely this is the situation: Code:
<h1>Chapter 1</h1> <p>Blah, blah, blah</p> <h2>Subchapter A</h2> <p>Blah, blah, blah</p> <h2>Subchapter B</h2> <p>Blah, blah, blah</p> <h2>Subchapter C</h2> <p>Blah, blah, blah</p> Code:
<h1>Chapter 1</h1> <p>Blah, blah, blah</p> <h2 id="sigil_toc_id_1">Subchapter A</h2> <p>Blah, blah, blah</p> <h2 id="sigil_toc_id_2">Subchapter B</h2> <p>Blah, blah, blah</p> <h2 id="sigil_toc_id_3">Subchapter C</h2> <p>Blah, blah, blah</p> |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating hidden or invisible page numbers | jmurphy | Workshop | 9 | 03-10-2023 02:49 PM |
Remove Chapter Numbers | Rahm | Conversion | 3 | 11-04-2021 01:39 PM |
Free (nook/Kindle/iTunes/ePub) Elegant Solution [Xtian 1720s Mathematical Thriller] | ATDrake | Deals and Resources (No Self-Promotion or Affiliate Links) | 1 | 01-27-2015 10:43 AM |
Regex Solution to hidden href search? | MizSuz | Sigil | 16 | 09-29-2012 07:40 PM |
chapter numbers are graphical | alansplace | Sigil | 6 | 07-04-2011 10:10 AM |