Skip to content

Commit

Permalink
Added python file to generate js bibliography variable. Updated READM…
Browse files Browse the repository at this point in the history
…E. Some formatting changes
  • Loading branch information
michaelplews committed Sep 12, 2016
1 parent eba1fcd commit 7660ba1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,32 @@ This exact reference used in custom_bibliography.js can be found [here](./exampl

This requires the [bibtex-parser](https://github.com/mikolalysenko/bibtex-parser) package also.

First, download the dependencies and package to the ~/.jupyter/custom location
```bash
mkdir ~/.jupyter/custom
cd ~/.jupyter/custom
git clone [email protected]:mikolalysenko/bibtex-parser.git
git clone [email protected]:michaelplews/jupyter-markdown-citations.git
touch ./jupyter-markdown-citations/custom_bibliography.js
echo 'var bibliography = ""' >> ./jupyter-markdown-citations/custom_bibliography.js
git clone [email protected]:michaelplews/jupyter_markdown_citations.git
cd jupyter_markdown_citations
```

- Creates the custom jupyter installs directory
- Installs dependencies
- Installs this package
- Creates the custom_bibliography.js file
- Adds the bibliography variable to the file
Next, symlink (or copy) your .bib file (mine is exported from [Mendeley](https://www.mendeley.com)) to the same folder:
```bash
ln -s /directory/to/bib_file.bib #for symlinking
cp /directory/to/bib_file.bib . #for copying
#only use one of the above options
```

Generate the custom_bibliography.js file with the make_bib_js.py file:
```bash
python make_bib_js.py bib_file.bib
```
Lastly, add this app to your custom.js file:
```bash
cd ~/.jupyter/custom
echo "require(['custom/jupyter_markdown_citations/citations']);" >> custom.js
```

Reloading your .iPyNb page in the browser should now load this package.

This repo is currently under development
Enjoy!
28 changes: 14 additions & 14 deletions citations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ function searchCite(){
json = doParse(bibliography)
var citations = document.getElementsByTagName("cite")
for(var i = 0; i < citations.length; i++){
citRef = citations[i].innerHTML.toUpperCase();
citation=citations[i];
a=document.createElement('a');
citation.parentNode.replaceChild(a, citation);
a.innerHTML = json[citRef].AUTHOR.split(',')[0] + " et. al., " + json[citRef].YEAR;
a.setAttribute('href', "http://dx.doi.org/" + json[citRef].DOI);
a.setAttribute('title',
json[citRef].TITLE.replace('{','"').replace('}','"') + ', '
+ json[citRef].JOURNAL + ', vol. '
+ json[citRef].VOLUME + ', pg. '
+ json[citRef].PAGES + ', '
+ json[citRef].MONTH.charAt(0).toUpperCase() //Capitalize first letter
+ json[citRef].MONTH.slice(1) + '. ' //Add remainder of string
+ json[citRef].YEAR);
citRef = citations[i].innerHTML.toUpperCase();
citation=citations[i];
a=document.createElement('a');
citation.parentNode.replaceChild(a, citation);
a.innerHTML = json[citRef].AUTHOR.replace('{','').replace('}','').split(',')[0] + " et. al., " + json[citRef].YEAR;
a.setAttribute('href', "http://dx.doi.org/" + json[citRef].DOI);
a.setAttribute('title',
json[citRef].TITLE.replace('{','"').replace('}','"') + ', '
+ json[citRef].JOURNAL + ', vol. '
+ json[citRef].VOLUME + ', pg. '
+ json[citRef].PAGES + ', '
+ json[citRef].MONTH.charAt(0).toUpperCase() //Capitalize first letter
+ json[citRef].MONTH.slice(1) + '. ' //Add remainder of string
+ json[citRef].YEAR);
};
}

Expand Down
17 changes: 17 additions & 0 deletions make_bib_js.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Generates the custom_bibliography.js file from a .bib file supplied as an argument
import sys

def generate_bib_js(bib_file):
file_bib = open(bib_file, 'r')
file_js = open("custom_bibliography.js", "w")
file_js.write("var bibliography = `")
for line in file_bib:
file_js.write(line.replace("`",""))
file_js.write("`")
file_js.close()

if __name__ == "__main__":
if len(sys.argv) == 2:
generate_bib_js(sys.argv[1])
else:
raise ValueError('Only one argument is allowed.')

0 comments on commit 7660ba1

Please sign in to comment.