是否有任何markdown fork允许你引用其他文件,比如包含文件?具体来说,我想创建一个单独的markdown文件,其中包含我经常调用但不总是调用的链接(调用此B.md),然后当我通过引用链接到我正在写入的md文件(A.md)时,我希望它从另一个文件(B.md)中拉出链接,而不是从当前文件(A.md)的末尾。
当前回答
如果您正在使用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())
```
其他回答
恕我直言,你可以通过连接你的输入得到你的结果*。Md文件如下:
$ pandoc -s -o outputDoc.pdf inputDoc1.md inputDoc2.md outputDoc3.md
您实际上可以使用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,用于展示适合大型文档项目的预处理器特性。
我在Mac OS x上使用标记2,它支持以下语法来包含其他文件。
<<[chapters/chapter1.md]
<<[chapters/chapter2.md]
<<[chapters/chapter3.md]
<<[chapters/chapter4.md]
遗憾的是,您不能将其提供给pandoc,因为它不理解语法。但是,编写一个脚本来剥离语法来构造一个pandoc命令行是非常容易的。
我的解是用m4。大多数平台都支持它,并且包含在binutils包中。
首先在文件中包含一个宏changequote(),以将引用字符更改为您喜欢的字符(默认为“)。处理文件时将删除宏。
changequote(`{{', `}}')
include({{other_file}})
在命令行中:
m4 -I./dir_containing_other_file/ input.md > _tmp.md
pandoc -o output.html _tmp.md
另一个使用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>
推荐文章
- 如何将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维基?