Smart Citations extension

Configure Smart Citations and customize text review, references, and callbacks.

Import SmartCitations and its public types from @tiptap-pro/extension-smart-citations. The package also exports createSources, defaultShouldReviewCitation, and the query functions. Run citation commands on editor.commands.

The runtime extension name is smartCitations. Inline citations use the citation mark. Node citations use the smartCitations node attribute, an array of CitationAttributes serialized to HTML as data-node-citations.

Configuration

The configuration type for SmartCitations is SmartCitationsOptions.

OptionTypeRequired or default
sourcesSourceCollection | nullProvide an application-owned source collection. The default null fails editor setup.
userCitationUser | (() => CitationUser)Required. Provide a nonempty string id and optional string name.
shouldReviewCitationShouldReviewCitationOptional. Defaults to defaultShouldReviewCitation.
renderCitation(context: CitationRenderContext) => CitationRenderResultDefaults to the source label or Missing source. See reference rendering.
formatCopiedReference(context: CopiedReferenceContext) => string | nullFormats copied references as [Label] by default. See copy and paste.
onCitationClick(context: CitationClickContext) => voidOptional. See references and clicks.
onError(error: CitationError) => voidOptional. Receives expected command failures.

When the active user can change, pass a synchronous user callback that reads the current app state. Keep it free of side effects. Smart Citations calls it during setup, local edits, and validation for creation, approval, and restoration.

If the callback returns an invalid user during an edit, Smart Citations keeps the edit and prior attribution and reports invalidUser.

Text review rule

ShouldReviewCitation is (context: CitationReviewContext) => boolean. Smart Citations calls it when the current and confirmed comparison strings for an inline citation differ. The context has four readonly fields.

FieldTypeMeaning
textstringCurrent comparison text. Hard breaks between cited ranges can appear as \n.
confirmedTextstringConfirmed comparison text. Uses citation.confirmedReviewText if present, otherwise citation.confirmedText.
citationReadonly<Omit<Citation, 'status' | 'invalidReasons'>>Current citation before status and invalid reasons are calculated.
sourceSourceSnapshot | undefinedCurrent source, if present.

Returning true adds textChanged. Returning false skips that reason and keeps the confirmed text for future comparisons. A changed or missing source can still invalidate either kind of citation.

defaultShouldReviewCitation takes { text, confirmedText }. It trims both strings and collapses runs of whitespace to a single space. With 10 samples as the confirmed text, 10 samples returns false. 10samples, 10 sam ples, 12 samples, and 10 Samples return true.

Keep the callback synchronous and free of side effects. Use the same rule and equivalent source snapshots across collaborating editors to derive the same citation status.

Copied reference format

CopiedReferenceContext contains the readonly fields citation: Citation and label: string. The label is the plain text of the displayed reference. Return the full string to append, including any spacing, or null to omit the label. The format applies to both plain-text and HTML clipboard content.