Difference between revisions of "Convert text documents with Pandoc"

From Parallel Library Services
Jump to navigation Jump to search
Line 27: Line 27:
=== Common pandoc arguments===
=== Common pandoc arguments===


'''-f''' - option standing for “from”, is followed by the input format;
<code>-f</code> Option stands for “from”, which is followed by the input format;


'''-t''' - option standing for “to”, is followed by the output format;
<code>-t</code> Option stands for “to”, which is followed by the output format;


'''-s''' - option standing for “standalone”, produces output with an appropriate header and footer;
<code>-s</code> Option stands for “standalone”, produces output with an appropriate header and footer;


'''-o''' - option for file output;
<code>-o</code> Option for file output;


'''page.wiki''' - MediaWiki input filename
<code>page.wiki</code> MediaWiki input filename


== Changing the default template ==
== Changing the default template ==

Revision as of 14:45, 6 October 2021

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 stands for “from”, which is followed by the input format;

-t Option stands for “to”, which is followed by the output format;

-s Option stands 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