How to use parts of Zotero code just for citations and bibliographies?

75 views
Skip to first unread message

Ariel Balter

unread,
Aug 6, 2024, 12:54:47 AM8/6/24
to zotero-dev
I would like to use just enough of Zotero code to do the following given a biblatex or csl-json library:

1. Generate in-text citations formatted for html using a specific CSL template
2. Generate bibliographies formatted for html using a specific CSL template

How hard would this be?

I've tried using citation-js and citeproc-js and can't figure out how to get the citations in a format based on CSL.

Emiliano Heyns

unread,
Aug 6, 2024, 11:51:00 AM8/6/24
to zotero-dev
It's not easier than using citeproc-js. Maybe pandoc can do what you need?

Ariel Balter

unread,
Aug 6, 2024, 5:54:53 PM8/6/24
to zotero-dev
I want to do it in javascript. Basically I want to write a javascript library that will turn `<cite>citation_id_1, citation_id_2</cite` into a properly formatted citation with hover preview like I get in quarto.

Here is a proof of principal: https://replit.com/@abalter/citation-tooltips

But I can't figure out how to engage the machinery in citation.js to properly engage the template: https://stackoverflow.com/questions/78836802/citation-js-not-using-the-specified-csl-template

Emiliano Heyns

unread,
Aug 7, 2024, 1:59:46 AM8/7/24
to zotero-dev
This seems easy to use: https://citation.js.org/

straight citeproc-js:

const CSL = require('citeproc')
const fs = require('fs')

const style = fs.readFileSync('apa.csl', 'utf-8')

// your list of references in CSL-JSON
const references = {
  item1: {
    id: 'item1',
    type: 'book',
    title: 'Stuff',
  },
}

// Create a CSL engine
const sys = {
  retrieveLocale: function (lang) {
    const locale = fs.readFileSync('locales-en-US.xml', 'utf-8')
    return locale
  },
  retrieveItem: function (id) {
      return references[id]
  }
}
const citeproc = new CSL.Engine(sys, style)

// Specify the references to cite
citeproc.updateItems(Object.keys(references))

// Generate the bibliography
var bib = citeproc.makeBibliography()
console.log(bib[1].join('\n'))
Reply all
Reply to author
Forward
0 new messages