View Single Post
Old 02-24-2024, 05:32 AM   #1
cheonsangel
Junior Member
cheonsangel began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Feb 2024
Device: none
How to Detect and Format "Side Story" with Calibre

Hello all!

I convert several txt files to epubs via Calibre, and several of these txt files have chapters that I would like to be detected as "Side Story 1" or "Side Story 2-3" etc. etc. I'm going crazy trying to find a way for Calibre's struction detection to detect and consistently format these headers the same as regular chapters.

Taking Calibre's default:
Code:
//*[((name()='h1' or name()='h2') and re:test(., 'chapter|book|section|part\s+', 'i')) or @class = 'chapter']
Changing it to any variation of following does not work as I'd hope:
Code:
//*[((name()='h1' or name()='h2') and re:test(., 'chapter|book|side\s+story|section|part\s+', 'i')) or @class = 'chapter']
Code:
//*[((name()='h1' or name()='h2') and re:test(., 'chapter|book|side\sstory|section|part\s+', 'i')) or @class = 'chapter']
What DOES work is if I change it to either:
Code:
//*[((name()='h1' or name()='h2') and re:test(., '\s*((chapter|book|section|part)\s+)|((prolog|prologue|epilogue)(\s+|$))', 'i')) or @class = 'chapter' or contains(., 'Side Story')]
Code:
//*[(re:test(., '\s*((chapter|book|section|part)\s+)|((prolog|prologue|epilogue)(\s+|$))', 'i')) or @class = 'chapter' or contains(., 'Side Story')]
That being said, while the conversion and detection works to split each Side Story into its own chapter in the TOC, it does not format consistently with the regular chapters.

For example, my regular chapters are auto-formatted to:
Code:
<h2 id="calibre_toc_2" class="calibre4">Chapter 2</h2>
But the Side Story chapters are auto-formatted to:
Code:
<p id="calibre_toc_21" class="calibre3">Side Story 3</p>
I tried Search and Replace to no avail, and don't want to have to change to Markdown for my txt files.

Is there any way to adjust settings so that I can consistently detect and format Side Story chapters to be the same as regularly detected chapters? Any help would be greatly appreciated!
cheonsangel is offline   Reply With Quote