-
Notifications
You must be signed in to change notification settings - Fork 2
/
bib2md.py
executable file
·36 lines (29 loc) · 1.05 KB
/
bib2md.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/python
# bib2md converts a BibTeX file to a github style Markdown file
# Authors: Leif Dreizler and Phill Conrad, UCSB
import re
fileToRead = 'paper.bib'
fileToWrite = 'REFERENCES.md'
title = 'SBL_Paper\n=========\n\n'
header = 'start-of-references\n\n'
footer ='end-of-references\n'
delimiter = '---\n\n'
sentinels = ["author", "title", "booktitle", "url"]
def bibtoMD(read, write):
with open(read,'r') as infile:
with open(write,'w') as outfile:
outfile.write(title+header)
for line in infile:
split = line.split('=',1)
key = split[0].strip()
if key in sentinels:
outfile.write(key.title() + ": ")
elif line[0] =='}':
outfile.write(delimiter)
continue
else:
continue
value = split[1]
outfile.write(re.sub('.*?{|}.*','',value) +'\n')
outfile.write(footer)
bibtoMD(fileToRead, fileToWrite)