@citation-js/plugin-csl

0.7.14 • Public • Published

@citation-js/plugin-csl

Plugin for CSL output for Citation.js. Output generation is done with citeproc-js.

NPM version NPM total downloads License Dependency status

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
  • entry (String, Array[String]): entry ID or list of entry IDs to identify the items to cite

Bibliography

This plugin adds the output format bibliography, and accepts the following specific options:

  • prepend (String, Function): prepend static or dynamic text to each entry
  • append (String, Function): append static or dynamic text to each entry
  • nosort (Boolean, default: false): do not sort according to the style-defined rules
  • asEntryArray (Boolean, default: false): return an array of entries consisting of an id and the output for that individual entry

Here's an example for prepend and append:

let cite = new Cite({ id: 'a', title: 'Item A' })

cite.format('bibliography', { append: ' [foobar]' })
// 'Item A. (n.d.). [foobar]\n'

cite.format('bibliography', { prepend (entry) { return `${entry.id}: ` } })
// 'a: Item A. (n.d.).\n'

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}]`
})

// `<div class="csl-bib-body">
//   <div data-csl-entry-id="Q30000000" class="csl-entry">
//     [Q30000000]: Miccadei, S., De Leo, R., Zammarchi, E., Natali, P. G., &#38; Civitareale, D. (2002). The Synergistic Activity of Thyroid Transcription Factor 1 and Pax 8 Relies on the Promoter/Enhancer Interplay. <i>Molecular Endocrinology</i>, <i>16</i>(4), 837–846. https://doi.org/10.1210/MEND.16.4.0808 [Retrieved on 2018-7-10]
//   </div>
// </div>`

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).

Here's an example for asEntryArray:

const cite = new Cite([
  { id: 'a', title: 'Item A', issued: { literal: 2021 } },
  { id: 'b', title: 'Item B', issued: { literal: 2021 } }
])

cite.format('bibliography', { asEntryArray: true })
// [
//   [
//     "a"
//     "Item A. (2021).\n"
//   ],
//   [
//     "b"
//     "Item B. (2021).\n"
//   ]
// ]

Citation

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')
// '(“Item A,” 2016; “Item B,” 2017; “Item C,” 2018)'

cite.format('citation', { entry: ['a', 'b'] })
// '(“Item A,” 2016; “Item B,” 2017)'

cite.format('citation', { entry: 'a' })
// '(“Item A,” 2016)'

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>' // The actual XML file

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>' // The actual XML file

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(
  /* data: */ [{ ... }],
  /* template: */ 'apa',
  /* locale: */ 'en-US',
  /* format: */ 'html'
)

let sortedIds = citeproc.updateItems(/* ids: */ [...])
let makeBibliography = citeproc.makeBibliography()

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.7.1412,224latest

Version History

VersionDownloads (Last 7 Days)Published
0.7.1412,224
0.7.1316
0.7.11591
0.7.91,161
0.7.635
0.7.2778
0.7.110
0.7.00
0.6.91,169
0.6.8391
0.6.7134
0.6.514
0.6.456
0.6.30
0.6.10
0.6.00
0.5.7628
0.5.5174
0.5.473
0.5.330
0.5.21
0.5.15
0.5.0643
0.5.0-alpha.101
0.5.0-alpha.94
0.5.0-alpha.80
0.5.0-alpha.70
0.5.0-alpha.60
0.5.0-alpha.50
0.5.0-alpha.40
0.5.0-alpha.30
0.5.0-alpha.20
0.5.0-alpha.10
0.5.0-alpha.00
0.4.101,684
0.4.90
0.4.86
0.4.71
0.4.60
0.4.50
0.4.30
0.4.3-alpha.00
0.4.20
0.4.10
0.4.00
0.4.0-rc.40
0.4.0-rc.30
0.4.0-rc.20
0.4.0-rc.10
0.4.0-rc.00

Package Sidebar

Install

npm i @citation-js/plugin-csl

Weekly Downloads

19,829

Version

0.7.14

License

MIT

Unpacked Size

361 kB

Total Files

23

Last publish

Collaborators

  • larsgw