Using/creating a custom(?) schema/short-hand to expand into a html-link

Hey,

I didn’t know how to phrase my question better.

I often have to past links into my notes which all have a similar url: https://some.where/id-XXXX

I am looking for a way where I only type [id-XXXX] and Obsidian will automatically expand the short-hand to the full url either as [id-XXXX](https://some.where/id-XXXX) or just https://some.where/id-XXXX. Ideally this would happen automatically after typing the ID in brackets, but I would also be happy if I had to press some kind of key-combination or close and open Obsidian/the note to trigger the changes.

I haven’t found any discussion which seems to ask for the same thing. If there are any please point me there. And since I’m not sure if this is the right part of the forum, please move the question if necessary.

I don’t know if there is any plugin in Obsidian that can do that. Maybe ones like GitHub - ArianaKhit/text-snippets-obsidian: Snippets plugin for obsidian Or maybe Templater or RunJS.

But you could also check into snippet manager apps in whatever OS you use. They might have the ability to trigger patterns like that.

The only one I’m familiar with is Alfred on MacOS, and it has workflows that could likely do things like this.

Templater could be a good solution if the IDs and their corresponding links follow a consistent pattern.

In the script, you can retrieve the current note’s content, use regex to find all IDs, replace them with the correct links, and save the updated content. You can also assign a hotkey to the Templater template, making it easy to run on any note.

EDIT:
Something like this would work. If you are going to use it, make sure the regex covers you use case. Especially, when letter case matters or your id contains special symbols.

<%*
const activeNote = app.workspace.getActiveFile();
let noteContent = await app.vault.read(activeNote);

const baseURL = "https://some.where/";

noteContent = noteContent.replace(/\[id-([a-zA-Z0-9]+)\](?!\()/gi, (match, id) => {
    return `[id-${id}](${baseURL}id-${id})`;
});

await app.vault.modify(activeNote, noteContent);
%>