From 30117934eddd457d8abef2cb0ed11c48e2de71d9 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Thu, 7 Aug 2014 10:19:35 +0200 Subject: [PATCH] bib2html: adding DOI, pimping formatting --- bib2html.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bib2html.py b/bib2html.py index 28abd58..111d108 100755 --- a/bib2html.py +++ b/bib2html.py @@ -42,7 +42,8 @@ def format_field_span(type, value): def format_field(bibentry, field, pre='', post=''): if field in bibentry.fields: - return format_field_span(field, pre + bibentry.fields[field] + post) + if bibentry.fields[field] != "": + return format_field_span(field, pre + bibentry.fields[field] + post) return "" def format_author(a): @@ -95,12 +96,13 @@ def format_details_book(entry): return [", ".join(line)] def format_links(entry): + doi = format_field(entry, 'doi', pre='[DOI]') webpdf = format_field(entry, 'webpdf', pre='[PDF]') weblink = format_field(entry, 'weblink', pre='[link]') webslides = format_field(entry, 'webslides', pre='[slides]') weberrata = format_field(entry, 'weberrata', pre='[errata]') - return " ".join([webpdf, weblink, webslides, weberrata]) + return " ".join([doi, webpdf, weblink, webslides, weberrata]) def format_entry(entry): lines = [] @@ -131,11 +133,16 @@ def entryCompareDate(p1, p2): def toStr(e): - month = { 'jan' : '01', 'feb' : '02', 'mar' : '03', \ + month2num = { 'jan' : '01', 'feb' : '02', 'mar' : '03', \ 'apr' : '04', 'may' : '05', 'jun' : '06', \ 'jul' : '07', 'aug' : '08', 'sep' : '09', \ 'oct' : '10', 'nov' : '11', 'dec' : '12'} - return e.fields['year'] + "-" + month[e.fields['month'].lower()[0:3]] + month = e.fields['month'].lower()[0:3] + if month in month2num: + month = month2num[month] + else: + month = "" + return e.fields['year'] + "-" + month return cmp(toStr(e1), toStr(e2)) -- 2.39.5