A universal document converter and its ecosystem
Yasin Raies
09.01.1984
Pandoc is a free and open-source software document converter created by John MacFarlane.
Supported Formats:
In
commonmark, creole, docbook, docx, epub, fb2, gfm (GitHub-Flavored Markdown), haddock, html, jats, json, latex, markdown (Pandoc’s Markdown), markdown_mmd, markdown_phpextra, markdown_strict, mediawiki, man, muse, native, odt, opml, org, rst, t2t, textile, tikiwiki, twiki, vimwiki
Out
asciidoc, beamer, commonmark, context, docbook or docbook4, docbook5, docx, dokuwiki, epub or epub3, epub2, fb2, gfm (GitHub-Flavored Markdown), haddock, html or html5 (HTML, i.e. HTML5/XHTML polyglot markup), html4, icml, jats, json, latex, man, markdown (Pandoc’s Markdown), markdown_mmd, markdown_phpextra, markdown_strict, mediawiki, ms, muse, native, odt, opml, opendocument, org, plain, pptx, rst, rtf, texinfo, textile, slideous, slidy, dzslides, revealjs, s5, tei, zimwiki
---
title: Pandoc
subtitle: A universal document converter and its ecosystem
author: Yasin Raies
theme: white
center: true
width: 1280
height: 720
date: 09.01.2019
---
In | Out |
---|---|
text |
text |
*emphasis* |
emphasis |
**strong** |
strong |
~~strike~~ |
|
S~ub~ S^uper^ |
Sub Super |
$$e^{\pi i} + 1 = 0$$ |
eπi + 1 = 0 |
| **Ingredients**:
| 0.5 Lime
| 5 *tbsp* Sugar
| 350 *ml* Ginger Ale
| Crusehd Ice
```java
while(true){
doTalk();
}
```
This is a blockquote
> This is a blockquote
I) one
3. two
7. three
I) five
- some
+ things
+ are
- weird
Term 1
~ Definition 1
Term 2
~ Definition 2a
~ Definition 2b
See (2).
(@) This is a numbered example.
(@ex) This example can be referenced.
See (@ex).
Right | Left | Center | Default |
---|---|---|---|
12 | 12 | 12 | 12 |
Fruit | Price | Advantages |
---|---|---|
Bananas | $1.34 |
|
Right | Left | Default | Center |
---|---|---|---|
12 | 12 | 12 | 12 |
Right Left Center Default
------- ------ ---------- -------
12 12 12 12
+---------------+---------------+--------------------+
| Fruit | Price | Advantages |
+===============+===============+====================+
| Bananas | $1.34 | - built-in wrapper |
| | | - bright color |
+---------------+---------------+--------------------+
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
| 12 | 12 | 12 | 12 |
This is a div.
### Headers, Rules and Divs {#headers-and-stuff}
::: {style="color:red"}
This is a div.
:::
Reader ⇒ Filters ⇒ Writer ⇒ Template
Pandoc has some parameters:
pandoc [OPTIONS] [FILES]
-f FORMAT, -r FORMAT --from=FORMAT, --read=FORMAT
-t FORMAT, -w FORMAT --to=FORMAT, --write=FORMAT
-o FILE --output=FILE
--data-dir=DIRECTORY
--base-header-level=NUMBER
--strip-empty-paragraphs
--indented-code-classes=STRING
-F PROGRAM --filter=PROGRAM
--lua-filter=SCRIPTPATH
-Pandoc is a free and open-source software document converterp --preserve-tabs
--tab-stop=NUMBER
--track-changes=accept|reject|all
--file-scope
--extract-media=PATH
-s --standalone
--template=FILE
-M KEY[:VALUE] --metadata=KEY[:VALUE]
-V KEY[:VALUE] --variable=KEY[:VALUE]
-D FORMAT --print-default-template=FORMAT
--print-default-data-file=FILE
--print-highlight-style=STYLE|FILE
--dpi=NUMBER
--eol=crlf|lf|native
--wrap=auto|none|preserve
--columns=NUMBER
--strip-comments
--toc, --table-of-contents
--toc-depth=NUMBER
--no-highlight
--highlight-style=STYLE|FILE
--syntax-definition=FILE
-H FILE --include-in-header=FILE
-B FILE --include-before-body=FILE
-A FILE --include-after-body=FILE
--resource-path=SEARCHPATH
--request-header=NAME:VALUE
--self-contained
--html-q-tags
--ascii
--reference-links
--reference-location=block|section|document
--atx-headers
--top-level-division=section|chapter|part
-N --number-sections
--number-offset=NUMBERS
--listings
-i --incremental
--slide-level=NUMBER
--section-divs
--default-image-extension=extension
--email-obfuscation=none|javascript|references
--id-prefix=STRING
-T STRING --title-prefix=STRING
-c URL --css=URL
--reference-doc=FILE
--epub-subdirectory=DIRNAME
--epub-cover-image=FILE
--epub-metadata=FILE
--epub-embed-font=FILE
--epub-chapter-level=NUMBER
--pdf-engine=PROGRAM
--pdf-engine-opt=STRING
--bibliography=FILE
--csl=FILE
--citation-abbreviations=FILE
--natbib
--biblatex
--mathml
--webtex[=URL]
--mathjax[=URL]
--katex[=URL]
--gladtex
--abbreviations=FILE
--trace
--dump-args
--ignore-args
--verbose
--quiet
--fail-if-warnings
--log=FILE
--bash-completion
--list-input-formats
--list-output-formats
--list-extensions[=FORMAT]
--list-highlight-languages
--list-highlight-styles
-v --version
-h --help
Compiling Markdown to HTML:
pandoc --standalone --from markdown --to html -o Out.html In.txt
Compiling this talk:
echo recompiling HTML
pandoc -f markdown+emoji -s --toc --toc-depth=2 --css gitlab.css -o Vortrag.html Vortrag.md
echo recompiling Reveal
pandoc -f markdown+emoji -s -t revealjs -o Vortrag_reveal.html -V revealjs-url=reveal.js-3.7.0 --slide-level 2 Vortrag.md
Variables filled into templates are taken from metadata or commandline-arguments.
They are referenced by $varname$
.
To check if a variable is set use $if(var)$
with $endif$
.
Iteration is also possible:
$for(var)$$var$$sep$, $endfor$
HTML Template:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang$" xml:lang="$lang$"$if(dir)$ dir="$dir$"$endif$>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
$for(author-meta)$
<meta name="author" content="$author-meta$" />
$endfor$
$if(date-meta)$
<meta name="dcterms.date" content="$date-meta$" />
$endif$
$if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
$endif$
<title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
$if(quotes)$
q { quotes: "“" "”" "‘" "’"; }
$endif$
</style>
$if(highlighting-css)$
<style type="text/css">
$highlighting-css$
</style>
$endif$
$for(css)$
<link rel="stylesheet" href="$css$" />
$endfor$
$if(math)$
$math$
$endif$
$for(header-includes)$
$header-includes$
$endfor$
</head>
<body>
$for(include-before)$
$include-before$
$endfor$
$if(title)$
<header>
<h1 class="title">$title$</h1>
$if(subtitle)$
<p class="subtitle">$subtitle$</p>
$endif$
$for(author)$
<p class="author">$author$</p>
$endfor$
$if(date)$
<p class="date">$date$</p>
$endif$
</header>
$endif$
$if(toc)$
<nav id="$idprefix$TOC">
$table-of-contents$
</nav>
$endif$
$body$
$for(include-after)$
$include-after$
$endfor$
</body> </html>
Readers and writers allow for fine-grained customization by use of extensions.
Enabling emoji (👍) in markdown:
pandoc -f markdown+emoji in.md
Convert tables to multiline:
pandoc -f markdown -t markdown-grid_tables-simple_tables
+multiline_tables-pipe_tables
Filters allow for even more individualisation and actual extensibility by piping the native representation through a program which outputs the modified native code.
import Text.Pandoc.JSON
doInclude :: Block -> IO Block
doInclude cb@(CodeBlock (id, classes, namevals) contents) =
case lookup "include" namevals of
Just f -> return . (CodeBlock (id, classes, namevals)) =<< readFile f
Nothing -> return cb
doInclude x = return x
main :: IO ()
main = toJSONFilter doInclude
~~~~ {include="README"}
this will be replaced by contents of README
~~~~
data Pandoc = Pandoc Meta [Block]
data Block
= Plain [Inline]
| Para [Inline]
| LineBlock [[Inline]]
| CodeBlock Attr String
| RawBlock Format String
| BlockQuote [Block]
| OrderedList ListAttributes [[Block]]
| BulletList [[Block]]
| DefinitionList [([Inline],[[Block]])]
| Header Int Attr [Inline]
| HorizontalRule
| Table [Inline] [Alignment] [Double] [TableCell] [[TableCell]]
| Div Attr [Block]
| Null
data Inline
= Str String
| Emph [Inline]
| Strong [Inline]
| Strikeout [Inline]
| Superscript [Inline]
| Subscript [Inline]
| SmallCaps [Inline]
| Quoted QuoteType [Inline]
| Cite [Citation] [Inline]
| Code Attr String
| Space
| SoftBreak
| LineBreak
| Math MathType String
| RawInline Format String
| Link Attr [Inline] Target
| Image Attr [Inline] Target
| Note [Block]
| Span Attr [Inline]
All available options do work, but each require individual, manual fixing.
Python, Ruby, Scala, JavaScript, Perl, Pascal, C, R
E-Book generation scripts, Journal, PhD theses, lecture notes, resume/CV, Bootstrap & HTML
Neither is Pandoc made to replace Latex (-Beamer), nor is it the painless solution to everything.
There are many annoyances:
Pandoc should in my Opinion be used for:
Slides are possible and good for some poeple if you settle on one format.
Demo!
Relevant websites: