是否有任何markdown fork允许你引用其他文件,比如包含文件?具体来说,我想创建一个单独的markdown文件,其中包含我经常调用但不总是调用的链接(调用此B.md),然后当我通过引用链接到我正在写入的md文件(A.md)时,我希望它从另一个文件(B.md)中拉出链接,而不是从当前文件(A.md)的末尾。
当前回答
受@Oliver Matthews回答的启发,你可以创建一个perl脚本,递归地查找语法!md]],并将其替换为B.md content
让我们创建名为parsem .sh的递归脚本
#!/usr/bin/env bash
perl -ne 's#^!\[\[(.+?)\]\].*#`'$0' "$1"`#e;print' "$@"
像这样使用它
./parseMd.sh A.md > result.md
使用它和pandoc一起导出为pdf
pandoc <(./parseMd.sh A.md) -o result.pdf
其他回答
我知道这是一个老问题,但我还没有看到任何关于这个效果的答案:本质上,如果你使用markdown和pandoc将你的文件转换为pdf,在页面顶部的yaml数据中,你可以包括这样的东西:
---
header-includes:
- \usepackage{pdfpages}
output: pdf_document
---
\includepdf{/path/to/pdf/document.pdf}
# Section
Blah blah
## Section
Blah blah
由于pandoc使用latex来转换所有文档,因此包含头的部分调用pdfpages包。然后,当你包含\includepdf{/path/to/pdf/document.pdf}时,它将插入该文档中包含的内容。此外,您还可以通过这种方式包含多个pdf文件。
作为一个有趣的奖励,这只是因为我经常使用markdown,如果您想包括markdown以外的文件,例如latex文件。我稍微修改了一下这个答案。假设你有一个markdown1.md文件:
---
title: Something meaning full
author: Talking head
---
还有两个额外的乳胶文件document1,看起来像这样:
\section{Section}
Profundity.
\subsection{Section}
Razor's edge.
另一个document2.tex,看起来像这样:
\section{Section
Glah
\subsection{Section}
Balh Balh
假设您想将document1.tex和document2.tex包含到markdown1中。Md,你只要这样做,就可以降低1。Md
---
title: Something meaning full
author: Talking head
---
\input{/path/to/document1}
\input{/path/to/document2}
用pandoc检查一下。
在终端pandoc markdown1。Md -o markdown1.pdf
你的最终文档看起来是这样的:
有意义的事
的头部特写
部分
深刻。
部分
剃刀边缘。
部分
Glah
部分
Balh Balh
我认为我们最好采用一种新的文件包含语法(这样就不会搞砸了 代码块,我认为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
我的解是用m4。大多数平台都支持它,并且包含在binutils包中。
首先在文件中包含一个宏changequote(),以将引用字符更改为您喜欢的字符(默认为“)。处理文件时将删除宏。
changequote(`{{', `}}')
include({{other_file}})
在命令行中:
m4 -I./dir_containing_other_file/ input.md > _tmp.md
pandoc -o output.html _tmp.md
Multimarkdown天生就有这个。它称之为文件传输:
{{some_other_file.txt}}
这就是一切。名字很奇怪,但符合所有条件。
推荐文章
- 如何将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维基?