Convert text documents with Pandoc

From Parallel Library Services
Jump to navigation Jump to search

https://pandoc.org

Pandoc is a "universal document converter" which converts from one markup language to another.

In this guide, we try converting downloaded wiki pages (plain text in the .wiki format) to HTML files.

More extensive documentation is available in the official Pandoc manual or through the command line by typing

man pandoc

Getting started

You can find instructions for installation on [ the Pandoc website] for your particular operating system. Once you have pandoc installed, open a terminal session to use its command line interface.

Example 1: Convert an HTML string to Markdown

Enter a string of HTML and pipe it to pandoc:

echo "<h1>Hello Pandoc</h1><p>from html to markdown</p>" | pandoc -f html -t markdown

Example 2: Convert a MediaWiki file to HTML

  1. Save the content of a wiki page on to a plain-text file, example: page.wiki
  2. Convert:
pandoc page.wiki -f mediawiki -t html -o page.html

Common pandoc arguments

-f - option standing for “from”, is followed by the input format;

-t - option standing for “to”, is followed by the output format;

-s - option standing for “standalone”, produces output with an appropriate header and footer;

-o - option for file output;

page.wiki - MediaWiki input filename

Changing the default template

pandoc --from markdown --to html5 --print-default-template=html5 > template.html
pandoc --from markdown --to html5 --template template.html input.md -o output.html