在templater和Advanced URI的帮助下已经能实现下图这样的效果了:
可是它除了返回引用链接外还会额外换行, 在列表中使用的话, 就会像上图这样列表被中断了, 我心目中理想的效果应该是这样的:
即在操作完成后光标紧贴着链接, 而不是自动换行. 这个好像是由templater本身决定的. 请问有大佬知道应该怎么做吗?
<%*
/*======== 以下内容按需修改 =======*/
// 新笔记的存放位置,例如:Folder/SubFolder/
const path = '3永久笔记/'
// 笔记模板,created 创建时间,updated 更新时间,这两个名字按需修改,也可以加入其它内容
const template = (alias, tags, content)=>`---
aliases: ${alias}
tags:
${tags}
---
${content}
`
/*======== 以上内容按需修改 =======*/
// const nowTime = tp.date.now("YYYY-MM-DD HH:mm:ss")
// 将选中部分作为内容
let content = tp.file.selection()
// 如果没有选中内容则使用剪切板中的内容
if(!content.length){
content = await tp.system.clipboard()
}
// 如果没有内容,就要求输入(快速记录)
if(!content.length){
content = await tp.system.prompt('请输入笔记内容:', '', false, true)
}
// 如果有内容就保存,没内容就下班
if(content.length){
// 要求用户输入信息,不过一溜回车也可以
let title = await tp.system.prompt('请输入笔记的名称(不可包含 *"\\/<>:|?):')
if (!title) {
title = '默认标题'
}
const typechoice = await tp.system.suggester(
["词条笔记", "观点笔记"],
[0, 1]);
const typecontent = ['词条笔记/公认词条', '观点笔记/成熟观点']
types = typecontent[typechoice]
const tags = await tp.system.prompt('请输入笔记的标签(多个标签用空格分隔):', types)
const alias = await tp.system.prompt('请输入笔记的别名(仅用于当前链接):', title)
//整理一下信息
const tagsCode = tags.split(/\s+/g).map(tag=>` - ${tag}`).join('\n')
const noteContent = template(alias, tagsCode, content)
const mdFiles = this.app.vault.getMarkdownFiles()
const existNote = mdFiles.find(file => file.name === title)
if (existNote) {
// 如果笔记已经存在,则打开它
open(existNote.path)
} else {
const realTitle = title.replace(/[\*\\\|\?"<>:]/g, '') // 删除无效符号
.replace(/\s/g, '%20') // 替换空格
const AdvancedURI = 'obsidian://advanced-uri?'
+ 'filepath='+encodeURIComponent(path+title)+'.md'
+ '&mode=new'
+ '&data='+encodeURIComponent(noteContent)
// 透过 Advanced URI 创建新笔记
open(AdvancedURI)
}
// 返回链接
// (${path+title.replace(/ /g, '%20')}.md)文档路径
tR += `![[${title || alias}]]`
}
%>