在Excalidraw中列出某笔记所有二级Heading

我拿 QuickAdd Capture 测试,应该 canvasFile = await app.vault.create(canvasPath, canvasJson) 就不会报错而是直接创建了。

基本配置参 QuickAdd JS & Templater JS 简介及相互修改“QuickAdd Capture 加载内部代码”。

js quickadd 代码,点击展开
const getFBP = path=> app.vault.getAbstractFileByPath(path), getFC = file=> app.metadataCache.getFileCache(file)
, file = app.workspace.getActiveFile(), cvsData = { nodes: [], edges: [] }
, lv = 2, width = 400, height = 400, space = 20, limit = 4, cvsPath = '未命名.canvas' // 参数行
switch (file.extension) {
case 'md': let heads = getFC(file).headings?.filter(p=> p.level <= lv).map(p=> `#${p.heading}`)
if (!heads) return; let x = 0, y = 0, n = 1, nodes = []
  for (let i = 1; i <= heads.length; i++) {
    let node = { id: '', type: 'file', file: file.path, subpath: '', x: 0, y: 0, width: width, height: height }
    node.subpath = heads[i-1]; node.id = String(i); node.x = x; node.y = y; x += width + space
    if (i >= limit * n) { y += height + space; x = 0; n += 1 }; nodes.push(node)
  }; cvsData.nodes = nodes; let cvsFile = getFBP(cvsPath), cvsJson = JSON.stringify(cvsData, null, 2)
  if (cvsFile) { app.vault.modify(cvsFile, cvsJson) } else cvsFile = await app.vault.create(cvsPath, cvsJson)
  app.workspace.activeLeaf.openFile(cvsFile); break
case 'canvas': app.workspace.activeLeaf.openFile(getFBP(JSON.parse(await app.vault.read(file)).nodes[0].file)); break
}

感谢分享 :hand_with_index_finger_and_thumb_crossed: 比心

更新:js quickadd 版本代码已和 #13 同步。

1 个赞