@citation-js/plugin-csl
Plugin for CSL output for Citation.js. Output generation is done with citeproc-js
.
Install
npm install @citation-js/plugin-csl
Usage
Register by importing the package:
require('@citation-js/plugin-csl')
Formats
Formats and other features added by this plugin. General output options:
template
: the style template to use. Currently, the following are built-in:
apa
(default)vancouver
harvard1
lang
: the locale to use. Currently, the following are built-in:
en-US
(default)es-ES
de-DE
fr-FR
nl-NL
format
: output (markup) format. Note: this doesn't support the output format dictionaries
Bibliography
This plugin adds the output format bibliography
, and accepts the following specific options:
prepend
(String
, Function
): prepend static or dynamic text to each entryappend
(String
, Function
): append static or dynamic text to each entrynosort
(Boolean
, default: false
): do not sort according to the style-defined rules
Here's an example for prepend
and append
:
let cite = new Cite({id: 'a', title: 'Item A'})
cite.format('bibliography', {append: ' [foobar]'})
cite.format('bibliography', {prepend (entry) { return `${entry.id}: ` }})
And here's another example, possibly more realistic:
let cite = new Cite('Q30000000')
let date = (new Date()).toLocaleDateString()
cite.format('bibliography', {
format: 'html',
template: 'apa',
prepend (entry) {
return `[${entry.id}]: `
},
append: ` [Retrieved on ${date}]`
})
This prepends [$ID]:
to each entry, where $ID
is the ID of that entry, and appends [Retrieved on $DATE]
, where $DATE
is today (constant for all entries).
Citation
This plugin adds the output format citation
, and accepts the following specific options:
entry
(String
, Array[String]
): entry ID or list of entry IDs to identify the items to cite
Here's an example for entry
:
let cite = new Cite([
{id: 'a', title: 'Item A', issued: {'date-parts': [[2016]]}},
{id: 'b', title: 'Item B', issued: {'date-parts': [[2017]]}},
{id: 'c', title: 'Item C', issued: {'date-parts': [[2018]]}}
])
cite.format('citation')
cite.format('citation', {entry: ['a', 'b']})
cite.format('citation', {entry: 'a'})
Configuration
It is possible to add different styles and locales.
const {Cite, plugins} = require('@citation-js/core')
Templates
Different CSL Templates can be registered like this:
let templateName = 'custom'
let template = '<?xml version="1.0" encoding="utf-8"?><style ...>...</style>'
let config = plugins.config.get('csl')
config.templates.add(templateName, template)
let example = new Cite(...)
example.format('bibliography', {
format: 'html',
template: templateName,
lang: 'en-US'
})
Locales
Different CSL Locales can be registered like this:
let language = 'en-GB'
let locale = '<?xml version="1.0" encoding="utf-8"?><locale ...>...</locale>'
let config = plugins.config.get('csl')
config.locales.add(language, locale)
let example = new Cite(...)
example.format('bibliography', {
format: 'html',
template: 'apa',
lang: language
})
Engine
The configuration object also exposes an internal method to prepare a Citeproc engine with given data and configuration:
let config = plugins.config.get('csl')
let citeproc = plugins.engine(
[{...}],
'apa',
'en-US',
'html'
)
let sortedIds = citeproc.updateItems( [...])
let makeBibliography = citeproc.makeBibliography()