如何使用 YAML 块指定 pandoc 的降价扩展?

How can I specify pandoc's markdown extensions using a YAML block?

背景

Pandoc 的 markdown 可以让你specify extensions了解你希望如何处理你的 markdown:

Markdown syntax extensions can be individually enabled or disabled by appending +EXTENSION or -EXTENSION to the format name. So, for example, markdown_strict+footnotes+definition_lists is strict markdown with footnotes and definition lists enabled, and markdown-pipe_tables+hard_line_breaks is pandoc’s markdown without pipe tables and with hard line breaks.

我的具体问题

对于给定的 pandoc 转换,例如,我在源代码中使用 grid tables

pandoc myReport.md --from markdown+pipe_tables --to latex -o myReport.pdf

如何编写 pandoc YAML block 来完成同样的事情(指定我的源包含网格表?)

我的问题的概括形式

如何使用 pandoc YAML 打开和关闭扩展?

我认为没有完全回答我的问题的 Stack Overflow 问题

也可能没有办法做到这一点

pandoc 并非旨在让您在 YAML 中指定这些扩展名。虽然,我希望是这样。

您可以使用 Markdown 变体在 Rmarkdown 文档中执行此操作。本质上,您将扩展名输入 .Rmd 文件开头的 YAML header 块中的 variant 选项。

例如,要使用网格表,您的 YAML header 块中有这样的内容:

---
title: "Habits"
author: John Doe
date: March 22, 2005
output: md_document
    variant: markdown+grid_tables
---

然后您可以直接在 pandoc 中编译为 PDF,方法是在命令行中键入以下内容:

pandoc yourfile.md -o yourfile.pdf

有关 RStudio 中降价变体的更多信息:http://rmarkdown.rstudio.com/markdown_document_format.html#markdown_variants

有关 RStudio markdown/Rmarkdown 中 Pandoc 扩展的更多信息: http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html#pandoc_markdown

您可以使用每个输出格式中包含的 md_extension 参数在 yaml header 中指定 pandoc markdown 扩展。

---
title: "Your title"
output:
  pdf_document:
    md_extensions: +grid_tables
---

这将激活扩展。有关详细信息,请参阅 Rmarkdown Definitive Guide

在 Rmarkdown 范围之外,您可以将 Pandocomatic to it, or Paru 用于 Ruby。

---
 title: My first pandocomatic-converted document
 pandocomatic_:
     pandoc:
         from: markdown+footnotes
         to: html
 ...

正如 Merchako 指出的那样,接受的答案特定于 rmarkdown。例如,在 Atom md_extensions: 中不起作用。

更通用的方法是将扩展放在命令行选项中。这个例子工作正常:

----
title: "Word document with emojis"
author: me
date: June 9, 2021
output:
  word_document:
    pandoc_args: ["--standalone", "--from=markdown+emoji"]
----

对于在 2021 年或之后遇到这个问题的人来说,这可以在没有 Rmarkdown 的情况下完成。您可以指定一个 YAML“默认”文件,它基本上包括您可能想要配置的任何内容。

为了达到 OP 的要求,您只需

from: markdown+pipe_tables

在defaults文件里,编译的时候传进去。 您还可以指定输入和输出文件,这样您就可以得到非常少的命令 pandoc --defaults=defaults.yaml 让它为你处理剩下的事情。有关更多信息,请参阅 https://pandoc.org/MANUAL.html#extensions