Convert text documents with Pandoc
Revision as of 13:30, 6 October 2021 by Simon (talk | contribs) (→pandoc example2: mediawiki file to HTML)
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 at Pandoc’s Manual or through the command line by typing
man pandoc
Example 1: Convert an HTML string to Markdown
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 - 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