![]() |
#1 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 Last edited by phossler; 02-01-2015 at 09:17 AM. |
![]() |
![]() |
![]() |
#2 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Works fine for me.
![]() |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
thanks for checking, but the first of the 4 <h1> still ends up like
<h1> Chapter 1 AAAAAAAAAAAAAAA BBBBBBBBBBBB CCCCCCCCCCCCCC</h1> If you could verify my Saved Search in the screen shot is the same as yours please? |
![]() |
![]() |
![]() |
#4 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Now I see the problem.
Titlecasing ignores words that have capitals in the middle of the word (unless the whole thing is uppercased). Try titlecasing "ChaPter". See: src/calibre/utils/titlecase.py line 71 Code:
if INLINE_PERIOD.search(word) or UC_ELSEWHERE.match(word): line.append(word) continue ![]() Last edited by eschwartz; 02-01-2015 at 02:26 PM. |
![]() |
![]() |
![]() |
#5 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,047
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
I always Lowered, then set the desired case |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
The workaround that I came up with is the UPPERCASE first and then TitleCase
That's why I was wondering about modifying the title case RegExFunction and just doing a upper case first; do it in one step |
![]() |
![]() |
![]() |
#7 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Try:
Func: "Upper-case text then Title-case it" Code:
from calibre.utils.icu import upper from calibre.utils.titlecase import titlecase from calibre.ebooks.oeb.polish.utils import apply_func_to_match_groups def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): '''Title-case matched text. If the regular expression contains groups, only the text in the groups will be changed, otherwise the entire text is changed.''' text = apply_func_to_match_groups(match, upper) '''Now return it titlecased.''' return titlecase(text) |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
RegEx Function: Title Case | phossler | Editor | 29 | 07-04-2020 10:52 AM |
having metadata.opf, cover.jpg + title.[pdf|epub|..] what's the best function to use? | kabirmaar | Development | 2 | 06-21-2017 03:33 PM |
Regex for Title Case or Sentence case? | Turtle91 | Sigil | 3 | 01-19-2013 01:36 PM |
Dutch title case function | fvdham | Library Management | 8 | 10-11-2012 10:09 PM |
Title Case | Dopedangel | Calibre | 6 | 10-16-2009 08:01 AM |