是否有任何markdown fork允许你引用其他文件,比如包含文件?具体来说,我想创建一个单独的markdown文件,其中包含我经常调用但不总是调用的链接(调用此B.md),然后当我通过引用链接到我正在写入的md文件(A.md)时,我希望它从另一个文件(B.md)中拉出链接,而不是从当前文件(A.md)的末尾。
当前回答
我认为我们最好采用一种新的文件包含语法(这样就不会搞砸了 代码块,我认为C风格的包含是完全错误的),我用Perl写了一个小工具,命名为cat.pl, 因为它的工作方式像cat (cat a.txt b.txt c.txt将合并三个 文件),但它合并文件的深度,而不是宽度。如何使用?
$ perl cat.pl <your file>
详细语法为:
递归包含文件:@include <-=path= 只包含一个:%include <-=path=
它可以正确地处理文件包含循环(如果a.txt <- b.txt, b.txt <- a.txt,那么您期望什么?)
例子:
a.txt:
a.txt
a <- b
@include <-=b.txt=
a.end
b.txt:
b.txt
b <- a
@include <-=a.txt=
b.end
Perl cat.pl .txt > c.txt
a.txt
a <- b
b.txt
b <- a
a.txt
a <- b
@include <-=b.txt= (note:won't include, because it will lead to infinite loop.)
a.end
b.end
a.end
更多例子请访问https://github.com/district10/cat/blob/master/tutorial_cat.pl_.md。
我还编写了一个Java版本,具有相同的效果(不相同,但接近)。
其他回答
就在最近,我在Node中写了一些类似的东西,叫做markdown-include,它允许你用C风格的语法包含markdown文件,像这样:
#include "my-file.md"
我相信这和你问的问题很吻合。我知道这是一个旧的,但我至少想更新它。
您可以将此包含在任何您希望的标记文件中。该文件还可以有更多的include, markdown-include将创建一个内部链接,并为您完成所有工作。
你可以通过npm下载它
npm install -g markdown-include
您实际上可以使用Markdown预处理器(MarkdownPP)。运行其他答案中的假设图书示例,您将创建.mdpp文件来表示您的章节。然后.mdpp文件可以使用!INCLUDE "路径/to/file。Mdpp指令,该指令在最终输出中用引用文件的内容递归地替换该指令。
chapters/preface.mdpp
chapters/introduction.mdpp
chapters/why_markdown_is_useful.mdpp
chapters/limitations_of_markdown.mdpp
chapters/conclusions.mdpp
然后需要一个索引。MDPP包含以下内容:
!INCLUDE "chapters/preface.mdpp"
!INCLUDE "chapters/introduction.mdpp"
!INCLUDE "chapters/why_markdown_is_useful.mdpp"
!INCLUDE "chapters/limitations_of_markdown.mdpp"
!INCLUDE "chapters/conclusions.mdpp"
要渲染你的书,你只需要在index.mdpp上运行预处理器:
$ markdown-pp.py index.mdpp mybook.md
别忘了看自述书。MarkdownPP存储库中的mdpp,用于展示适合大型文档项目的预处理器特性。
我只想提一下,在将输入文件输送到markdown_py之前,可以使用cat命令连接输入文件,这与pandoc处理多个输入文件的效果相同。
cat *.md | markdown_py > youroutputname.html
在我的Mac上,Python版本的Markdown与上面的pandoc示例几乎相同。
如果您正在使用pandoc进行markdown处理,除了在调用pandoc时使用多个输入markdown文件外,还没有本地解决方案(在https://github.com/jgm/pandoc/issues/553中讨论)。
然而,使用codebraid(实际上是为了包括自动生成的内容Markdown)可以实现这一点:
This is the content of the main Markdown file `main.md`.
Below this line, the content of the file `chapter01.md` is included:
```{.python .cb.run}
with open('chapter01.md') as fp:
print(fp.read())
```
This line is printed below the external content.
要将其转换为任何输出格式,可以使用如下代码:
codebraid pandoc main.md --to markdown
虽然codebraid可能被认为是“只是”包括外部Markdown文件,但它允许更多,例如包括来自外部来源的CSV或Excel表格:
Details are shown in the following table:
```{.python .cb.run}
import pandas as pd
table = pd.read_csv('table.csv')
print(table.to_markdown())
```
我认为我们最好采用一种新的文件包含语法(这样就不会搞砸了 代码块,我认为C风格的包含是完全错误的),我用Perl写了一个小工具,命名为cat.pl, 因为它的工作方式像cat (cat a.txt b.txt c.txt将合并三个 文件),但它合并文件的深度,而不是宽度。如何使用?
$ perl cat.pl <your file>
详细语法为:
递归包含文件:@include <-=path= 只包含一个:%include <-=path=
它可以正确地处理文件包含循环(如果a.txt <- b.txt, b.txt <- a.txt,那么您期望什么?)
例子:
a.txt:
a.txt
a <- b
@include <-=b.txt=
a.end
b.txt:
b.txt
b <- a
@include <-=a.txt=
b.end
Perl cat.pl .txt > c.txt
a.txt
a <- b
b.txt
b <- a
a.txt
a <- b
@include <-=b.txt= (note:won't include, because it will lead to infinite loop.)
a.end
b.end
a.end
更多例子请访问https://github.com/district10/cat/blob/master/tutorial_cat.pl_.md。
我还编写了一个Java版本,具有相同的效果(不相同,但接近)。
推荐文章
- 如何将LaTeX与Markdown混合?
- 乳胶渲染在README。md在Github上
- 在Markdown Jekyll中使用图像说明
- Slack Markdown链接没有解决
- 差异语法突出显示在Github Markdown
- 我如何创建一个文本框的笔记在markdown?
- 在Markdown中创建一个没有标题的表
- R -降价避免包装加载消息
- 在MarkDown中包含SVG(托管在GitHub上)
- 自动TOC在github风味markdown
- 使用pandoc从Markdown转换为PDF时设置空白大小
- 如何显示数学方程在一般github的markdown(不是github的博客)
- 使用Markdown的Sphinx而不是reST
- 降价和图像对齐
- 如何样式一个JSON块在Github维基?