Skip to content

link

This module provides utilities for handling and updating links within Obsidian vaults. It includes functions to split paths, update links in files, and generate markdown links with various options.

Interface Description
BacklinkConversionParams Params passed to the link converter of editBacklinksSnapshot.
BacklinksLike The minimal shape buildBacklinksSnapshot reads a set of backlinks from. Both a CustomArrayDict<Reference> — what getBacklinksForFileSafe returns — and a plain Map<string, Reference[]> satisfy it, so a caller can pass either without converting first.
BuildBacklinksSnapshotParams Params for buildBacklinksSnapshot.
ConvertLinkParams Params for convertLink.
EditBacklinksParams Parameters for editBacklinks.
EditBacklinksSnapshotParams Parameters for editBacklinksSnapshot.
EditLinksInContentParams Parameters for editLinksInContent.
EditLinksParams Parameters for editLinks.
ExtractLinkFileParams Parameters for extractLinkFile.
GenerateMarkdownLinkParams Params for generateMarkdownLink.
GenerateRawMarkdownLinkParams Params for generateRawMarkdownLink.
ShouldResetAliasParams Params for shouldResetAlias.
SplitSubpathResult Splits a link into its link path and subpath.
UpdateFileUrlLinksInContentParams Params for updateFileUrlLinksInContent.
UpdateFileUrlLinksInFileParams Params for updateFileUrlLinksInFile.
UpdateLinkParams Params for updateLink.
UpdateLinksInFileParams Params for updateLinksInFile.
Function Description
buildBacklinksSnapshot Records a set of backlinks into a snapshot that editBacklinksSnapshot can rewrite later. Call it once per target and pass BuildBacklinksSnapshotParams.target to accumulate several targets into one snapshot, so that a note linking to several of them is still rewritten exactly once.
convertLink Converts a link to a new path.
editBacklinks Edits the backlinks for a file or path.
editBacklinksSnapshot Edits a captured snapshot of backlinks, rewriting each backlink-holding note exactly once. The counterpart of editBacklinks for callers that cannot fetch the backlinks at rewrite time — because the rename that invalidated them has already happened — or that rewrite links to several targets at once. See BacklinksSnapshot for both cases.
editLinks Edits the links for a file or path.
editLinksInContent Edits the links in a content string.
extractLinkFile Extracts the file associated with a link.
generateMarkdownLink Generates a markdown link based on the provided parameters.
generateRawMarkdownLink Generates a raw markdown link based on the provided params.
getGenerateMarkdownLinkDefaultParamsFns Returns the shared, mutable list of functions that provide default params for generateMarkdownLink. Each function is invoked on every generateMarkdownLink call and its result is merged into the params (later registrations take precedence over the built-in defaults, but never over explicitly passed params). Register entries by adding a GenerateMarkdownLinkDefaultParamsComponent to a component tree rather than mutating this list directly.
hasAngleBrackets Tests whether a link uses angle brackets, possibly embed: [title](<link>), ![title](<link>).
hasEmbedSyntax Tests whether a link is an embed link: ![[link]], ![title](link).
hasLeadingDot Tests whether a link has a leading dot, possibly embed: [[./link]], [title](./link), [title](<./link>), ![[./link]], ![title](./link), ![title](<./link>).
hasLeadingSlash Tests whether a link has a leading slash, possibly embed: [[/link]], [title](/link), [title](</link>), ![[/link]], ![title](/link), ![title](</link>).
hasWikilinkSyntax Tests whether a link is a wikilink, possibly embed: [[link]], ![[link]].
shouldResetAlias Determines if the alias of a link should be reset.
splitSubpath Splits a link into its link path and subpath.
updateFileUrlLinksInContent Normalizes the file:// links in a content string to a pretty form, converting backslashes to forward slashes. Other links are left unchanged.
updateFileUrlLinksInFile Normalizes the file:// links in a file to a pretty form, converting backslashes to forward slashes. Other links are left unchanged.
updateLink Updates a link based on the provided parameters.
updateLinksInContent Updates the links in a content string based on the provided parameters.
updateLinksInFile Updates the links in a file based on the provided parameters.
Type Description
BacklinksSnapshot A captured snapshot of a set of backlinks: the path of each backlink-holding note, mapped to the identity keys of that note’s own links to the target(s), each mapped to the payload recorded for it. The snapshot exists so that the fetch and the rewrite can happen at different moments. A rename invalidates the metadata cache for the old path, so a caller that rewrites links after renaming has to capture the backlinks before — which is why editBacklinksSnapshot takes a snapshot rather than a path. The payload is whatever the caller needs to remember per link. It is undefined for a single-target rewrite (the target is implied), and the old target’s path for a multi-target one, where one note’s links may point at several files that all moved and each link has to be resolved to its own new path.
EditBacklinksOptions Options for editBacklinks.
EditBacklinksSnapshotOptions Options for editBacklinksSnapshot.
EditLinksOptions Options for editLinks.
MutableBacklinksSnapshot A BacklinksSnapshot while it is still being accumulated by buildBacklinksSnapshot.
Enum Description
LinkPathStyle A style of the link path.
LinkStyle A style of the link.