Skip to content

Instantly share code, notes, and snippets.

@inukshuk
Created November 20, 2011 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inukshuk/1380295 to your computer and use it in GitHub Desktop.
Save inukshuk/1380295 to your computer and use it in GitHub Desktop.
Pandoc CSL Tests for citeproc-js
require 'bibtex'
require 'citeproc/js'
repo = 'https://raw.github.com/citation-style-language/styles/master/'
data = BibTeX.open('http://johnmacfarlane.net/pandoc/csltest/biblio.bib')
# styles to test
styles = %w{ aaa apa ama }
styles.each do |style|
puts style
# create processor
p = CiteProc::Processor.new :style => "#{repo}#{style}.csl"
# register input data
data.to_citeproc.each { |d| p << d }
# generate citations
puts p.append(:id => 'item1').inspect
puts p.append(:id => 'item2', :locator => 'p. 30').inspect
puts p.append(:id => 'item3', :locator => 'p. 30', :suffix => 'and nowhere else').inspect
# generate bibliography
puts p.bibliography.join
puts
end
aaa
[[0, "(Doe 2005)"]]
[[0, "(Doe 2005)"], [1, "(Doe 2006:p. 30)"]]
[[0, "(Doe 2005)"], [1, "(Doe 2006:p. 30)"], [2, "(Doe and Roe 2007:p. 30 and nowhere else)"]]
<div class="csl-bib-body">
<div class="csl-entry">
<div class="csl-block">Doe, John</div>
<div class="csl-left-margin"> 2005</div><div class="csl-right-inline">First Book. Cambridge: Cambridge University Press.</div>
</div>
<div class="csl-entry">
<div class="csl-left-margin"> 2006</div><div class="csl-right-inline">Article. Journal of Generic Studies.</div>
</div>
<div class="csl-entry">
<div class="csl-block">Doe, John, and Jenny Roe</div>
<div class="csl-left-margin"> 2007</div><div class="csl-right-inline">Why Water Is Wet. <i>In</i> Third Book. Sam Smith, ed. Oxford: Oxford University Press.</div>
</div>
</div>
apa
[[0, "(Doe, 2005)"]]
[[0, "(Doe, 2005)"], [1, "(Doe, 2006, p. p. 30)"]]
[[0, "(Doe, 2005)"], [1, "(Doe, 2006, p. p. 30)"], [2, "(Doe &#38; Roe, 2007, p. p. 30 and nowhere else)"]]
<div class="csl-bib-body">
<div class="csl-entry">Doe, J. (2005). <i>First Book</i>. Cambridge: Cambridge University Press.</div>
<div class="csl-entry">Doe, J. (2006). Article. <i>Journal of Generic Studies</i>.</div>
<div class="csl-entry">Doe, J., &#38; Roe, J. (2007). Why Water Is Wet. In S. Smith (Ed.), <i>Third Book</i>. Oxford: Oxford University Press.</div>
</div>
ama
[[0, "<sup>1</sup>"]]
[[1, "<sup>2(pp. 30)</sup>"]]
[[2, "<sup>3(pp. 30) and nowhere else</sup>"]]
<div class="csl-bib-body">
<div class="csl-entry">1. Doe J. <i>First Book</i>. Cambridge: Cambridge University Press; 2005.</div>
<div class="csl-entry">2. Doe J. Article. <i>Journal of Generic Studies</i>. 2006;6:33-34.</div>
<div class="csl-entry">3. Doe J, Roe J. Why Water Is Wet. In: Smith S, ed. <i>Third Book</i>. Oxford: Oxford University Press; 2007.</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment