I had some 'unexpected' results trying to re-format a lot of Hx titles into TitleCase.
Ending up making just a small test doc to investigate further
It seems as if the TitleCase function stops if the first word is already in mixed case so the first H1 is found but not replaced. The rest are fine
Code:
<body>
<h1> Chapter 1 AAAAAAAAAAAAAAA BBBBBBBBBBBB CCCCCCCCCCCCCC</h1>
<h1>CHAPTER 1 AAAAAAAAAAAAAAA BBBBBBBBBBBB CCCCCCCCCCCCCC</h1>
<h1>chapter 1 aaaaaaaaaaaaa bbbbbbbbbbbbbb cccccccccccccccc</h1>
<h1>AAAAAAAAAAAAAAA BBBBBBBBBBBB CCCCCCCCCCCCCCCCCCCCCC</h1>
</body>
The workaround I've found it to do the S/R with the built-in UPPERCASE function first, and then the TitleCase
Is there a way to 'include the call' to the UPPECASE function as part of the TitleCase function?
I got far enough to see the function (or at least I think it was) but couldn't figure out to to do it myself
Code:
from calibre.utils.titlecase import titlecase
from calibre.ebooks.oeb.polish.utils import apply_func_to_html_text
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
'''Title-case matched text, ignoring the text inside tag definitions.'''
return apply_func_to_html_text(match, titlecase)
Thanks