I'm using Django and am storing bibtex in my model and want to be able to pass my view the reference in the form of a formatted HTML string made to look like the Harvard reference style.
Using the method described in Pybtex does not recogonize bibtex entry it is possible for me to convert a bibtex string into a pybtex BibliographyData object. I believe it should be possible to get from this to an HTML format based on the docs https://pythonhosted.org/pybtex/api/formatting.html but I just don't seem to be able to get it working.
Pybtex seems to be set up to be used from the command line rather than python, and there are very few examples of it being used on the internet. Has anyone done anything like this? Perhaps it would be easier to pass the bibtex to my template and use a javascript library like https://github.com/pcooksey/bibtex-js to try and get an approximation of the Harvard style?
To do that I adapted some code from here. I am not sure what is the name of this particular formatting style, but most probably you can change/edit it. This is how it looks:
This generates the following HTML formatted reference:
I've notice the command line
pybtex-format
tool produces a fair output for HTML:So I went to the source code at
pybtex/database/format/__main__.py
and found an incredibly simple solution that worked like a charm for me:Here are my input and output files: