View Single Post
Old 10-30-2023, 10:06 AM   #9
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
One can do what I think the OP wants, all words capitalized, using template mode in search & replace. (Personally I think capitalizing every word is wrong, but the OP is in charge of the OP's library.)

If the titles don't contain non-alphabetic characters other than space then this GPM template does the job.
Code:
program:
	new_title = list_re_group($title, ' ', '.', '(.*)', 'program: capitalize($)')
With this template, "a witch in the time of the lords" becomes "A Witch In The Time Of The Lords".

If the titles do contain non-alphabetic characters such as colons and you want strings like foo:bar to become Foo:Bar then this python template gets close.
Code:
python:
def evaluate(book, context):
	import re
	nt = []
	for w in re.split(r'([() :-]+)', book.get('title')):
		nt.append(w.capitalize())
	return ''.join(nt)
You must list the characters on line 5 that can precede words to be capitalized. This example uses r'([() :-]+)', parens, space, colon, dash. The problem children are quotes. Sometimes one wants the capitalization after the quote (quoted words in titles, as in "What Does "Foobar" Mean") and sometimes not (possessives, as in "John's Great Escape").

The first template probably gets most of the way there. I wouldn't try to get too fancy, instead correcting any "mistakes" by hand.

The search/replace looks like this, with the desired template in the template box.
Attached Thumbnails
Click image for larger version

Name:	Clipboard01.jpg
Views:	90
Size:	124.2 KB
ID:	204481  
chaley is offline   Reply With Quote