Contains utility functions for handling references in Obsidian.
| Function |
Description |
| getReferenceLinkText |
Gets the text of the one link a reference stands for. For most references that is Reference.original. A frontmatter link that carries offsets is the exception: its original is the WHOLE property value, which may hold several links, and startOffset / endOffset give this link’s span in it. Anything that parses, compares or replaces the link as one link must read that span, never the whole value. |
| isCanvasFileNodeReference |
Checks if a reference is a canvas file node reference. |
| isCanvasReference |
Checks if a reference is a canvas reference. |
| isCanvasTextNodeReference |
Checks if a reference is a canvas text node reference. |
| isReferenceInHeading |
Checks if a reference sits inside a heading. The answer comes from the parsed heading positions of the file’s metadata, never from a pattern over its text: a reference is inside a heading when it is fully contained in a headings entry or in a heading section. The section covers a Setext heading’s underline as well, so both heading syntaxes count. Only a reference that carries a position within the file’s content can be inside a heading. A FrontmatterLinkCache — a frontmatter link, a multi-link frontmatter value entry, or any canvas reference — never is. A link in a heading is part of that heading’s text, and so of every #heading subpath pointing at it. Rewriting such a link changes the heading text and breaks those subpaths, which is why a link converter may want to leave it alone. |
| isReferenceInOffsetRange |
Checks if a reference is fully contained within an offset range. Only a reference that carries a position within the file’s content can be in a range. A FrontmatterLinkCache — a frontmatter link, a multi-link frontmatter value entry, or any canvas reference — carries no such position and is therefore never in range. Its startOffset / endOffset, where present, locate the link within its own property value rather than within the file, so they are deliberately not compared against the range. Containment is full and both bounds are inclusive: a reference that only partially overlaps the range is not in it, because rewriting part of a link corrupts it. |
| referenceToFileChange |
Converts a reference to a file change. |
| sortReferences |
Sorts references by their type and position. |