This sounds like a good plugin idea.
I like this idea too. +1
He’s suggesting this as a possible fix, not saying it works now.
I’ve run into this issue too, I agree that the original text should be kept.
2 posts were split to a new topic: If a link has matching name and alias, do not change alias if the note is renamed
I’m currently considering renaming the file to UID{{date:YYYYMMDDHHmmss}}, and I wish this feature existed.
create [[any words]] wikilinks on multiple notes and then create [[any words]] notes and rename the file to just a UID, many notes lose their context.
I want an option to use original text as display text when updating internal links.
Workaround… for a workaround discovered:
If we have the link:
[[Apples|Apples]]
And the file Apples.md gets renamed to Oranges.md
The link will become:
[[Oranges|Oranges]]
But if the file Apples.md contains the alias Apples in YAML:
---
aliases: Apples
---
then when Apples.md is renamed to Oranges.md
the original link [[Apples|Apples]] will keep its display text, turning into:
[[Oranges|Apples]]
The plugin Link with alias adds a “Create link with alias” command that, when run for selection Hello in:
Hello, world!
-
Will output:
[[Hello|Hello]], world!or (depending on plugin setting)
[[|Hello]], world!with cursor placed before
|in both cases. -
Once the cursor leaves the line with the link, will put the alias
Hellointo the target note’s YAML:--- aliases: Hello ---
This effectively utilizes the workaround shared above.
After mulling this over, I’m gonna go with the following workaround: to prevent any possible occurrence of the link display text auto-rename introduced in ver. 1.2.1, I will prepend all link display text with a zero-width space.
I set up regex search-and-replace rule in Linter to automate this process. (It’s also possible to apply this rule to all existing notes by running the command to lint all files).
The regex to find is:
\[\[(?!.*?\.(?:avif|bmp|gif|jpe?g|png|svg|webp|canvas|pdf)(?=[|\]]))([^\]|]+)\|(?![\s]*–)(?!(?:X|Y|Z)\s*)(?![^\]|]*\|)([^\]|]+)\]\]
(X, Y and Z here are placeholders for aliases to exclude from this rule—I use this for custom cssclasses).
With the flags set to gi and regex to replace set to:
[[$1|$2]]
Also, for the Web Clipper author property to follow this rule, the filter is:
{{author|split:", "|wikilink|join|replace:"/\[{2}([^\]]+)\]{2}/g":"[[$1|$1]]"}}
Alternatively, for the problem outlined in the OP, one could, whenever creating an unresolved link, duplicate its target into link display text but add a distinguishing character to it like so:
[[unresolved|– unresolved]]
Here, Claude wrote me a Templater script to perform this action in one go:
Templater script
<%*
/**
* Template Name: Add Unresolved Link
* Description: Creates wikilink with –prefix alias from selection or prompts for input. If selection is already a wikilink, adds –prefix to alias.
* Version: 1.0
* Author: Created via Claude
* Source: https://forum.obsidian.md/t/add-option-to-always-preserve-original-link-text-as-display-text-alias-when-the-target-note-is-renamed-dont-change-original-text-when-updating-links/6521/32
* Last Updated: 2024-01-09
*/
const selection = tp.file.selection();
const editor = app.workspace.activeLeaf.view.editor;
const selections = editor.listSelections();
if (selections.length > 1) {
new Notice("Multiple selections or cursors aren't supported");
tR = editor.getSelection();
return;
}
let linkText;
if (selection) {
// Check if selection is already a wikilink
const wikiLinkMatch = selection.match(/\[\[(.*?)\]\]/);
if (wikiLinkMatch) {
linkText = wikiLinkMatch[1];
} else {
linkText = selection;
}
} else {
linkText = await tp.system.prompt("Add unresolved link");
if (!linkText) return;
}
tR = `[[${linkText}|–${linkText}]]`;
tp.file.cursor_append("");
-%>
It’s a dirty workaround but also a feature:
-
If the link ever becomes resolved,
–will still signify that it was unresolved at the time of link creation. -
The following regex search query will show all such links in vault:
/\[\[.*?\|–[^\]]+?\]\]/For easy access, the query can be saved to Bookmarks.
Related bug report: Renaming notes may change display text in referencing notes
This got insta-sent to the bug graveyard, which to me reads like “we’re not fixing that”.
No, we consider this a FR and you were linked to continue here.
On a tangential note, in v1.11.6+ If a link has matching name and alias, do not change alias if the note is renamed was implemented for links in the shortest path format.
Links with complete path and alias will still change both.
So the trick of doing [[collagen|collagen]], as it was referred in this thread in the past, will work again.