@ 引用-js/plugin-csl
引用.js 的 CSL 输出插件 。 输出生成完成 citeproc-js。 。 。 .
安装
npm install @citation-js/plugin-csl
使用量
通过导入软件包注册 :
require('@citation-js/plugin-csl')
// or
import '@citation-js/plugin-csl'
格式
此插件添加的格式和其他特性 。 一般输出选项:
style:要使用的风格. 目前,内置的有:apa(默认)vancouverharvard1
lang:要使用的地块. 目前,内置的有:en-US(默认)es-ESde-DEfr-FRnl-NL
format: 输出( 标记) 格式citeproc-jstext(默认)htmlrtfasciidocfolatex
entry(单位:千美元)String, (中文(简体) ),Array[String]: 条目标识或条目标识清单,以识别要引用的项目
文献目录
此插件添加输出格式 bibliography,并接受下列具体选项:
prepend(单位:千美元)String, (中文(简体) ),Function: 预先将静态或动态文本插入到每个条目append(单位:千美元)String, (中文(简体) ),Function: 在每个条目中附加静态或动态文本nosort(单位:千美元)Boolean,默认值 :false: 不按照样式定义的规则排序asEntryArray(单位:千美元)Boolean,默认值 :false: 返回由 id 和该单项输出组成的一系列条目
这是一个例子 prepend 财务报告和审定财务报表 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'
还有一个例子,也许更现实:
let cite = new Cite('Q30000000')
let date = (new Date()).toLocaleDateString()
cite.format('bibliography', {
format: 'html',
style: '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., & 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>`
这个垫款 [$ID]: 每个条目,其中 $ID 是该条目和附件的标识 [Retrieved on $DATE]时 $DATE 是今天(对所有条目都保持不变).
这是一个例子 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"
// ]
// ]
引用
这是一个例子 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)'
配置
可以添加不同的风格和地块.
const { Cite, plugins } = require('@citation-js/core')
// or
import { Cite, plugins } from '@citation-js/core'
样式
不同 SSL 样式 可以这样注册 :
let styleName = 'custom'
let style = '<?xml version="1.0" encoding="utf-8"?><style ...>...</style>' // The actual XML file
let config = plugins.config.get('@csl')
config.styles.add(styleName, style)
let example = new Cite(...)
example.format('bibliography', {
format: 'html',
style: styleName,
lang: 'en-US'
})
语言
不同 CSL 语言 可以这样注册 :
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',
style: 'apa',
lang: language
})
发动机
配置对象还暴露了一种内部方法来准备带有给定数据和配置的 Citeproc 引擎:
let config = plugins.config.get('@csl')
let citeproc = plugins.engine(
/* data: */ [{ ... }],
/* style: */ 'apa',
/* locale: */ 'en-US',
/* format: */ 'html'
)
let sortedIds = citeproc.updateItems(/* ids: */ [...])
let makeBibliography = citeproc.makeBibliography()