Pandoc-在生成目录之前插入页面 [英] Pandoc - Inserting pages before generated Table of Contents

查看:335
本文介绍了Pandoc-在生成目录之前插入页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在和Pandoc玩耍.

I've been playing around with Pandoc.

总有没有在生成的目录之前插入页面?

Is there anyway to insert pages before the generated Table of Contents?

例如:

  • 标题页
  • 插入自定义页面001
  • 插入自定义页面002
  • (生成的)目录

非常感谢!

推荐答案

对于此答案,我将假设您正在生成markdown,尽管其他文件格式的处理过程也相同.

For this answer, I'm going to assume you are generating markdown, though the process is the same for other file formats as well.

关键见解是Pandoc使用模板确定最终放置位置.它具有默认模板,如果您对它们进行了修改,则可以更改各节的顺序.

The key insight is that Pandoc uses templates to determine the final placement. It has default templates and if you modify them, you can change the order of sections.

  1. 找到默认模板

  1. Find the default template

> 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$

下一步将不需要此功能,但是如果您想知道这些文件的存放位置,则可以请求一个无意义的文件类型(尽管我确定有更好的方法):

You won't need this for the next step, but if you are curious where these files live, asking for a nonsense file type works (though I'm sure there is a better way):

> pandoc -D nonsense
pandoc: Could not find data file /usr/local/.../templates/default.nonsense

  • 复制并修改默认模板

  • Copy and modify the default template

    > pandoc -D markdown > modified.markdown
    

    使用您喜欢的文本编辑器,您可以打开Modifyed.markdown将$body$放在$toc$之前.

    Using your favorite text editor, you can open modified.markdown to put the $body$ before the $toc$.

    $body$
    $if(toc)$
    $toc$
    $endif$
    

  • 使用修改后的模板

  • Use the modified template

    > pandoc --template modified.markdown <... rest of your command ...>
    

  • 这篇关于Pandoc-在生成目录之前插入页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆