Rename operations should preserve link prefix style for updated links

Use case or problem

I’m attempting to follow Google’s Open Knowledge Format for one of my vaults. One of the things it encourages is to use absolute paths for links. The / at the beginning of the path is a critical part of making it clear that it is an absolute path relative to the vault root.

However, even when using the “Path from vault folder” setting for “New link format”, any renames that affect existing links will strip the beginning slash from links in the process of updating them. This results in ambiguous link paths that are not clear whether they are absolute or relative. Although Obsidian still behaves correctly with these links, other apps or just human readers outside of Obsidian may not.

This happens whether I rename files or folders in the app UI or use plugin.app.fileManager.renameFile() from code.

Proposed solution

When updating links after a rename operation, I propose that the new link path generation should perform a best effort to match the style of the link before it was updated.

  1. If the “New link format” setting is “Path from vault folder”, then preserve the beginning slash if it was already there.
  2. If the setting is “Path from current file”, preserve the beginning ./ if it was already there.
  3. I leave it to your discretion when the setting is “Shortest path when possible”. I’m mostly focused on a markdown-first perspective, where files remain usable with or without Obsidian, and my understanding of that option is that it relies on Obsidian-specific behavior that may produce broken links outside of Obsidian.

Related: Start absolute path (path from vault folder) with a leading slash /.