0042 粘贴链接-Templater

选中文字,粘贴,就能给文字插入剪切板中的链接。这是我们认为很合理的操作。然而,Obsidian 中并不能。

对,有一个插件『Paste URL into selection』,但是这个又不怎么聪明的样子,就是只要你选中文字然后粘贴它就都当成插入链接。有点烦诶。

然后我就写了个模板,复制链接,在笔记中选中文字,然后插入模板,就添加好链接了。如果没有选中文字,会提示你输入标题。就酱!

插入后最好检查一下,避免万一的错误。

模板代码

1
2
3
4
5
6
7
<%*
const selection = tp.file.selection()
const urlSource = await tp.system.clipboard()
const url = decodeURIComponent(urlSource)
const title = selection && selection.length ? selection : await tp.system.prompt('请输入标题')
tR += `[${title ? title : url}](${url})`
%>