@citation-js/plugin-csl

中文文档
0.9.0发布于 2026/09/18MITTypeScriptESM + CJS近 30 天下载 31万

引用.js 的 SSL 输出插件

中文使用文档
文档目录6 节
  1. 安装
  2. 使用量
  3. 格式
  4. 文献目录
  5. 引用
  6. 配置

@ 引用-js/plugin-csl

引用.js 的 CSL 输出插件 。 输出生成完成 citeproc-js。 。 。 .

NPM version NPM total downloads License Dependency status

安装

npm install @citation-js/plugin-csl

使用量

通过导入软件包注册 :

require('@citation-js/plugin-csl')
// or
import '@citation-js/plugin-csl'

格式

此插件添加的格式和其他特性 。 一般输出选项:

  • style:要使用的风格. 目前,内置的有:
    • apa (默认)
    • vancouver
    • harvard1
  • lang:要使用的地块. 目前,内置的有:
    • en-US (默认)
    • es-ES
    • de-DE
    • fr-FR
    • nl-NL
  • format: 输出( 标记) 格式 citeproc-js
    • text (默认)
    • html
    • rtf
    • asciidoc
    • fo
    • latex
  • 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., &#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>`

这个垫款 [$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()

版本与发布记录

@citation-js/plugin-csl 共发布 57 个版本,首次发布于 2018/12/07;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.9.0latest2026/09/181 个月前
0.8.22026/07/133 个月前
0.8.12026/07/064 个月前
0.8.02026/07/064 个月前
0.7.222026/01/0110 个月前
0.7.212025/10/201.1 年前

关于 @citation-js/plugin-csl 的常见问题

@citation-js/plugin-csl 是什么?

引用.js 的 SSL 输出插件

如何安装 @citation-js/plugin-csl?

在项目目录运行 npm install @citation-js/plugin-csl,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@citation-js/core(^0.9.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@citation-js/plugin-csl 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@citation-js/plugin-csl 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@citation-js/plugin-csl 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@citation-js/plugin-csl 可以商用吗?

@citation-js/plugin-csl 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@citation-js/plugin-csl 的下载量有多少?

根据 npm 官方下载统计,@citation-js/plugin-csl 在 2026/10/10 – 2026/11/08 这 30 天内被下载 309,793 次,日均约 10,326 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@citation-js/plugin-csl 还在维护吗?

最新版本 0.9.0 发布于 2026/09/18(1 个月前);至今共发布 57 个版本,其中过去 12 个月发布了 5 个;首次发布于 2018/12/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。