diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index 7485effab9..b95775aa99 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -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`. diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index e9ff39d3bf..015a639af1 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -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
' - '{#genre:sublist(0,1,.)} returns A
' - '{#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: