diff --git a/v7/publication_list/README.md b/v7/publication_list/README.md index ab1af5c2..f4101efa 100644 --- a/v7/publication_list/README.md +++ b/v7/publication_list/README.md @@ -27,10 +27,6 @@ The `publication-list` directive accepts multiple options. owner of the website. This can be a list of names separated by “;” if there are several optional names. -* `:style:` indicates the style of the bibliography. All available styles are - provided by [Pybtex][]. You can see the [list of styles][] in the Pybtex - repository. The default style is `unsrt`. - In the BibTeX file entries, the following fields have special meanings. * `abstract` is the abstract of the paper. If it is present, the abstract will diff --git a/v7/publication_list/publication_list.py b/v7/publication_list/publication_list.py index 7de77871..7aa33d08 100644 --- a/v7/publication_list/publication_list.py +++ b/v7/publication_list/publication_list.py @@ -34,7 +34,28 @@ from pybtex.database import BibliographyData, Entry from pybtex.database.input.bibtex import Parser from pybtex.markup import LaTeXParser -from pybtex.plugin import find_plugin +from pybtex.style.formatting.unsrt import Style as UnsrtStyle +from pybtex.style.template import href, tag + + +class Style(UnsrtStyle): + """The style for publication listing. It hyperlinks the title to the detail page if user sets it. + """ + + def __init__(self, detail_page_url): + super().__init__() + self.detail_page_url = detail_page_url + + def format_title(self, e, which_field, as_sentence=True): + "Override the UnsrtStyle format_title(), so we have the title hyperlinked." + + title = tag('strong')[super().format_title(e, which_field, as_sentence)] + + if self.detail_page_url: + url = '/'.join((self.detail_page_url, e.label + '.html')) + return href[url, title] + else: + return title class Plugin(RestExtension): @@ -64,12 +85,12 @@ class PublicationList(Directive): def run(self): - style = find_plugin('pybtex.style.formatting', self.options.get('style', 'unsrt'))() bibtex_dir = self.options.get('bibtex_dir', 'bibtex') detail_page_dir = self.options.get('detail_page_dir', 'papers') highlight_authors = self.options.get('highlight_author', None) if highlight_authors: highlight_authors = highlight_authors.split(';') + style = Style(self.site.config['BASE_URL'] + detail_page_dir if detail_page_dir else None) self.state.document.settings.record_dependencies.add(self.arguments[0]) parser = Parser() @@ -101,6 +122,7 @@ def run(self): cur_year = entry.fields['year'] html += '

{}

\n