如何在另一个 markdown 文件中读取一个 markdown 文件?

How to read a markdown file in another markdown file?

我的目的是将许多用 markdown 编写的描述收集到一个 markdown 文件中,作为一篇综合文章。

例如./f1/a.md

This is the description for f1 project. 

并在./b.md

The introduction of f1 project is shown below, 
<!-- Contain of the a.md goes here -->

b.md 的预期结果应该是,

The introduction of f1 project is shown below, 
This is the description for f1 project. 

那么,如何实现这个功能呢?

Markdown 本身不支持文件包含,但根据您使用的 Markdown 处理器,您有几个选择:

  • 一些 Markdown 处理器支持多个输入文件。例如,Pandoc 可以接受多个输入文件并生成一个输出文件:

    pandoc -o output.html one.md two.md three.md
    
  • 您可以简单地将各个源文件以正确的顺序连接在一起,然后将该连接的文件用作不太灵活的解析器的单个输入:

    cat one.md two.md three.md > source.md
    markdown source.md
    

    如果您在 Windows,您可能需要将 cat 替换为 type

    根据您输入的复杂程度,您可能希望自动执行此过程。像 make 这样的工具可以帮助解决这个问题。