Skip to content

Instantly share code, notes, and snippets.

@inukshuk inukshuk/style-gen.rb
Last active Sep 21, 2018

What would you like to do?
require 'anystyle'
require 'citeproc/ruby'
require 'csl/styles'
# Load all dependent CSL styles and create a Renderer
# Those should be cached!
styles = { |id| CSL::Style.load id }.reject { |s| s.bibliography.nil? }
cp =
# Parse a reference to CSL/JSON
input = 'Knuth, Donald. (1968). The art of computer programming (Vol. 1). Boston: Addison-Wesley.'
items = AnyStyle.parse(input, format: 'csl')
# Generate a output hash for every style
refs = Hash[ { |s|
# Convert the item for use with CiteProc
item = { |c| =[0]) }
# Render the item
ref = cp.render item, s.bibliography
# TODO compute Levenshtein distance to input (or similar)
score = 0
# Return style id and reference string and score
[, ref, score]

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.