@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.
| Name | Type | Default |
|---|---|---|
options | BibliographyPluginOptions |
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/entriesin a transaction kept out of history, so undo never steps through a re-render.
| Name | Type | Default |
|---|---|---|
__0 | BibliographyPluginOptions |
BibliographyPluginOptions
Options for bibliographyPlugin and bibliographyPlugins.
flushBibliography
Runs any pending formatting now and resolves once its result is in the doc. For tests and for exports that need fresh text.
| Name | Type | Default |
|---|---|---|
view | EditorView |
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.
| Name | Type | Default |
|---|---|---|
input | CitationInput |
CitationInput
What insertCitation and insertCitationAsFootnote take.
canInsertCitation
Whether a citation could replace the selection. The toolbar probes it.
| Name | Type | Default |
|---|---|---|
state | EditorState | |
dispatch | (tr: Transaction) => void | |
view | EditorView |
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.
| Name | Type | Default |
|---|---|---|
input | CitationInput |
editCitation
Changes the citation at pos (the selected one by default).
| Name | Type | Default |
|---|---|---|
input | Partial<CitationInput> & { pos?: number } |
removeCitationItem
Removes one source from a citation; the whole citation when it was the last.
| Name | Type | Default |
|---|---|---|
__0 | { pos?: number; sourceId: string; } |
exitCitation
Moves the caret just after the citation at pos.
| Name | Type | Default |
|---|---|---|
pos | number |
citationAt
The citation at pos, or the selected one.
| Name | Type | Default |
|---|---|---|
state | EditorState | |
pos | number |
Bibliography commands
insertBibliography
Inserts a bibliography at the caret. Refused where the schema can’t hold one (cells, notes, headers).
| Name | Type | Default |
|---|---|---|
attrs | Partial<Pick<BibliographyAttrs, "scope" | "includeUncited" | "types">> |
bibliographyAt
The bibliography at pos, or the selected one.
| Name | Type | Default |
|---|---|---|
state | EditorState | |
pos | number |
setBibliographyAttrs
Changes a bibliography’s scope, uncited-sources and type filter.
| Name | Type | Default |
|---|---|---|
attrs | Partial<Pick<BibliographyAttrs, "scope" | "includeUncited" | "types">> | |
pos | number |
setIncludeUncited
Sets includeUncited on every bibliography in the document. False when there is none.
| Name | Type | Default |
|---|---|---|
includeUncited | boolean |
setBibliographyStyle
Sets the CSL style and, optionally, the locale (null: the document language).
| Name | Type | Default |
|---|---|---|
__0 | { styleId: string; locale?: string | null; } |
convertBibliographyToStatic
Replaces a bibliography with its entries as plain paragraphs (Word’s “Convert bibliography to static text”): they stop following the citations.
| Name | Type | Default |
|---|---|---|
pos | number |
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.
| Name | Type | Default |
|---|---|---|
sourceId | string |
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.
| Name | Type | Default |
|---|---|---|
source | Omit<BibliographySource, "id"> & { id?: string; } | |
onAdded | (id: string) => void |
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.
| Name | Type | Default |
|---|---|---|
incoming | (Omit<BibliographySource, "id"> & { id?: string; })[] | |
onAdded | (count: number) => void |
updateSource
Replaces the source with source.id.
| Name | Type | Default |
|---|---|---|
source | BibliographySource |
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.
| Name | Type | Default |
|---|---|---|
sourceId | string |
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.
| Name | Type | Default |
|---|---|---|
__0 | { keepId: string; mergeIds: string[]; } |
Reading sources
sourcesOf
The root doc’s sources.
| Name | Type | Default |
|---|---|---|
state | EditorState |
findSource
The root doc’s source with this id.
| Name | Type | Default |
|---|---|---|
state | EditorState | |
sourceId | string |
normalizeDoi
A DOI without resolver prefix, lowercased; "" for none.
| Name | Type | Default |
|---|---|---|
doi | unknown |
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.
| Name | Type | Default |
|---|---|---|
source | Omit<BibliographySource, "id"> |
CitationRegistry
The plugin’s registry: citation order and per-source usage, and the bibliographies to render.
BibliographyNodeInfo
A bibliography node as the plugin renders it.
| Name | Type | Default |
|---|---|---|
pos | number | |
sectionIndex | number | |
attrs | BibliographyAttrs |
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.
| Name | Type | Default |
|---|---|---|
adapter | Pick<BibliographyAdapter, "loadStyle" | "loadLocale"> |
CitationFormatter
Turns sources and citations into runs. The citeproc implementation is the default.
| Name | Type | Default |
|---|---|---|
format | (request: FormatRequest) => Promise<FormatResult> | |
dispose | () => void |
FormatRequest
Everything a CitationFormatter needs for one pass over the document.
| Name | Type | Default |
|---|---|---|
styleId | string | |
locale | stringBCP 47. | |
sources | readonly BibliographySource[] | |
citations | readonly FormatterCitation[] | |
uncited | readonly string[]Source ids listed though nothing cites them. |
FormatResult
A formatter’s output: runs, never HTML.
FormatterCitation
One citation as the formatter sees it, in reading order.
| Name | Type | Default |
|---|---|---|
items | CitationItem[]Only items whose source exists. | |
mode | CitationMode | |
noteIndex | numberThe 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.
| Name | Type | Default |
|---|---|---|
styleId | string |
loadBundledLocale
CSL locale XML of the bundled locale closest to lang.
| Name | Type | Default |
|---|---|---|
lang | 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.
| Name | Type | Default |
|---|---|---|
input | string |
ClassifiedInput
classifyInput’s result: an identifier, normalised, or a free-text query.
| Name | Type | Default |
|---|---|---|
kind | IdentifierKind | "query" | |
value | string |
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.
normalizeDoiInput
A DOI without resolver prefix or trailing punctuation, lowercased (DOIs are case-insensitive).
| Name | Type | Default |
|---|---|---|
input | string |
isValidDoi
Whether the string is a bare DOI (10. prefix, registrant, suffix); no resolver prefix.
| Name | Type | Default |
|---|---|---|
doi | string |
isValidIsbn
Whether the string is a valid ISBN-10 or ISBN-13.
| Name | Type | Default |
|---|---|---|
isbn | string |
isValidIsbn10
Whether the string is an ISBN-10 with a valid check digit; spaces and hyphens ignored.
| Name | Type | Default |
|---|---|---|
isbn | string |
isValidIsbn13
Whether the string is a 978/979 ISBN-13 with a valid check digit; spaces and hyphens ignored.
| Name | Type | Default |
|---|---|---|
isbn | string |
isValidOrcid
Whether the string is an ORCID iD, bare or as an orcid.org URL, with a valid ISO 7064 11,2 check digit.
| Name | Type | Default |
|---|---|---|
orcid | string |
isValidArxiv
Whether the string is an arXiv id, new (2101.00001v2) or old (hep-th/9901001) scheme, arXiv: prefix allowed.
| Name | Type | Default |
|---|---|---|
id | string |
isValidUrl
Whether the string is an absolute http(s) URL.
| Name | Type | Default |
|---|---|---|
url | string |
Validation
Validation only reports: an incomplete source is kept as a placeholder.
validateSource
The problems with one source, field by field.
| Name | Type | Default |
|---|---|---|
source | BibliographySource | |
now | Date |
validateBibliography
Document-level problems: duplicates (same DOI, or same title, year and first author), uncited sources, and citations to sources the document lacks.
| Name | Type | Default |
|---|---|---|
sources | readonly BibliographySource[] | |
registry | BibliographyState | |
now | Date |
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.
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.
| Name | Type | Default |
|---|---|---|
type | CslItemType |
FieldRule
Fields a CSL type needs: each required entry is satisfied by any one of its fields (“author or editor”).
| Name | Type | Default |
|---|---|---|
required | string[][] | |
recommended | string[] |
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.
| Name | Type | Default |
|---|---|---|
text | string |
detectBibliographyFormat
Which format a file’s text is in, by its first significant characters.
| Name | Type | Default |
|---|---|---|
text | string |
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.
| Name | Type | Default |
|---|---|---|
text | string |
parseRis
Sources from RIS text (EndNote, Mendeley, most databases).
| Name | Type | Default |
|---|---|---|
text | string |
parseCslJson
Sources from CSL-JSON: an array of items, a single item, or Zotero’s { items: [...] }.
| Name | Type | Default |
|---|---|---|
text | string |
ImportResult
Parsed sources, ids as the file named them (citation keys); add them with addSource.
| Name | Type | Default |
|---|---|---|
sources | BibliographySource[] | |
errors | ImportError[] |
ImportError
A record the parser skipped, with its line when the format has lines.
| Name | Type | Default |
|---|---|---|
line | number | |
message | string |
parseBibtexName
One BibTeX name: “Last, First”, “Last, Jr, First” or “First von Last”.
| Name | Type | Default |
|---|---|---|
raw | string |
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.
| Name | Type | Default |
|---|---|---|
text | string |