bib2html.py: Add isbn and note fields
[shutils.git] / bib2html.py
index 3ad3a93ee061d6f44088be9ac134b7f308ce9d43..5db0d075d32d4ba6b75cbe1ddc7ba66a51cc822c 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 """Creates a webpage with all entries of a .bib file"""
 
-__version__ = "1.0"
+__version__ = "1.1"
 
 __author__ = "Stefan Huber"
 __email__ = "shuber@sthu.org"
@@ -31,11 +31,13 @@ __license__ = "MIT"
 # OTHER DEALINGS IN THE SOFTWARE.
 
 
-import os, sys, getopt
+import os, sys, getopt, re
 
 
 def format_latex(text):
-    return text.replace('{', '').replace('}', '').replace('\\', '')
+    # Get rid of matching dollar signs
+    text = re.sub(r'\$([^\$]*)\$', r'\1', text)
+    return text.replace('\mathcal', '').replace('{', '').replace('}', '').replace('\\', '')
 
 def format_field_span(type, value):
     return "<span class=bibentry_" + type + ">" + format_latex(value) + "</span>"
@@ -63,8 +65,9 @@ def format_details_article(entry):
             format_field(entry, 'number', pre='(', post=')'))
     line.append(format_field(entry, 'month', post=' ') + \
             format_field(entry, 'year'))
-    line = filter(lambda l: l != "", line)
+    line.append(format_field(entry, 'note'))
 
+    line = filter(lambda l: l != "", line)
     return [where, ", ".join(line)]
 
 def format_details_inproceedings(entry):
@@ -75,6 +78,9 @@ def format_details_inproceedings(entry):
     line.append(format_field(entry, 'address'))
     line.append(format_field(entry, 'month', post=' ') + \
             format_field(entry, 'year'))
+    line.append(format_field(entry, 'isbn', pre='ISBN '))
+    line.append(format_field(entry, 'note'))
+
     line = filter(lambda l: l != "", line)
     return [where, ", ".join(line)]
 
@@ -83,6 +89,8 @@ def format_details_thesis(entry):
     line.append(format_field(entry, 'school'))
     line.append(format_field(entry, 'month', post=' ') + \
             format_field(entry, 'year'))
+    line.append(format_field(entry, 'note'))
+
     line = filter(lambda l: l != "", line)
     return [", ".join(line)]
 
@@ -92,6 +100,8 @@ def format_details_book(entry):
     line.append(format_field(entry, 'isbn', pre='ISBN '))
     line.append(format_field(entry, 'month', post=' ') + \
             format_field(entry, 'year'))
+    line.append(format_field(entry, 'note'))
+
     line = filter(lambda l: l != "", line)
     return [", ".join(line)]
 
@@ -134,11 +144,16 @@ def entryDateSortKey(p):
             'apr' : '04', 'may' : '05', 'jun' : '06', \
             'jul' : '07', 'aug' : '08', 'sep' : '09', \
             'oct' : '10', 'nov' : '11', 'dec' : '12'}
+
+    if not 'month' in e.fields:
+        return e.fields['year']
+
     month = e.fields['month'].lower()[0:3]
     if month in month2num:
         month = month2num[month]
     else:
         month = ""
+
     return e.fields['year'] + "-" + month