Skip to content

UpdateLinksInFileParams

Params for updateLinksInFile.

Import:

import type { UpdateLinksInFileParams } from '@mnaoumov/obsidian-lib/link';

Signature:

export interface UpdateLinksInFileParams extends ProcessOptions

Extends: ProcessOptions

Properties

PropertyTypeDescription
appAppAn Obsidian app instance.
isEmptyEmbedAliasAllowed?booleanWhether to allow an empty alias for embeds.

Applicable only if the result link style is LinkStyle.Markdown.

If true: ![](foo.png).

If false: ![foo](foo.png).
linkPathStyle?LinkPathStyleA style of the link path.
linkStyle?LinkStyleA style of the link.
linkStyleProvider?(link: Reference) => LinkStyle | undefinedDecides the style of one link, overriding linkStyle for it. Returning undefined keeps linkStyle.

Use it when one style for the whole file is wrong for some of its links. A caller forcing LinkStyle.Markdown over a note, for example, keeps a frontmatter wikilink a wikilink, because Obsidian reads a property value as a link only in that form.
newSourcePathOrFilePathOrFileA file to update the links in.
offsetRange?OffsetRangeA range within the file's content, in character offsets, restricting the pass to the links inside it. When omitted, every link is visited.

A link is updated only when it is **fully contained** in the range; one that merely overlaps it is left alone, because rewriting part of a link corrupts it. Both bounds are inclusive, so a range whose offsets coincide exactly with a link's does include that link.

A reference that carries no position within the file's content — a frontmatter link, a multi-link frontmatter value entry, or any canvas reference — is never in range and is skipped whenever a range is supplied.

The offsets are into the content this function reads from the vault. Before reading, it saves any unsaved editor buffer for the file, so a range taken from an open editor via Editor.posToOffset is valid. The caller owns only the case where the buffer changes between computing the range and this call.
oldSourcePathOrFile?PathOrFileAn old path of the file.
pluginNoticeComponentnull | PluginNoticeComponentPlugin notice component used to show the timeout notice. When null, no timeout notice is shown regardless of ProcessOptions.shouldShowTimeoutNotice; the timeout is only logged.
(Inherited from ProcessOptions)
resourceLockComponentnull | ResourceLockComponentAn resource-lock component used to lock the file's editor read-only for the duration of processing. The lock is reference-counted, so it composes with any outer operation-level lock on the same note.
(Inherited from ProcessOptions)
shouldEscapeAlias?booleanWhether to escape the alias.

Applicable only if the result link style is LinkStyle.Markdown.

If true: [\*\*alias\*\*](link.md).

If false: [**alias**](link.md).
shouldFailOnMissingFile?booleanWhether to fail if the file is missing or deleted.
(Inherited from ProcessOptions)
shouldIncludeAttachmentExtensionToEmbedAlias?booleanWhether to include the attachment extension in the embed alias.

Applicable only if isEmptyEmbedAliasAllowed is false.

If true: [foo.png](foo.png).

If false: [foo](foo.png).
shouldShowTimeoutNotice?booleanWhether to show a timeout notice.
(Inherited from ProcessOptions)
shouldUpdateEmbedOnlyLinks?booleanWhether to update only embedded links.
shouldUpdateFileNameAlias?booleanWhether to update file name alias.
shouldUseAngleBrackets?booleanIndicates if the link should use angle brackets.

Applicable only if linkStyle is LinkStyle.Markdown.

If true: [alias](<path with spaces.md>).

If false: [alias](path%20with%20spaces.md).
shouldUseLeadingDotForRelativePaths?booleanIndicates if the link should use a leading dot.

Applicable only if linkPathStyle is LinkPathStyle.RelativePathToTheSource.

If true: [[./relative/path/to/target]]

If false: [[relative/path/to/target]]
shouldUseLeadingSlashForAbsolutePaths?booleanIndicates if the link should use a leading slash.

Applicable only if linkPathStyle is LinkPathStyle.AbsolutePathInVault.

If true: [[/absolute/path/to/target]]

If false: [[absolute/path/to/target]]

Links to this page: