Skip to content
Browse files
publication_list: Highlight paper titles.
  • Loading branch information
xuhdev committed Feb 28, 2017
1 parent d5697de commit 802714bf4e5ee50186714ba1c8c2ccd6e43d02fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
@@ -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
@@ -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 import Style as UnsrtStyle
from 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):
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]
return title

class Plugin(RestExtension):
@@ -64,12 +85,12 @@ class PublicationList(Directive):

def run(self):

style = find_plugin('', 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(['BASE_URL'] + detail_page_dir if detail_page_dir else None)

parser = Parser()
@@ -101,6 +122,7 @@ def run(self):
cur_year = entry.fields['year']
html += '<h3>{}</h3>\n<ul>'.format(cur_year)

entry.label = label # Pass label to the style.
pub_html = list(style.format_entries((entry,)))[0].text.render_as('html')
if highlight_authors: # highlight one of several authors (usually oneself)
for highlight_author in highlight_authors:

0 comments on commit 802714b

Please sign in to comment.