I worked on updates for Citation.js in the past few weeks, and I thought I'd go over them in this post.
Async
First of all, Citation.js now has support for asynchronous parsing, so it won't lag your app as much when it uses e.g. the Wikidata API. This is good, as synchronous requests are not only blocking your app, but also deprecated in most major browsers. This allows for more development on input formats where additional data needs to be fetched, like a DOI as input. I could have done this before, but this order made more sense to me. The API is simple:
// With callback Cite.async($INPUT, $OPTIONS, function (data) { data // instance of Cite // Further manipulations... console.log(data.get()) }) // Or with a promise, like this: Cite.async($INPUT, $OPTIONS).then(function (data) { data // instance of Cite // Further manipulations... console.log(data.get()) }) // Where $INPUT is input data and $OPTIONS is options // $OPTIONS is optional in both cases
The promise-returning part is good when using the async await syntax, i.e. var data = await Cite.async($INPUT, $OPTIONS)
.
Extensions
Unfortunately, no actual extensions to the Cite object. (However, extensions in input parsing is planned in v0.4
, and the API for output formatting is getting a rework in v0.3
(this and more)).
I'm talking about citation.js-showdown, citation.js-form and citation.js-replacer (coming soon). Citation.js-form is just jquery.citation.js in its own repository, citation.js-replacer will be a small tool to easily put references on your site, without having to bother with writing scripts, but, as a consequence, with fewer options. Citation.js-showdown, however, is a (functioning) Showdown plugin, that makes it easier to make references and bibliographies in a markdown document.
Bib.TXT
A few days ago I heard about Bib.TXT, and since implementing it in Citation.js only meant parsing a relatively simple text format (all the fields are the same as the already supported BibTeX), I thought: Why not? So there you have it, Bib.TXT support in Citation.js. That's good, because, among other things, you don't have to bother with weird (La?)TeX Unicode workarounds. And with Citation.js, you can easily convert Bib.TXT to BibTeX. Below as a command:
$ npm i -g citation-js@0.3.0-7 $ citation-js --input inputFile.txt --output-format string --output-style bibtex > out.bib
Homepage improvement
I changed some things on the Citation.js homepage. It should now be more responsive and have more room for expansion, and I added a demo and a small list of the "extensions" mentioned above. Oh, and the README has the same banner as the page now.
Citation.js banner |