# @citation-js/plugin-csl 中文文档

规范地址：https://npmcn.com/package/%40citation-js/plugin-csl/

版本：0\.9\.0
npm 元数据更新时间：2026-09-18T11:14:42.775Z
中文译文更新时间：2026-11-09T16:59:39.890Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40citation-js/plugin-csl
原文对照：https://npmcn.com/package/%40citation-js/plugin-csl/?lang=original
项目主页：https://citation.js.org/
源码仓库：https://github.com/citation-js/citation-js

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：460 kB，24 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=22\.12\.0
- 运行依赖：2 个
- peer 依赖：@citation-js/core ^0\.9\.0
- 首次发布：2018-12-06T20:51:55.221Z
- 最新版本发布：2026-09-18T11:14:42.597Z
- 近 30 天下载量：309793（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：57（近 12 个月 5 个）

## 中文简介

引用.js 的 SSL 输出插件

## 安装

```sh
npm install @citation-js/plugin-csl
```

也可以使用：`pnpm add @citation-js/plugin-csl`、`yarn add @citation-js/plugin-csl`、`bun add @citation-js/plugin-csl`

## README

# @ 引用-js/plugin-csl

引用.js 的 CSL 输出插件 。 输出生成完成 [`citeproc-js`](https://github.com/Juris-M/citeproc-js)。 。 。 .

## [![NPM version](https://img.shields.io/npm/v/@citation-js/plugin-csl.svg)](https://npmjs.org/package/@citation-js/plugin-csl) [![NPM total downloads](https://img.shields.io/npm/dt/@citation-js/plugin-csl.svg)](https://npmcharts.com/compare/@citation-js%2Fplugin-csl?minimal=true) ![License](https://img.shields.io/npm/l/@citation-js/plugin-csl.svg) ![Dependency status](https://img.shields.io/librariesio/release/npm/@citation-js/plugin-csl)

## 安装

```
npm install @citation-js/plugin-csl
```

## 使用量

通过导入软件包注册 :

```js
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`数字 :

```js
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'
```

还有一个例子,也许更现实:

```js
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`数字 :

```js
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`数字 :

```js
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)'
```

### 配置

可以添加不同的风格和地块.

```js
const { Cite, plugins } = require('@citation-js/core')
// or
import { Cite, plugins } from '@citation-js/core'
```

#### 样式

不同 [SSL 样式](https://github.com/citation-style-language/styles) 可以这样注册 :

```js
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 语言](https://github.com/citation-style-language/locales) 可以这样注册 :

```js
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 引擎:

```js
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 是什么？

引用\.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 和提交记录判断。

