mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
...
This commit is contained in:
parent
2dc704a18c
commit
8831eb5443
@ -132,18 +132,18 @@ The functions available are:
|
||||
* ``subitems(val, start_index, end_index)`` -- This function is used to break apart lists of tag-like hierarchical items such as genres. It interprets the value as a comma-separated list of tag-like items, where each item is a period-separated list. Returns a new list made by first finding all the period-separated tag-like items, then for each such item extracting the start_index`th to the `end_index`th components, then combining the results back together. The first component in a period-separated list has an index of zero. If an index is negative, then it counts from the end of the list. As a special case, an end_index of zero is assumed to be the length of the list. Examples::
|
||||
|
||||
Assuming a #genre column containing "A.B.C":
|
||||
{#genre:subitems(0,1)} returns A
|
||||
{#genre:subitems(0,2)} returns A.B
|
||||
{#genre:subitems(1,0)} returns B.C
|
||||
{#genre:subitems(0,1)} returns "A"
|
||||
{#genre:subitems(0,2)} returns "A.B"
|
||||
{#genre:subitems(1,0)} returns "B.C"
|
||||
Assuming a #genre column containing "A.B.C, D.E":
|
||||
{#genre:subitems(0,1)} returns A, D
|
||||
{#genre:subitems(0,2)} returns A.B, D.E
|
||||
{#genre:subitems(0,1)} returns "A, D"
|
||||
{#genre:subitems(0,2)} returns "A.B, D.E"
|
||||
|
||||
* ``sublist(val, start_index, end_index, separator)`` -- interpret the value as a list of items separated by `separator`, returning a new list made from the `start_index`th to the `end_index`th item. The first item is number zero. If an index is negative, then it counts from the end of the list. As a special case, an end_index of zero is assumed to be the length of the list. Examples assuming that the tags column (which is comma-separated) contains "A, B ,C"::
|
||||
|
||||
{tags:sublist(0,1,\,)} returns A
|
||||
{tags:sublist(-1,0,\,)} returns C
|
||||
{tags:sublist(0,-1,\,)} returns A, B
|
||||
{tags:sublist(0,1,\,)} returns "A"
|
||||
{tags:sublist(-1,0,\,)} returns "C"
|
||||
{tags:sublist(0,-1,\,)} returns "A, B"
|
||||
|
||||
* ``test(text if not empty, text if empty)`` -- return `text if not empty` if the field is not empty, otherwise return `text if empty`.
|
||||
|
||||
|
@ -432,10 +432,11 @@ class BuiltinSublist(BuiltinFormatterFunction):
|
||||
'The first item is number zero. If an index is negative, then it '
|
||||
'counts from the end of the list. As a special case, an end_index '
|
||||
'of zero is assumed to be the length of the list. Examples using '
|
||||
'basic template mode and assuming a #genre value if A.B.C: '
|
||||
'{#genre:sublist(-1,0,.)} returns C<br/>'
|
||||
'{#genre:sublist(0,1,.)} returns A<br/>'
|
||||
'{#genre:sublist(0,-1,.)} returns A.B')
|
||||
'basic template mode and assuming that the tags column (which is '
|
||||
'comma-separated) contains "A, B, C": '
|
||||
'{tags:sublist(0,1,\,)} returns "A". '
|
||||
'{tags:sublist(-1,0,\,)} returns "C". '
|
||||
'{tags:sublist(0,-1,\,)} returns "A, B".')
|
||||
|
||||
def evaluate(self, formatter, kwargs, mi, locals, val, start_index, end_index, sep):
|
||||
if not val:
|
||||
@ -465,10 +466,10 @@ class BuiltinSubitems(BuiltinFormatterFunction):
|
||||
'then it counts from the end of the list. As a special case, an '
|
||||
'end_index of zero is assumed to be the length of the list. '
|
||||
'Example using basic template mode and assuming a #genre value of '
|
||||
'"A.B.C": {#genre:subitems(0,1)} returns A. {#genre:subitems(0,2)} '
|
||||
'returns A.B. {#genre:subitems(1,0)} returns B.C. Assuming a #genre '
|
||||
'value of "A.B.C, D.E.F", {#genre:subitems(0,1)} returns A, D. '
|
||||
'{#genre:subitems(0,2)} returns A.B, D.E')
|
||||
'"A.B.C": {#genre:subitems(0,1)} returns "A". {#genre:subitems(0,2)} '
|
||||
'returns "A.B". {#genre:subitems(1,0)} returns "B.C". Assuming a #genre '
|
||||
'value of "A.B.C, D.E.F", {#genre:subitems(0,1)} returns "A, D". '
|
||||
'{#genre:subitems(0,2)} returns "A.B, D.E"')
|
||||
|
||||
def evaluate(self, formatter, kwargs, mi, locals, val, start_index, end_index):
|
||||
if not val:
|
||||
|
Loading…
x
Reference in New Issue
Block a user