Difference between revisions of "Convert text documents with Pandoc"
Line 27: | Line 27: | ||
=== Common pandoc arguments=== | === Common pandoc arguments=== | ||
<code>-f</code> Option | <code>-f</code> or <code>--from</code> Option which is followed by the input format; | ||
<code>-t</code> Option | <code>-t</code> or <code>--to</code> Option which is followed by the output format; | ||
<code>-s</code> Option | <code>-s</code> or <code>--standalone</code> Option produces output with an appropriate header and footer; | ||
<code>-o</code> Option for file output; | <code>-o</code> or <code>--output</code> Option for file output; | ||
<code>page.wiki</code> MediaWiki input filename | <code>page.wiki</code> MediaWiki input filename |
Revision as of 14:47, 6 October 2021
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
- Save the content of a wiki page on to a plain-text file, example:
page.wiki
- Convert:
pandoc page.wiki -f mediawiki -t html -o page.html
Common pandoc arguments
-f
or --from
Option which is followed by the input format;
-t
or --to
Option which is followed by the output format;
-s
or --standalone
Option produces output with an appropriate header and footer;
-o
or --output
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