How can I specify pandoc's markdown extensions

2020-02-26 06:55发布

Background

Pandoc's markdown lets you specify extensions for how you would like your markdown to be handled:

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.

My specific question

For a given pandoc conversion where, say, I use grid tables in my source:

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

How can I write a pandoc YAML block to accomplish the same thing (specifying that my source contains grid tables?)

A generalized form of my question

How can I turn extensions on and off using pandoc YAML?

Stack Overflow Questions that I don't think completely answer my question

There may also not be a way to do this

It's always possible that pandoc isn't designed to let you specify those extensions in the YAML. Although, I'm hoping it is.

3条回答
再贱就再见
2楼-- · 2020-02-26 07:17

Outside Rmarkdown scope, you can use Pandocomatic to it, or Paru for Ruby.

---
 title: My first pandocomatic-converted document
 pandocomatic_:
     pandoc:
         from: markdown+footnotes
         to: html
 ...
查看更多
Root(大扎)
3楼-- · 2020-02-26 07:19

You can use Markdown Variants to do this in an Rmarkdown document. Essentially, you enter your extensions into a variant option in the YAML header block at the start of the your .Rmd file.

For example, to use grid tables, you have something like this in your YAML header block:

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

Then you can compile to a PDF directly in pandoc by typing in your command line something like:

pandoc yourfile.md -o yourfile.pdf

For more information on markdown variants in RStudio: http://rmarkdown.rstudio.com/markdown_document_format.html#markdown_variants

For more information on Pandoc extensions in markdown/Rmarkdown in RStudio: http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html#pandoc_markdown

查看更多
我想做一个坏孩纸
4楼-- · 2020-02-26 07:36

You can specify pandoc markdown extension in the yaml header using md_extension argument included in each output format.

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

This will activate the extension. See Rmarkdown Definitive Guide for details.

查看更多
登录 后发表回答