Pandoc: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 1: Line 1:
[[File:pandoc_diagram.jpg|400px|right]]
[[File:pandoc_diagram.jpg|400px|right|thumb]]
 
A universal document converter - converts from one markup language onto another


https://pandoc.org/
https://pandoc.org/


Use: convert downloaded wiki pages onto HTML files
You can use Pandoc to generate PDF's directly from other '''document formats''', like Markdown, wikitext, Libre Office or PDF.  
 
extensive documentation in [https://pandoc.org/MANUAL.html Pandoc’s Manual] or <code>man pandoc</code>
 


Pandoc is an universal document converter - converts from one markup language onto another


=== pandoc example1: convert HTML string to markdown ===
'''Extensive documentation''': [https://pandoc.org/MANUAL.html Pandoc’s Manual] or <code>man pandoc</code>


<pre>echo "<h1>Hello Pandoc</h1><p>from html to markdown</p>" | pandoc -f html -t markdown</pre>
==Pandoc common arguments==
 
=== pandoc example2: mediawiki file to HTML===
* Save the content of a wiki page on to a plain-text file, example: <code>page.wiki</code>
* convert:
<code>pandoc page.wiki -f mediawiki -t html -o page.html</code>
 
 
===Pandoc common arguments===


'''-f''' - option standing for “from”, is followed by the input format;
'''-f''' - option standing for “from”, is followed by the input format;
Line 35: Line 23:
== changing the default template ==
== changing the default template ==


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


==PDF==
A range of '''PDF engines''' are supported at the moment, including <code>Paged.js</code>, <code>weasyprint</code> and <code>LaTeX</code>. You need to select the one of choice using the <code>--pdf-engine</code> option, and have the PDF engine installed on your computer.
You can follow this page for instructions: https://pandoc.org/MANUAL.html#creating-a-pdf
==Examples==
===Convert HTML string to markdown ===
<pre>echo "<h1>Hello Pandoc</h1><p>from html to markdown</p>" | pandoc -f html -t markdown</pre>
===Mediawiki file to HTML===
* Save the content of a wiki page on to a plain-text file, example: <code>page.wiki</code>
* convert:
<code>pandoc page.wiki -f mediawiki -t html -o page.html</code>




[[Category:Cookbook]]
[[Category:Cookbook]]
[[Category:PagedMedia]]

Revision as of 08:26, 3 October 2023

Pandoc diagram.jpg

https://pandoc.org/

You can use Pandoc to generate PDF's directly from other document formats, like Markdown, wikitext, Libre Office or PDF.

Pandoc is an universal document converter - converts from one markup language onto another

Extensive documentation: Pandoc’s Manual or man pandoc

Pandoc common 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 html --print-default-template=html5 > template.html
$ pandoc --from markdown --to html --template template.html input.md -o output.html

PDF

A range of PDF engines are supported at the moment, including Paged.js, weasyprint and LaTeX. You need to select the one of choice using the --pdf-engine option, and have the PDF engine installed on your computer.

You can follow this page for instructions: https://pandoc.org/MANUAL.html#creating-a-pdf

Examples

Convert HTML string to markdown

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

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