View Single Post
Old 02-01-2015, 09:12 AM   #1
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
S/R Function Title-Case

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
Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	276
Size:	90.1 KB
ID:	134397  

Last edited by phossler; 02-01-2015 at 09:17 AM.
phossler is offline   Reply With Quote