Skip to content

Commit

Permalink
Initial Commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
pablooliveira committed Dec 23, 2010
0 parents commit 0434a3b
Show file tree
Hide file tree
Showing 4 changed files with 1,242 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(The MIT License)

Copyright (c) 2010 Pablo de Oliveira Castro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
This plugin interfaces [bibtex2html](http://www.lri.fr/~filliatr/bibtex2html/) with Jekyll
to generate an html bibliography list from bibtex entries.
For this to work, the bibtex entries must be enclosed in a special liquid block:
{% bibtex %}
....
{% endbibtex %}

Setup
-----

* Install [bibtex2html](http://www.lri.fr/~filliatr/bibtex2html/).
* Copy bibtex.rb and style.bst on your _plugins directory.
* Edit bibtex.rb to tweak the options that are passed to bibtex2html.

Limitations
-----------

When the option -nobibsource is NOT USED,
bibtex2html generates two html files: the first (source.html) contains
an html bibliography list and the second (source_bib.html) contains the
original bib entries. It also links the bibliography entries with the
bib excerpts.

If you need this feature and decide to NOT USE -nobibsource, then you can
only put one {% bibtex %} block per file. This may change in the future.

License
-------

This plugin is realeased under the MIT License.

Contact
-------

You can reach me at Pablo de Oliveira <[email protected]>.
82 changes: 82 additions & 0 deletions bibtex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# This plugin interfaces bibtex2html (http://www.lri.fr/~filliatr/bibtex2html/) with Jekyll
# to generate an html bibliography list from bibtex entries.
# For this to work, the bibtex entries must be enclosed in a special liquid block:
# {% bibtex %}
# ....
# {% endbibtex %}

module Jekyll
class BibtexBlock < Liquid::Block

# The options that are passed to bibtex2html
# BEWARE :
# * if the option -nobibsource is USED, you can put as MANY {% bibtex %}
# blocks as you like in the same source file.
# * if the option -nobibsource is NOT USED, you can only put a SINGLE
# {% bibtex %} block per source file.
Options = "-nofooter -noheader -use-table -nokeywords -nokeys -nodoc"

# The Bibtex style
Style = "_plugins/style.bst"

# Bibtex code may use {{ }} markups which interfere with liquid.
# Therefore, we override parse to completely ignore the content
# of the {% bibtex %} blocks.
def parse(tokens)
@nodelist ||= []
@nodelist.clear
while token = tokens.shift
if token =~ IsTag and token =~ FullToken
# if we found the proper block delimitor just end parsing here and let the outer block
# proceed
if block_delimiter == $1
end_tag
return
end
else
@nodelist << token
end
end
assert_missing_delimitation!
end

def render(context)
# get the content of the {% bibtex %} block
content = super.join

# get the complete paths for the style file and the source file
stylepath = File.join(context['site']['source'], Style)
file = File.join(context['site']['destination'],context['page']['url'])
dirname = File.dirname(file)

# ensure that the destination directory exists
FileUtils.mkdir_p(dirname)

# enter the destination directory
Dir.chdir(dirname) do
basename = File.basename(file).split('.')[-2]
outname = basename + ".html"

# write the content of the {% bibtex %} block to temp
temp = basename + ".bib"
File.open(temp, 'w') {|f| f.write(content)}

# call bibtex2html
system("bibtex2html #{Options} -s #{stylepath} -o #{basename} #{temp}")
# XXX
# If the option -nobibsource is NOT USED, bibtex2html will create an
# additional file called {basename + "_bib.html"} containing the bib
# source. When multiple {% bibtex %} blocks are used in the same source,
# these additional files are overwritten ...

File.delete(temp)

# return the produced output
IO.read(outname)
end
end
end
end


Liquid::Template.register_tag('bibtex', Jekyll::BibtexBlock)
Loading

0 comments on commit 0434a3b

Please sign in to comment.