diff --git a/manual/template_lang.rst b/manual/template_lang.rst index 207d366145..806cd2dcb1 100644 --- a/manual/template_lang.rst +++ b/manual/template_lang.rst @@ -242,7 +242,7 @@ The following functions are available in addition to those described in single-f * ``add(x, y)`` -- returns x + y. Throws an exception if either x or y are not numbers. * ``assign(id, val)`` -- assigns val to id, then returns val. id must be an identifier, not an expression * ``approximate_formats()`` -- return a comma-separated list of formats that at one point were associated with the book. There is no guarantee that the list is correct, although it probably is. This function can be called in template program mode using the template ``{:'approximate_formats()'}``. Note that format names are always uppercase, as in EPUB. - * ``author_links()`` -- returns a string containing a list of authors and that author's link values in the form ``author1:author1link & author2:author2link`` etc. An author is separated from its link value by a : character. ``author:linkvalue`` pairs are separated by " & " (space ampersand space) characters. An author is included even if the author link is empty. + * ``author_links(val_separator, pair_separator)`` -- returns a string containing a list of authors and that author's link values in the form ``author1 val_separator author1link pair_separator author2 val_separator author2link`` etc. An author is separated from its link value by the ``val_separator`` string with no added spaces. ``author:linkvalue`` pairs are separated by the ``pair_separator`` string argument with no added spaces. It is up to you to choose separator strings that do not occur in author names or links. An author is included even if the author link is empty. * ``booksize()`` -- returns the value of the |app| 'size' field. Returns '' if there are no formats. * ``cmp(x, y, lt, eq, gt)`` -- compares x and y after converting both to numbers. Returns ``lt`` if x < y. Returns ``eq`` if x == y. Otherwise returns ``gt``. * ``current_library_name() -- `` return the last name on the path to the current calibre library. This function can be called in template program mode using the template ``{:'current_library_name()'}``. diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index fd3884e910..924dd6ac3b 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -1400,23 +1400,27 @@ class BuiltinTransliterate(BuiltinFormatterFunction): class BuiltinAuthorLinks(BuiltinFormatterFunction): name = 'author_links' - arg_count = 0 + arg_count = 2 category = 'Get values from metadata' - __doc__ = doc = _('author_links() -- returns a string containing a list of ' - 'authors and that author\'s link values in the form ' - 'author1:author1link & author2:author2link etc. ' - 'An author is separated from its link value by a : character. ' - 'author:linkvalue pairs are separated by " & " (space ampersand ' - 'space) characters. An author is included even if the ' - 'author link is empty.') + __doc__ = doc = _('author_links(val_separator, pair_separator) -- returns ' + 'a string containing a list of authors and that author\'s ' + 'link values in the ' + 'form author1 val_separator author1link pair_separator ' + 'author2 val_separator author2link etc. An author is ' + 'separated from its link value by the val_separator string ' + 'with no added spaces. author:linkvalue pairs are separated ' + 'by the pair_separator string argument with no added spaces. ' + 'It is up to you to choose separator strings that do ' + 'not occur in author names or links. An author is ' + 'included even if the author link is empty.') - def evaluate(self, formatter, kwargs, mi, locals): + def evaluate(self, formatter, kwargs, mi, locals, val_sep, pair_sep): if hasattr(mi, '_proxy_metadata'): link_data = mi._proxy_metadata.author_link_map if not link_data: return '' names = sorted(link_data.keys(), key=sort_key) - return ' & '.join(n + ':' + link_data[n] for n in names) + return pair_sep.join(n + val_sep + link_data[n] for n in names) return _('This function can be used only in the GUI') _formatter_builtins = [