Quote:
Originally Posted by Buckskin
If I was using C or other programming language I would just split the author field into words and iterate through each entry. In Calibres template languages I don't know how to do this.
|
You can write a
User-defined template function in python to do things like this.
Look at calibre's source code "calibre.db.cache" see what is in the mi structure.
The built-in template function 'author_sorts' gets close to what you want and probably can be used as a starting point.
Code:
def evaluate(self, formatter, kwargs, mi, locals, val_sep):
sort_data = mi.author_sort_map
if not sort_data:
return ''
names = [sort_data.get(n) for n in mi.authors if n.strip()]
return val_sep.join(n for n in names)
Instead of using a comprehension, iterate through the authors building the sort string from the author_sort_map and adding on the stuff in parenthesis.