Hi there,
Say I just copied an internal wikilink.
I want to be able to highlight a word in a note, and press a hotkey that inserts the copied link, with the highlighted word as the link’s display text.
Are there any existing plugins that are capable of this? I have already used the link with alias and Paste into Selection plugins, and neither are exactly what I’m looking for. Paste into Selection does basically what I want, but with markdown links.
1 Like
Did you find a way?
I want this too! I even requested this for a few plugins that do this exact thing but for URLs:
1 Like
This Templater script works for me:
Script
<%*
/**
* Template Name: Paste Wikilink with Selection as Alias
* Description: pastes wikilink and puts selection into link display text.
* Version: 1.0
* Author: Created via Claude
* Source: https://forum.obsidian.md/t/paste-wiki-link-into-highlighted-text-link-with-alias/83118/4
* Last Updated: 2025-01-10
*/
const selection = tp.file.selection();
if (!selection) {
new Notice("No text selected");
return;
}
const selections = app.workspace.activeEditor.editor.listSelections();
if (selections.length > 1) {
new Notice("Multiple selections or cursors aren't supported");
return;
}
const clip = await tp.system.clipboard();
if (!/^\[{2}.*?\]{2}$/.test(clip) && !/^!\[{2}.*?\]{2}$/.test(clip)) {
new Notice("Wikilink in clipboard not found");
return;
}
const linkContent = clip.replace(/^!?/, '').slice(2, -2);
const linkText = linkContent.split("|")[0];
tR = `[[${linkText}|${selection}]]`;
%>
1 Like
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.