View Single Post
Old 01-30-2023, 09:00 AM   #5
enuddleyarbl
Guru
enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.
 
enuddleyarbl's Avatar
 
Posts: 777
Karma: 1538394
Join Date: Sep 2013
Device: Kobo Forma
Quote:
Originally Posted by Turtle91 View Post
Yeah, that’s ugly. The spans are a cludge to make something ‘appear’ to have small-caps for those older/deficient devices that don’t support the css.

It may be easier/faster to just manually type the headers yourself - assuming there are a reasonable number of chapters.

If not, I would simply use a few regex passes. Exactly HOW you do that is up to you - there are multiple techniques. I would just use incremental steps to do the job. Some regex geniuses could probably do it in 3 passes...

Code:
Pass 1: 
Find: <p class="calibre7"><br class="calibre1" id="filepos.*?"/>\s*</p>\s*<p class="whitespace"></p>
Replace: leave blank

Pass 2: 
Find: <p class="calibre7"><span class="calibre(24|19)">(.*?)</span></p>
Replace: <h4>\L\2\E</h4>

Pass 3: 
Find: <p class="calibre7"><span class="calibre18">(.*?)</span></p>
Replace: <h3>\1</h3>

Pass 4: 
Find: </h3>\s*<h4>(.*?)</h4>
Replace: \1</h3>

Pass 5: 
Find: </h3>\s*<h3>
Replace: single space

Pass 6:
Find: </h3>\s*<p class="whitespace"></p>\s*<h3>(.*?)</h3>
Replace: single space<span>\1</span></h3>

Pass 7: 
Find: <p class="calibre7"><br class="calibre1"/>\s*</p>
Replace: leave blank
Of course, standard regex safety protocols should be engaged - save your work first, and test the regex a couple of times BEFORE hitting the replace-all button. You also may need to hit the replace-all button a few times for each pass (until it can’t find anymore matches). Sigil just implemented the feature of being able to see what changes are being made, and allow you to edit which ones you want, before accepting the changes. I’m not sure if Calibre Editor has that feature??

That should leave you with:
Code:
 
<h3>One: The Years 583-590 afe <span>He Is Entered in the Lists of the World</span></h3>
Then you can style it however you wish. I like using the actual small-caps style as most modern devices respect it; IIRC kobo does. My CSS would look like this:
Code:
h3 {
margin:0; 
font-weight:bold; 
font-family:serif; 
font-size:1.2em; 
font-variant:small-caps;
text-align:center
}

h3 span {
display:block; 
margin-top:1em; 
font-size:1em
}
I wrote this on my phone. As soon as it’s safe for me to turn on the computer (ie I won’t wake up my wife ) I’ll double-check the regex. I think I got it right, but I’ll edit it if I missed something.

Cheers!


EDIT: Regex Confirmed - with only a small edit on pass 2. I've also attached a screenshot of how it would look.
Wow! Thanks. I'll work through that and see how it goes. I can't believe you typed all that on a phone. Thanks, again.
enuddleyarbl is offline   Reply With Quote