With Citation.js, you can parse input in a number of different ways:
- You can pass the data to the
Cite
constructor Cite Constructor - You can create a
Cite
instance asynchronously withCite.async()
Cite Constructor - You can pass the data to the
Cite#add()
andCite#set()
methods, returning the modifiedCite
instance. See Cite Data Methods - You can pass the data to
Cite.input()
andCite.inputAsync()
, returning CSL-JSON. See below
The available formats are documented in input_formats. To add your own formats, see Input Plugins.
Cite.input[Async]()
You can parse input data with Cite.input()
, which returns CSL-JSON:
let json = Cite.input('10.5281/zenodo.1005176')
> json
< [{title: 'Citation.js', DOI: '10.5281/zenodo.1005176', ...}]
There is also an async variant, Cite.parseAsync()
, that returns a Promise
.
let json = await Cite.inputAsync('10.5281/zenodo.1005176')
> json
< [{title: 'Citation.js', DOI: '10.5281/zenodo.1005176', ...}]
Input parsing in Citation.js works by:
- Determining the input format (this can be bypassed with input_options
forceType
) - If it's CSL-JSON, you're done. Else, proceed.
- Parse the input. Go back to step 1. (this step is limited by the input_options
maxChainLength
option.
This repetition of parsing is called a "chain". There are also functions to parse only a single chainlink. These are currently accessible as Cite.plugins.input.chainLink[Async]()
, and work similarly. Note that the conversion of @else/list+object
(i.e. a "miscellaneous" array) to @csl/list+object
(i.e. the end product) is considered one step.