是否有任何markdown fork允许你引用其他文件,比如包含文件?具体来说,我想创建一个单独的markdown文件,其中包含我经常调用但不总是调用的链接(调用此B.md),然后当我通过引用链接到我正在写入的md文件(A.md)时,我希望它从另一个文件(B.md)中拉出链接,而不是从当前文件(A.md)的末尾。
当前回答
切换到asciidoc,这样你就不必使用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版本,具有相同的效果(不相同,但接近)。
事实上,你可以使用\input{filename}和\include{filename}这两个乳胶命令, 因为它支持几乎所有的html和latex语法。
但是要注意,包含的文件将被视为乳胶文件。但是您可以使用Pandox轻松地将您的markdown编译为latex。
如果您正在使用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())
```
另一个使用markdown-it和jQuery的基于html的客户端解决方案。下面是一个小的HTML包装作为主文档,它支持无限的markdown文件的include,但不支持嵌套include。在JS注释中提供了解释。错误处理略。
<script src="/markdown-it.min.js"></script>
<script src="/jquery-3.5.1.min.js"></script>
<script>
$(function() {
var mdit = window.markdownit();
mdit.options.html=true;
// Process all div elements of class include. Follow up with custom callback
$('div.include').each( function() {
var inc = $(this);
// Use contents between div tag as the file to be included from server
var filename = inc.html();
// Unable to intercept load() contents. post-process markdown rendering with callback
inc.load(filename, function () {
inc.html( mdit.render(this.innerHTML) );
});
});
})
</script>
</head>
<body>
<h1>Master Document </h1>
<h1>Section 1</h1>
<div class="include">sec_1.md</div>
<hr/>
<h1>Section 2</h1>
<div class="include">sec_2.md</div>
我在Mac OS x上使用标记2,它支持以下语法来包含其他文件。
<<[chapters/chapter1.md]
<<[chapters/chapter2.md]
<<[chapters/chapter3.md]
<<[chapters/chapter4.md]
遗憾的是,您不能将其提供给pandoc,因为它不理解语法。但是,编写一个脚本来剥离语法来构造一个pandoc命令行是非常容易的。
推荐文章
- 如何将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维基?