Render citation references

Customize citation labels, styles, and click handling.

Smart Citations displays one reference after each citation's final range. It orders references by end position, then by citation ID.

Try reference labels

The demo uses a full label for the first citation of each source, a back reference for a later citation, and Id. when the previous citation uses the same source. Delete the second paragraph to see the next reference change to Id..

New tab

Customize references

Set renderCitation in your Smart Citations configuration. Use firstSourceIndex to refer to the first earlier citation of the same source. For Smith, Jones, then Smith again, the last reference displays Smith, supra note 1.

SmartCitations.configure({
  sources,
  user: { id: 'ada' },
  renderCitation: ({ defaultLabel, firstSourceIndex }) =>
    firstSourceIndex === undefined
      ? defaultLabel
      : `${defaultLabel}, supra note ${firstSourceIndex + 1}`,
  onCitationClick: ({ citations }) => {
    console.log(citations.map(citation => citation.id))
  },
})

CitationRenderContext provides citation, source, previousCitation, a zero-based index, and defaultLabel. The source and previous citation can be undefined.

For the same source, firstSourceCitation and previousSourceCitation give the first and closest earlier citations. firstSourceIndex and previousSourceIndex give their zero-based document reference indices. previousSourceCount counts all earlier citations to that source. With no earlier reference to the same source, the citations and indices are undefined and the count is 0.

Return plain text, an HTMLElement, or null to hide the reference. Hidden references count toward the index and same-source history. Return { element, destroy } to run cleanup when the extension replaces or removes the element or destroys the editor.

CitationClickContext provides the mouse event and a read-only citations array. A reference click returns one citation. A click on overlapping text can return several. Custom references can suppress the callback with preventDefault() or stopPropagation(). Use a button or link for keyboard access.

SelectorWhat it targets
[data-citation-id]Persisted mark with its citation ID.
[data-node-citations]Persisted citation metadata on a cited node.
[data-node-citation-ids]Space-separated citation IDs on a decorated node.
.citation-textDecorated cited text or node.
.citation-invalidText or a node with at least one invalid citation.
.citation-reference or [data-citation-reference]Reference wrapper.
[data-citation-status]Derived status on a text decoration, cited node, or reference wrapper.