Pandoc Document Converter
pandoc generates documents from various input and output formats.
Therefore it is used to convert between document formats as well.
Input, output and document formats…
- …input document specified with
--from…- …supports multiple Markdown variants
- …defaults to
-f markdownfor Pandoc’s Markdown
- …format defined with option
--to…defaults tohtml
# list all supported markdown variants
pandoc --list-input-formats | grep markdown- …files path defined with option
--output- …
--standaloneinclude header & footer for a given format - …
--cssadds CSS from a file to an HTML document template
- …
--table-of-contentsto generate a table of content
Configuration
Instead of using command-line options & arguments…
- …use a defaults file …in the form of a YAML file
- …option
-d,--defaults=…path to file, for examplepandox.yaml ${.}variable- …resolve to the directory containing the defaults file itself
- …only works in fields that expect file paths
#…to prefix comments
Example…
from: markdown+yaml_metadata_block
standalone: true
self-contained: true
toc: true
template: ${.}/_templates/page.html
css:
- ${.}/_templates/normalize.css
- ${.}/_templates/main.css
resource-path:
- .
- ${.}/imagesTemplates
Option --template for custom template documents…
- …
pandoc -D $formatto print the default template - …templates contain variables set
- …default variables
- …with option
-V,--variable - …YAML metadata block…
- …within the file header
- …dedicated file with option
--metadata-file - ..defaults file
metadata:ormetadata-file:
Headers & References
ATX-style heading…
- …
+auto_identifiersextension{#<label>}specific label for a header{-}will not be numbered
- …
+implicit_header_referencesextension- …behaves as if reference links have been defined for each heading
[heading]to reference an existing# heading
# A level-one heading {#level-1}
## A level-two heading {-}
### A level-three heading
...[level one](#level-1)
[A level-three heading]pandoc-secnos filter…
- …for numbering section references
- Source Code Repository, GitHub
- Enables…
- …cross-referencing syntax
{@sec:label}prefix for a unique reference+@sec:labeladds reference number mid sentence
Text Style
Use the common Markdown inline formatting for emphasis. Pandoc support in addition…
with*emphasis
with_emphasis
strong emphasis
strong emphasis
feasible, not feasable
deleted text
H2O is a liquid. 210 is 1024.
Markdown…
_with\*emphasis_
*with_emphasis*
__strong emphasis__
**strong emphasis**
feas*ible*, not feas*able*
~~deleted text~~
H~2~O is a liquid. 2^10^ is 1024.…HTML markup…
<em>with*emphasis<em>
<em>with_emphasis<em>
<strong>strong emphasis</strong>
<strong>strong emphasis</strong>
"feas"<em>ible</em>, not "feas"<em>able</em>
<del>deleted text</del>
"H"<sub>2</sub>"O is a liquid. 2<sup>10</sup>" is 1024"<mark> Element
Mark relevant text using the <mark> HTML element…
- …requires
bracketed_spansextension (enabled by default) - …append
{.mark}to a text enclosed with[...]
Text within a mark-element
Markdown…
[Text within a mark-element]{.mark}…HTML markup…
<mark>Text within a mark-element]</mark>…style sheet…
mark {
background-color: rgba(255, 238, 0, 0.38);
padding:0.25rem;
}<span> Element
Syntax highlight text (for example colors) with <span> elements…
Text in light
Text in medium
Text in dark
Markdown…
[Text in light]{.light}
[Text in medium]{.medium}
[Text in dark]{.dark}…HTML markup…
<span class="light">Text in light</span>
<span class="medium">Text in medium</span>
<span class="dark">Text in dark</span>…style sheet…
span.light {
color: rgba(232, 232, 232, 1);
}
span.medium {
color: rgba(204, 204, 204, 1);
}
span.dark {
color: rgba(114, 114, 114, 1);
}Code Fragments
<code> Element
TODO
<pre> Element
Fenced code blocks with backticks…
- …enables syntax high-lighting for code blocks
- …
pandoc --list-highlight-languageslists supported languages
Append language identifier to the backticks…
puts "Hello World"Markdown…
```ruby
puts "Hello World"
```Optional attributes in curly braces {...}…
- …
#labelto specify a reference identifierlabel - …
.syntaxto for a specific languagesyntaxto highlight - …
.numberLinesto enable line numbering
Markdown…
```{#label .sh .numberLines}
function _error() {
echo 1>&2 "$SCRIPT error: $@"
exit 1
}
```Extensions
- …
pandoc --list-extensionsto list extensions enabled by default - …configure with
--from markdown[+-]...- …enable
+EXTENSION - …disable
-EXTENSION
- …enable
Filters
Lua filters…
- Manipulate the Pandoc abstract syntax tree (AST)…
- …between parsing input and writing output
- …option
--lua-filter=to pass a Lua filter