And*_*ink 14 markdown tableofcontents epub pandoc
我一直在玩Pandoc.
无论如何在生成的目录之前插入页面?
例如:
提前谢谢了!
小智 10
我猜你想创建一个带有标题页或标题信息的 HTML 文件。解决方法是分多个步骤完成。
首先,您将标题页与任何其他页面一起编译为一个 html。
$ pandoc .\01_HEADER.markdown -o header.html
Run Code Online (Sandbox Code Playgroud)
然后在正文之前包含该 header.html:
$ pandoc -s -S --toc -B .\header.html .\02_Document.markdown -o complete_doc.html
Run Code Online (Sandbox Code Playgroud)
完毕。
pandoc 帮助说明有可能使多部分文档成为可能,-B 和 -H 都可以工作,但我认为 -B 在我的情况下更正确。
-H FILENAME --include-in-header=FILENAME
-B FILENAME --include-before-body=FILENAME
-A FILENAME --include-after-body=FILENAME
Run Code Online (Sandbox Code Playgroud)
就我而言,我使用样式表进行操作并获得完美的文档:
$ pandoc -s -S -c .\res\github-pandoc.css .\01_HEADER.markdown -o header.html
$ pandoc -s -S --toc --toc-depth=2 -c .\res\github-pandoc.css -B .\header.html .\02_Document.markdown -o complete_document.html
Run Code Online (Sandbox Code Playgroud)
使用您可以在输出中观察到的include-before标签pandoc --print-default-template=markdown
---
title: My Way
toc: true
include-before: |
See these lines
Come __before__ the [toc](/dev/null)
---
# I've lived a life that's full
# I traveled each and every highway
# But more, much more than this
# I did it my way
Run Code Online (Sandbox Code Playgroud)
对于这个答案,我将假设您正在生成markdown,尽管其他文件格式的过程也相同.
关键的见解是Pandoc使用模板来确定最终的位置.它具有默认模板,如果您修改它们,则可以更改部分的顺序.
找到默认模板
> pandoc -D markdown
$if(titleblock)$
$titleblock$
$endif$
$for(header-includes)$
$header-includes$
$endfor$
$for(include-before)$
$include-before$
$endfor$
$if(toc)$
$toc$
$endif$
$body$
$for(include-after)$
$include-after$
$endfor$
Run Code Online (Sandbox Code Playgroud)
下一步你不需要这个,但如果你好奇这些文件存在的地方,要求一个无意义的文件类型可行(虽然我确信有更好的方法):
> pandoc -D nonsense
pandoc: Could not find data file /usr/local/.../templates/default.nonsense
Run Code Online (Sandbox Code Playgroud)复制并修改默认模板
> pandoc -D markdown > modified.markdown
Run Code Online (Sandbox Code Playgroud)
使用您喜欢的文本编辑器,您可以打开modified.markdown来放置$body$之前的$toc$.
$body$
$if(toc)$
$toc$
$endif$
Run Code Online (Sandbox Code Playgroud)使用修改后的模板
> pandoc --template modified.markdown <... rest of your command ...>
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
7195 次 |
| 最近记录: |