Skip to Content
API Referencebibliography

@stesura/bibliography

Citations, bibliographies and their sources, framework-free: the plugins, the commands, the citeproc formatter with bundled CSL styles, validation, and BibTeX / RIS / CSL-JSON importers. The UI is in @stesura/bibliography-react; setup, the data model and the adapter contract are in the citations guide.

Plugins

Pass the same adapter here and to createBibliographyUiExtension.

bibliographyPlugins

Every plugin the bibliography needs. citationClipboardPlugin also runs in sub-editors; bibliographyPlugin is excluded from them by core.

Parameters:
NameTypeDefault
optionsBibliographyPluginOptions
Returns:
(Plugin<any> | Plugin<PluginState>)[]

bibliographyPlugin

Keeps citations and bibliographies rendered:

  • in appendTransaction (sync), registers sources carried by pasted citations, flattens citations out of headers/footers, flags missing;
  • after a change touching citations, rebuilds the registry store on a microtask (the TOC pattern);
  • formats, debounced, and writes text / entries in a transaction kept out of history, so undo never steps through a re-render.
Parameters:
NameTypeDefault
__0BibliographyPluginOptions
Returns:
Plugin<PluginState>

BibliographyPluginOptions

Options for bibliographyPlugin and bibliographyPlugins.

NameTypeDefault
adapterBibliographyAdapter

Styles, locales, the user’s library and lookups. Without one (and without a formatter) citations are healed but never formatted.

formatterCitationFormatter

Replaces the citeproc formatter built from the adapter.

debounceMsnumber

Quiet time before a change is formatted, ms.

flushBibliography

Runs any pending formatting now and resolves once its result is in the doc. For tests and for exports that need fresh text.

Parameters:
NameTypeDefault
viewEditorView
Returns:
Promise<void>

BIBLIOGRAPHY_FORMAT_META

const BIBLIOGRAPHY_FORMAT_META = "bibliographyFormat"

Meta set on the formatting pass’s transactions, which write the cached text and entries out of history. Check tr.getMeta(BIBLIOGRAPHY_FORMAT_META) to ignore them, e.g. when marking a document dirty.

Citation commands

Commands take the usual ProseMirror (state, dispatch, view) arguments; run the source commands on the root editor, since sources live in its doc.

insertCitation

Replaces the selection with a citation and node-selects it. The plugin renders its text. False without items or where a citation can’t go.

Parameters:
NameTypeDefault
inputCitationInput
Returns:
Command

CitationInput

What insertCitation and insertCitationAsFootnote take.

NameTypeDefault
itemsCitationItem[]
modeCitationMode
sourcesBibliographySource[]

Sources the items cite that the document may not have yet (picked from the library or a lookup). Carried on the node and registered by the plugin, so this works from a note’s sub-editor too.

canInsertCitation

Whether a citation could replace the selection. The toolbar probes it.

Parameters:
NameTypeDefault
stateEditorState
dispatch(tr: Transaction) => void
viewEditorView
Returns:
boolean

insertCitationAsFootnote

Inserts a footnote at the end of the selection whose text is the citation: what a note style (Chicago notes) expects. Built by node name, as the notes plugin would, so this package needs no references import: the notes plugin numbers the anchor and keeps the body.

Parameters:
NameTypeDefault
inputCitationInput
Returns:
Command

editCitation

Changes the citation at pos (the selected one by default).

Parameters:
NameTypeDefault
inputPartial<CitationInput> & { pos?: number }
Returns:
Command

removeCitationItem

Removes one source from a citation; the whole citation when it was the last.

Parameters:
NameTypeDefault
__0{ pos?: number; sourceId: string; }
Returns:
Command

exitCitation

Moves the caret just after the citation at pos.

Parameters:
NameTypeDefault
posnumber
Returns:
Command

citationAt

The citation at pos, or the selected one.

Parameters:
NameTypeDefault
stateEditorState
posnumber
Returns:
{ node: Node; pos: number; } | null

Bibliography commands

insertBibliography

Inserts a bibliography at the caret. Refused where the schema can’t hold one (cells, notes, headers).

Parameters:
NameTypeDefault
attrsPartial<Pick<BibliographyAttrs, "scope" | "includeUncited" | "types">>
Returns:
Command

bibliographyAt

The bibliography at pos, or the selected one.

Parameters:
NameTypeDefault
stateEditorState
posnumber
Returns:
{ node: Node; pos: number; } | null

setBibliographyAttrs

Changes a bibliography’s scope, uncited-sources and type filter.

Parameters:
NameTypeDefault
attrsPartial<Pick<BibliographyAttrs, "scope" | "includeUncited" | "types">>
posnumber
Returns:
Command

setIncludeUncited

Sets includeUncited on every bibliography in the document. False when there is none.

Parameters:
NameTypeDefault
includeUncitedboolean
Returns:
Command

setBibliographyStyle

Sets the CSL style and, optionally, the locale (null: the document language).

Parameters:
NameTypeDefault
__0{ styleId: string; locale?: string | null; }
Returns:
Command

convertBibliographyToStatic

Replaces a bibliography with its entries as plain paragraphs (Word’s “Convert bibliography to static text”): they stop following the citations.

Parameters:
NameTypeDefault
posnumber
Returns:
Command

goToSource

Selects the bibliography listing sourceId: what a citation’s activation does, like a cross-reference’s. Doesn’t scroll: the caller reveals the entry (bibliography-react’s useGoToSource). False when no bibliography lists it.

Parameters:
NameTypeDefault
sourceIdstring
Returns:
Command

Source commands

addSource

Adds a source. An id taken (or empty) is replaced by a free one derived from the record; onAdded gets the id it ended up with. Never blocks on validation: an incomplete source is a placeholder, not an error.

Parameters:
NameTypeDefault
sourceOmit<BibliographySource, "id"> & { id?: string; }
onAdded(id: string) => void
Returns:
Command

addSources

Adds several sources in one step (an import). A record of a work the document already holds is skipped; a taken id is replaced by a free one. onAdded gets the count added.

Parameters:
NameTypeDefault
incoming(Omit<BibliographySource, "id"> & { id?: string; })[]
onAdded(count: number) => void
Returns:
Command

updateSource

Replaces the source with source.id.

Parameters:
NameTypeDefault
sourceBibliographySource
Returns:
Command

removeSource

Removes a source. Citations to it stay, flagged missing, as Word does: the text they show is kept until the source returns or they are deleted.

Parameters:
NameTypeDefault
sourceIdstring
Returns:
Command

mergeSources

Merges duplicates into keepId: their citations are re-pointed (a citation citing both keeps one item) and the duplicates removed. Root editor only: the citations of the whole document, note bodies included, are rewritten.

Parameters:
NameTypeDefault
__0{ keepId: string; mergeIds: string[]; }
Returns:
Command

Reading sources

sourcesOf

The root doc’s sources.

Parameters:
NameTypeDefault
stateEditorState
Returns:
BibliographySource[]

findSource

The root doc’s source with this id.

Parameters:
NameTypeDefault
stateEditorState
sourceIdstring
Returns:
BibliographySource | undefined

normalizeDoi

A DOI without resolver prefix, lowercased; "" for none.

Parameters:
NameTypeDefault
doiunknown
Returns:
string

workKeyOf

What makes two records the same work: the DOI when there is one, else the normalized title, year and first author. Null when there is too little to tell.

Parameters:
NameTypeDefault
sourceOmit<BibliographySource, "id">
Returns:
string | null

CitationRegistry

The plugin’s registry: citation order and per-source usage, and the bibliographies to render.

NameTypeDefault
stateBibliographyState
bibliographiesBibliographyNodeInfo[]
bannedCitations{ node: Node; pos: number; }[]

Citations in headers/footers, which have no place in reading order: flattened by the plugin.

BibliographyNodeInfo

A bibliography node as the plugin renders it.

NameTypeDefault
posnumber
sectionIndexnumber
attrsBibliographyAttrs

Formatter

The plugin builds a citeproc formatter from the adapter; pass formatter to replace it.

createCiteprocFormatter

The default formatter: citeproc-js, with styles and locales from the adapter. One engine per style, locale and source set; a batch that edits a single citation in place goes through processCitationCluster, anything else (insertions, reorders) rebuilds the processor state, which sidesteps citeproc’s incremental quirks on reorder.

Parameters:
NameTypeDefault
adapterPick<BibliographyAdapter, "loadStyle" | "loadLocale">
Returns:
CitationFormatter

CitationFormatter

Turns sources and citations into runs. The citeproc implementation is the default.

NameTypeDefault
format(request: FormatRequest) => Promise<FormatResult>
dispose() => void

FormatRequest

Everything a CitationFormatter needs for one pass over the document.

NameTypeDefault
styleIdstring
localestring

BCP 47.

sourcesreadonly BibliographySource[]
citationsreadonly FormatterCitation[]
uncitedreadonly string[]

Source ids listed though nothing cites them.

FormatResult

A formatter’s output: runs, never HTML.

NameTypeDefault
citationsBibliographyRun[][]

One per requested citation, in order.

entriesBibliographyEntry[]

Every listed source, in the style’s order.

styleClass"note" | "in-text"

A “note” style renders citations as note text.

FormatterCitation

One citation as the formatter sees it, in reading order.

NameTypeDefault
itemsCitationItem[]

Only items whose source exists.

modeCitationMode
noteIndexnumber

The note’s 1-based number for a citation in a note, 0 in body text.

Bundled CSL styles

For hosts building an adapter without withBundledStyles (e.g. outside React).

BUNDLED_STYLES

const BUNDLED_STYLES: readonly { id: string; title: string; class: "in-text" | "note" }[]

The CSL styles shipped with the package: apa, chicago-author-date, chicago-notes-bibliography, harvard-cite-them-right, ieee, modern-language-association and nlm-citation-sequence.

loadBundledStyle

CSL XML of a bundled style. Rejects for a style that isn’t bundled.

Parameters:
NameTypeDefault
styleIdstring
Returns:
Promise<string>

loadBundledLocale

CSL locale XML of the bundled locale closest to lang.

Parameters:
NameTypeDefault
langstring
Returns:
Promise<string>

Identifiers

What the citation picker uses to tell an identifier from a free-text query, and what validation uses to check stored identifiers. A host’s lookup service can reuse them.

classifyInput

What a user typed into the citation picker: an identifier the lookup ladder can resolve, or a free-text query.

Parameters:
NameTypeDefault
inputstring
Returns:
ClassifiedInput

ClassifiedInput

classifyInput’s result: an identifier, normalised, or a free-text query.

NameTypeDefault
kindIdentifierKind | "query"
valuestring

IdentifierKind

type IdentifierKind = "doi" | "isbn" | "arxiv" | "pmid" | "pmcid" | "url"

The identifiers classifyInput recognises.

DOI_PATTERN

A DOI anywhere in the text, doi: and resolver prefixes included.

NameTypeDefault
exec(string: string) => RegExpExecArray | null
test(string: string) => boolean
sourcestring
globalboolean
ignoreCaseboolean
multilineboolean
lastIndexnumber
compile(pattern: string, flags?: string | undefined) => RegExp
flagsstring
stickyboolean
unicodeboolean
dotAllboolean
hasIndicesboolean
__@match@41422(string: string) => RegExpMatchArray | null
__@replace@41420{ (string: string, replaceValue: string): string; (string: string, replacer: (substring: string, ...args: any[]) => string): string; }
__@search@41426(string: string) => number
__@split@41428(string: string, limit?: number | undefined) => string[]
__@matchAll@41430(str: string) => RegExpStringIterator<RegExpMatchArray>

normalizeDoiInput

A DOI without resolver prefix or trailing punctuation, lowercased (DOIs are case-insensitive).

Parameters:
NameTypeDefault
inputstring
Returns:
string | null

isValidDoi

Whether the string is a bare DOI (10. prefix, registrant, suffix); no resolver prefix.

Parameters:
NameTypeDefault
doistring
Returns:
boolean

isValidIsbn

Whether the string is a valid ISBN-10 or ISBN-13.

Parameters:
NameTypeDefault
isbnstring
Returns:
boolean

isValidIsbn10

Whether the string is an ISBN-10 with a valid check digit; spaces and hyphens ignored.

Parameters:
NameTypeDefault
isbnstring
Returns:
boolean

isValidIsbn13

Whether the string is a 978/979 ISBN-13 with a valid check digit; spaces and hyphens ignored.

Parameters:
NameTypeDefault
isbnstring
Returns:
boolean

isValidOrcid

Whether the string is an ORCID iD, bare or as an orcid.org URL, with a valid ISO 7064 11,2 check digit.

Parameters:
NameTypeDefault
orcidstring
Returns:
boolean

isValidArxiv

Whether the string is an arXiv id, new (2101.00001v2) or old (hep-th/9901001) scheme, arXiv: prefix allowed.

Parameters:
NameTypeDefault
idstring
Returns:
boolean

isValidUrl

Whether the string is an absolute http(s) URL.

Parameters:
NameTypeDefault
urlstring
Returns:
boolean

Validation

Validation only reports: an incomplete source is kept as a placeholder.

validateSource

The problems with one source, field by field.

Parameters:
NameTypeDefault
sourceBibliographySource
nowDate
Returns:
BibliographyProblem[]

validateBibliography

Document-level problems: duplicates (same DOI, or same title, year and first author), uncited sources, and citations to sources the document lacks.

Parameters:
NameTypeDefault
sourcesreadonly BibliographySource[]
registryBibliographyState
nowDate
Returns:
BibliographyProblem[]

BibliographyProblem

A problem with a source or a citation. Never a refusal: an incomplete source is a placeholder, and validation only reports. code is a stable key the UI translates; params fill its message.

NameTypeDefault
level"error" | "warning" | "info"
codeBibliographyProblemCode
fieldstring
sourceIdstring
posnumber

A citation’s position, for problems anchored in the text.

paramsRecord<string, string | number>

BibliographyProblemCode

type BibliographyProblemCode = | "doi-invalid" | "isbn-invalid" | "arxiv-invalid" | "url-invalid" | "date-invalid" | "date-future" | "creator-unsplit" | "creator-empty" | "page-range-invalid" | "required-missing" | "recommended-missing" | "duplicate" | "uncited" | "missing-source"

The stable key of a BibliographyProblem; problemMessage in @stesura/bibliography-react translates it.

fieldRuleOf

The type’s field rule: which fields it needs and which it should have.

Parameters:
NameTypeDefault
typeCslItemType
Returns:
FieldRule

FieldRule

Fields a CSL type needs: each required entry is satisfied by any one of its fields (“author or editor”).

NameTypeDefault
requiredstring[][]

Import

Parsers return sources with the file’s ids (citation keys); add them with addSources.

parseBibliographyFile

Sources from BibTeX, RIS, EndNote, PubMed (MEDLINE) or CSL-JSON text, the format detected.

Parameters:
NameTypeDefault
textstring
Returns:
ImportResult

detectBibliographyFormat

Which format a file’s text is in, by its first significant characters.

Parameters:
NameTypeDefault
textstring
Returns:
BibliographyFormat | null

BibliographyFormat

type BibliographyFormat = "bibtex" | "ris" | "csl-json"

The file formats the importers read.

parseBibtex

Sources from BibTeX or BibLaTeX text, ids from the citation keys.

Parameters:
NameTypeDefault
textstring
Returns:
ImportResult

parseRis

Sources from RIS text (EndNote, Mendeley, most databases).

Parameters:
NameTypeDefault
textstring
Returns:
ImportResult

parseCslJson

Sources from CSL-JSON: an array of items, a single item, or Zotero’s { items: [...] }.

Parameters:
NameTypeDefault
textstring
Returns:
ImportResult

ImportResult

Parsed sources, ids as the file named them (citation keys); add them with addSource.

NameTypeDefault
sourcesBibliographySource[]
errorsImportError[]

ImportError

A record the parser skipped, with its line when the format has lines.

NameTypeDefault
linenumber
messagestring

parseBibtexName

One BibTeX name: “Last, First”, “Last, Jr, First” or “First von Last”.

Parameters:
NameTypeDefault
rawstring
Returns:
CslName | null

parsePlainDate

A CSL date from the forms bibliographic exports write: ISO-ish (2020, 2020-05-03, 2020/05), May 2020, and ISO ranges 2019/2020 or 2019-01/2019-03. Undefined for nothing usable; the text is kept in raw when it doesn’t parse.

Parameters:
NameTypeDefault
textstring
Returns:
CslDate | undefined
Last updated on