No description
  • TypeScript 90.5%
  • JavaScript 9.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Johannes Wilm 901d0afde6
Some checks are pending
Deploy demo to Codeberg Pages / deploy (push) Waiting to run
include zotero2jurismCSL and modify it not to require citeproc-js,
relates to #1
2026-07-28 00:15:51 +02:00
.forgejo/workflows modernize code 2026-07-16 19:24:51 +02:00
.githooks var => let/const 2026-07-16 23:32:53 +02:00
.github/workflows export entirely as module 2026-07-16 23:22:33 +02:00
demo demo: use named import 2026-07-17 09:36:14 +02:00
fixtures export entirely as module 2026-07-16 23:22:33 +02:00
src 0.2.3: add core module (without XML parsing) 2026-07-17 09:30:32 +02:00
test-runner include zotero2jurismCSL and modify it not to require citeproc-js, 2026-07-28 00:15:51 +02:00
tools 0.2.3: add core module (without XML parsing) 2026-07-17 09:30:32 +02:00
.gitattributes minor comment updates 2026-07-16 23:26:07 +02:00
.gitignore 0.2.3: add core module (without XML parsing) 2026-07-17 09:30:32 +02:00
AGPLv3 Add a copy of AGPLv3, as an alternative license. 2010-06-01 21:47:01 +09:00
CPAL Tidy up license notices a bit 2016-03-04 23:00:52 +09:00
cslrun.yaml export entirely as module 2026-07-16 23:22:33 +02:00
eslint.config.js remove CSL imports 2026-07-17 05:44:08 +02:00
LICENSE Update copyright assertion 2019-03-08 09:03:54 +09:00
logo.svg modernize code 2026-07-16 19:24:51 +02:00
package-lock.json include zotero2jurismCSL and modify it not to require citeproc-js, 2026-07-28 00:15:51 +02:00
package.json include zotero2jurismCSL and modify it not to require citeproc-js, 2026-07-28 00:15:51 +02:00
package.template get rid of commonjs 2026-07-16 22:37:55 +02:00
README.md 0.2.3: add core module (without XML parsing) 2026-07-17 09:30:32 +02:00
tsconfig.json Restructure (1/N): convert sources to ES modules and bundle with esbuild 2026-07-15 17:38:40 +02:00

citeproc-ts

citeproc-ts

A TypeScript fork of citeproc-js — a Citation Style Language (CSL) processor for JavaScript, with a modernized code structure.

This is a fork of citeproc-js with relatively few changes beyond:

  • Porting the codebase from raw JavaScript to TypeScript
  • Adopting a modern project structure (esbuild bundling, local dev dependencies, gitignored build artifacts)
  • Replacing the Java-based Jing RELAX NG validator with a pure-JavaScript RNC validator (tools/rnc-validator.js)

The processor itself — CSL style parsing, citation formatting, bibliography generation — follows citeproc-js closely, with minimal rendering changes. All 1,518 integration tests pass.

Live demo — renders Chicago-style citations and bibliography in the browser.

Credits

This project is derived from citeproc-js, created and maintained over many years by:

  • Michael McMillan — original author
  • Frank Bennett — long-time maintainer, added CSL-M extensions for multilingual and legal content

citeproc-js powers the word processor integrations in both Zotero and Mendeley.

Bundles

Two ESM bundles are published:

Bundle File Size Description
Full citeproc.mjs ~765 KB Compatible with citeproc-js API. Includes XML/DOM parsing.
Core citeproc-core.mjs ~683 KB No XML/DOM parsing. For consumers that provide pre-parsed JSON styles/locales (e.g. citeproc-plus). Allows bundlers to tree-shake unused code.

Both export a CSL namespace identical in shape, except the core bundle omits parseXml, stripXmlProcessingInstruction, XmlDOM, and setupXml.


Usage

Traditional interface (full bundle)

import { CSL } from 'citeproc-ts';

const sys = {
    retrieveLocale(lang) { /* return locale XML/JSON string */ },
    retrieveItem(id)     { /* return citation item object */ },
};

const engine = new CSL.Engine(sys, styleXmlString, 'en-US');
engine.previewCitationCluster(...);
engine.makeBibliography(...);

The full bundle is a drop-in replacement for citeproc-js. Pass CSL XML strings, JSON strings, or pre-parsed objects — setupXml handles all formats.

Tree-shakeable interface (core bundle)

import { CSL } from 'citeproc-ts/core';

const sys = {
    retrieveLocale(lang) { /* return JSON object — never raw XML */ },
    retrieveItem(id)     { /* return citation item object */ },
};

// Pass a pre-parsed JS object (e.g. JSON.parse(…)) or an XmlJSON instance
const engine = new CSL.Engine(sys, styleObject, 'en-US');
engine.previewCitationCluster(...);
engine.makeBibliography(...);

The core bundle omits the parseXml() XML parser and XmlDOM DOM wrapper. Use it when your style/locale data is always pre-parsed JSON (objects or JSON strings). This reduces bundle size and lets bundlers tree-shake the XML processing code entirely.

Note

: If you pass an XML string or a DOM node to the core bundle, setupXml will log an error and return a stub parser. Always provide JSON objects or JSON strings.

Selecting the right bundle

Your data format Recommended import
CSL XML strings 'citeproc-ts' (full)
Mix of XML and JSON 'citeproc-ts' (full)
Pre-parsed JS objects only 'citeproc-ts/core' (core)
JSON strings only 'citeproc-ts/core' (core)

Advanced: using internals

The internals object (CSL.internals) provides hooks for host environment integration:

CSL.debug = function (str) { myLogger.debug('CSL: ' + str); };
CSL.error = function (str) { myLogger.error('CSL: ' + str); };
CSL.stringCompare = function (a, b) { return myCollator.compare(a, b); };

This is the extension point originally designed for XSL integration. You can override getAbbreviation, retrieveStyleModule, and other callbacks here.


Building

npm install
npm run build          # builds citeproc.mjs and citeproc-core.mjs
npm run build:runner   # compiles the test runner

Running Tests

npm test               # builds + runs all 1,518 tests (no Java required)

The test runner (cslrun) is included locally — no global installs needed.

License

CPAL-1.0 OR AGPL-3.0-or-later (same as citeproc-js).

The test runner component (test-runner/) is MIT (original author: Frank Bennett).

Repository

https://codeberg.org/fiduswriter/citeproc-ts