如何用文件内容替换对文件的引用?

问题描述 投票:0回答:1

假设我有一个目录,其中包含两个 Markdown 文件

a note.md
another one.md

a note.md
包含

Here is a description of an idea.

![[another one.md]]

another one.md
包含

Here is another idea related to it.

我正在 bash 中寻找一个可以实现的命令

  1. 采取
    a note.md
  2. ![[another one.md]]
    中的引用
    a note.md
    替换为
    another one.md
    中的实际内容,并且
  3. 返回结果(以便我可以将其通过管道传递给 Pandoc)。

此示例中的输出将包含

Here is a description of an idea.

Here is another idea related to it.

为什么? Obsidian Markdown 笔记应用程序允许使用 ![[]] 将文件内容

嵌入到 Markdown 文件中,如上所述。但是,当使用 Pandoc 转换此类文件时,引用将被视为文本。所以我正在寻找一种在 Pandoc 转换之前添加嵌入内容的方法。

bash markdown pandoc obsidian
1个回答
0
投票
如果你会使用perl :

perl -pe 's/!\[\[(.*?)]]/`cat "$1"`/eg' "a note.md"
    
© www.soinside.com 2019 - 2024. All rights reserved.