Skip to content

Commit

Permalink
publication_list: Highlight paper titles.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhdev committed Feb 28, 2017
1 parent d5697de commit 802714b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 0 additions & 4 deletions v7/publication_list/README.md
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions v7/publication_list/publication_list.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 802714b

Please sign in to comment.