View Single Post
Old 02-08-2021, 09:42 AM   #9
413Michele
Enthusiast
413Michele began at the beginning.
 
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>
And here's the string to replace with:
Code:
<h2 class="hidden">\1 \2</h2><h2 class="ChapterTitle">\1</h2><h3 class="ChapterSubtitle">\2</h3>
After this I used the ToC generation tool for multilevel elements with XPath:
  • h1 for the first level
  • h2 with class=hidden for the second level
and it worked like a charm!
413Michele is offline   Reply With Quote