Top Related Projects
A Python implementation of John Gruber’s Markdown with Extension support.
CommonMark spec, with reference implementations in C and JavaScript
Blackfriday: a markdown processor for Go
Determines which markup library to use to render a content file (e.g. README) on GitHub
A bidirectional Markdown to HTML to Markdown converter written in Javascript
:gem: A fast, open source text processor and publishing toolchain, written in Ruby, for converting AsciiDoc content to HTML 5, DocBook 5, and other formats.
Quick Overview
Pandoc is a universal document converter that can convert between numerous markup and document formats. It's particularly useful for converting between different flavors of Markdown, HTML, LaTeX, and various word processing formats. Pandoc is highly extensible and can be used as a library in multiple programming languages.
Pros
- Supports a wide range of input and output formats
- Highly customizable with options for fine-tuning output
- Can be used as a command-line tool or as a library in various programming languages
- Active development and community support
Cons
- Learning curve can be steep for advanced usage
- Some conversions may not preserve all formatting perfectly
- Large installation size due to comprehensive feature set
- Performance can be slow for very large documents
Code Examples
- Basic Markdown to HTML conversion:
import Text.Pandoc
main :: IO ()
main = do
let markdown = "# Hello, Pandoc!\nThis is a **test**."
result <- runIO $ readMarkdown def markdown >>= writeHtml5String def
putStrLn $ either show id result
- Converting a file from Markdown to PDF:
import Text.Pandoc
import qualified Data.Text.IO as TIO
main :: IO ()
main = do
input <- TIO.readFile "input.md"
result <- runIO $ do
doc <- readMarkdown def input
writeLaTeX def doc >>= writeFileLaTeX def "output.pdf"
print result
- Custom writer example:
import Text.Pandoc
import Text.Pandoc.Writers.Custom
main :: IO ()
main = do
let markdown = "# Title\n\nParagraph with *emphasis*."
result <- runIO $ do
doc <- readMarkdown def markdown
writeCustom def { writerRawHtml = True } customWriter doc
putStrLn $ either show id result
customWriter :: [Block] -> String
customWriter = concatMap blockToHtml
blockToHtml :: Block -> String
blockToHtml (Header 1 _ inlines) = "<h1>" ++ inlinesToHtml inlines ++ "</h1>"
blockToHtml (Para inlines) = "<p>" ++ inlinesToHtml inlines ++ "</p>"
blockToHtml _ = ""
inlinesToHtml :: [Inline] -> String
inlinesToHtml = concatMap inlineToHtml
inlineToHtml :: Inline -> String
inlineToHtml (Str s) = s
inlineToHtml (Emph inlines) = "<em>" ++ inlinesToHtml inlines ++ "</em>"
inlineToHtml _ = ""
Getting Started
To use Pandoc as a Haskell library:
- Install Pandoc:
cabal install pandoc
- In your Haskell file, import Pandoc:
import Text.Pandoc
main :: IO ()
main = do
let markdown = "# Hello, Pandoc!"
result <- runIO $ readMarkdown def markdown >>= writeHtml5String def
putStrLn $ either show id result
- Compile and run your Haskell program.
For command-line usage, install Pandoc and use it directly in the terminal:
pandoc input.md -o output.html
Competitor Comparisons
A Python implementation of John Gruber’s Markdown with Extension support.
Pros of Python-Markdown
- Lightweight and focused specifically on Markdown processing
- Easy to integrate into Python projects
- Extensible through custom extensions
Cons of Python-Markdown
- Limited to Markdown input and HTML output
- Fewer supported input/output formats compared to Pandoc
- Less comprehensive documentation and community support
Code Comparison
Python-Markdown:
import markdown
html = markdown.markdown(text)
Pandoc:
import Text.Pandoc
result <- runIO $ readMarkdown def text >>= writeHTML5 def
Python-Markdown focuses on simplicity and ease of use within Python ecosystems, while Pandoc offers a more comprehensive document conversion solution with support for numerous formats. Python-Markdown is ideal for projects requiring straightforward Markdown-to-HTML conversion, whereas Pandoc excels in complex document transformations across various formats.
Python-Markdown's lightweight nature makes it quicker to set up and use in Python projects, but it lacks the versatility of Pandoc's extensive format support. Pandoc's broader feature set comes with a steeper learning curve and potentially more complex integration, especially in Python-centric environments.
CommonMark spec, with reference implementations in C and JavaScript
Pros of CommonMark
- Focused specifically on standardizing Markdown syntax
- Provides a clear, unambiguous specification for Markdown
- Offers a test suite for implementers to ensure compliance
Cons of CommonMark
- Limited in scope compared to Pandoc's broader document conversion capabilities
- Less flexible for handling various input and output formats
- Lacks advanced features like citation support and custom extensions
Code Comparison
CommonMark (JavaScript implementation):
var reader = new commonmark.Parser();
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse("Hello *world*");
var result = writer.render(parsed);
Pandoc (Haskell):
import Text.Pandoc
import Text.Pandoc.PDF
main :: IO ()
main = runIOorExplode $ do
doc <- readMarkdown def "Hello *world*"
writeHtml5String def doc
Summary
CommonMark focuses on standardizing Markdown syntax, providing a clear specification and test suite. Pandoc, on the other hand, offers a more comprehensive document conversion tool with support for multiple formats and advanced features. CommonMark is ideal for those seeking a consistent Markdown implementation, while Pandoc is better suited for complex document processing tasks across various formats.
Blackfriday: a markdown processor for Go
Pros of Blackfriday
- Written in Go, offering better performance for Go-based applications
- Lightweight and focused specifically on Markdown parsing
- Easier to integrate into Go projects with minimal dependencies
Cons of Blackfriday
- Limited to Markdown input and HTML output
- Fewer features and customization options compared to Pandoc
- Less active development and community support
Code Comparison
Blackfriday (Go):
import "github.com/russross/blackfriday/v2"
markdown := []byte("# Hello, Markdown!")
html := blackfriday.Run(markdown)
Pandoc (Haskell):
import Text.Pandoc
main :: IO ()
main = do
let markdown = "# Hello, Markdown!"
result <- runIO $ readMarkdown def markdown >>= writeHtml5String def
putStrLn $ either show id result
Summary
Blackfriday is a lightweight, Go-specific Markdown parser that excels in performance and ease of integration for Go projects. However, it lacks the extensive features and format support of Pandoc. Pandoc, written in Haskell, offers a more comprehensive document conversion toolset with support for numerous input and output formats, making it more versatile but potentially more complex to use and integrate, especially in non-Haskell environments.
Determines which markup library to use to render a content file (e.g. README) on GitHub
Pros of Markup
- Lightweight and focused specifically on rendering various markup formats for GitHub
- Easier integration with GitHub-specific features and workflows
- Supports a wider range of markup languages out-of-the-box (e.g., .textile, .rdoc, .org)
Cons of Markup
- Limited functionality compared to Pandoc's extensive conversion capabilities
- Less flexible for non-GitHub use cases or complex document transformations
- Smaller community and fewer extensions/plugins available
Code Comparison
Markup (Ruby):
def render(content)
GitHub::Markup.render(file, content)
end
Pandoc (Haskell):
convertMarkdown :: String -> IO String
convertMarkdown input = runIOorExplode $ readMarkdown def input >>= writeHtml5String def
Summary
Markup is a specialized tool for GitHub-centric markup rendering, while Pandoc offers a more comprehensive document conversion solution. Markup excels in its simplicity and GitHub integration, whereas Pandoc provides greater flexibility and power for complex document transformations across various formats. The choice between the two depends on the specific use case and required features.
A bidirectional Markdown to HTML to Markdown converter written in Javascript
Pros of Showdown
- Lightweight and focused on Markdown to HTML conversion
- Easy to integrate into JavaScript projects, especially for browser-based applications
- Simpler to use for basic Markdown tasks
Cons of Showdown
- Limited input/output format support compared to Pandoc's extensive capabilities
- Less powerful for complex document conversions or academic writing needs
- Smaller community and fewer extensions/plugins available
Code Comparison
Showdown (JavaScript):
var converter = new showdown.Converter();
var html = converter.makeHtml('# Hello, Markdown!');
Pandoc (Command-line):
pandoc input.md -o output.html
Key Differences
- Pandoc is a comprehensive document conversion tool supporting numerous formats, while Showdown focuses on Markdown to HTML conversion.
- Showdown is JavaScript-based and easily integrates into web applications, whereas Pandoc is a standalone command-line tool written in Haskell.
- Pandoc offers more advanced features like citations, metadata handling, and custom templates, making it suitable for academic and complex document processing.
- Showdown is more appropriate for simpler Markdown tasks in web environments, while Pandoc excels in versatility and power for various document conversion needs.
:gem: A fast, open source text processor and publishing toolchain, written in Ruby, for converting AsciiDoc content to HTML 5, DocBook 5, and other formats.
Pros of Asciidoctor
- Native Ruby implementation, making it faster and more efficient for Ruby-based projects
- More extensive syntax and formatting options for technical documentation
- Better support for generating complex, multi-format output (HTML, PDF, EPUB)
Cons of Asciidoctor
- Limited support for input formats compared to Pandoc
- Steeper learning curve due to more complex syntax
- Less flexibility in converting between various document formats
Code Comparison
Asciidoctor (Ruby):
require 'asciidoctor'
Asciidoctor.convert_file 'document.adoc', to_file: 'output.html', safe: :safe
Pandoc (Haskell):
import Text.Pandoc
main :: IO ()
main = runIOorExplode $ readMarkdown def "input.md" >>= writeHtml5 def
Both Asciidoctor and Pandoc are powerful document conversion tools, but they cater to different needs. Asciidoctor excels in creating technical documentation with its rich syntax and multi-format output capabilities, making it ideal for Ruby-based projects. Pandoc, on the other hand, offers unparalleled flexibility in converting between various document formats and supports a wider range of input formats. The choice between the two depends on the specific requirements of your project and the ecosystem you're working in.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Pandoc
The universal markup converter
Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library.
It can convert from
bibtex
(BibTeX bibliography)biblatex
(BibLaTeX bibliography)bits
(BITS XML, alias forjats
)commonmark
(CommonMark Markdown)commonmark_x
(CommonMark Markdown with extensions)creole
(Creole 1.0)csljson
(CSL JSON bibliography)csv
(CSV table)tsv
(TSV table)djot
(Djot markup)docbook
(DocBook)docx
(Word docx)dokuwiki
(DokuWiki markup)endnotexml
(EndNote XML bibliography)epub
(EPUB)fb2
(FictionBook2 e-book)gfm
(GitHub-Flavored Markdown), or the deprecated and less accuratemarkdown_github
; usemarkdown_github
only if you need extensions not supported ingfm
.haddock
(Haddock markup)html
(HTML)ipynb
(Jupyter notebook)jats
(JATS XML)jira
(Jira/Confluence wiki markup)json
(JSON version of native AST)latex
(LaTeX)markdown
(Pandocâs Markdown)markdown_mmd
(MultiMarkdown)markdown_phpextra
(PHP Markdown Extra)markdown_strict
(original unextended Markdown)mediawiki
(MediaWiki markup)man
(roff man)muse
(Muse)native
(native Haskell)odt
(OpenOffice text document)opml
(OPML)org
(Emacs Org mode)ris
(RIS bibliography)rtf
(Rich Text Format)rst
(reStructuredText)t2t
(txt2tags)textile
(Textile)tikiwiki
(TikiWiki markup)twiki
(TWiki markup)typst
(typst)vimwiki
(Vimwiki)- the path of a custom Lua reader, see Custom readers and writers below
It can convert to
ansi
(text with ANSI escape codes, for terminal viewing)asciidoc
(modern AsciiDoc as interpreted by AsciiDoctor)asciidoc_legacy
(AsciiDoc as interpreted byasciidoc-py
).asciidoctor
(deprecated synonym forasciidoc
)beamer
(LaTeX beamer slide show)bibtex
(BibTeX bibliography)biblatex
(BibLaTeX bibliography)chunkedhtml
(zip archive of multiple linked HTML files)commonmark
(CommonMark Markdown)commonmark_x
(CommonMark Markdown with extensions)context
(ConTeXt)csljson
(CSL JSON bibliography)djot
(Djot markup)docbook
ordocbook4
(DocBook 4)docbook5
(DocBook 5)docx
(Word docx)dokuwiki
(DokuWiki markup)epub
orepub3
(EPUB v3 book)epub2
(EPUB v2)fb2
(FictionBook2 e-book)gfm
(GitHub-Flavored Markdown), or the deprecated and less accuratemarkdown_github
; usemarkdown_github
only if you need extensions not supported ingfm
.haddock
(Haddock markup)html
orhtml5
(HTML, i.e. HTML5/XHTML polyglot markup)html4
(XHTML 1.0 Transitional)icml
(InDesign ICML)ipynb
(Jupyter notebook)jats_archiving
(JATS XML, Archiving and Interchange Tag Set)jats_articleauthoring
(JATS XML, Article Authoring Tag Set)jats_publishing
(JATS XML, Journal Publishing Tag Set)jats
(alias forjats_archiving
)jira
(Jira/Confluence wiki markup)json
(JSON version of native AST)latex
(LaTeX)man
(roff man)markdown
(Pandocâs Markdown)markdown_mmd
(MultiMarkdown)markdown_phpextra
(PHP Markdown Extra)markdown_strict
(original unextended Markdown)markua
(Markua)mediawiki
(MediaWiki markup)ms
(roff ms)muse
(Muse)native
(native Haskell)odt
(OpenOffice text document)opml
(OPML)opendocument
(OpenDocument)org
(Emacs Org mode)pdf
(PDF)plain
(plain text)pptx
(PowerPoint slide show)rst
(reStructuredText)rtf
(Rich Text Format)texinfo
(GNU Texinfo)textile
(Textile)slideous
(Slideous HTML and JavaScript slide show)slidy
(Slidy HTML and JavaScript slide show)dzslides
(DZSlides HTML5 + JavaScript slide show)revealjs
(reveal.js HTML5 + JavaScript slide show)s5
(S5 HTML and JavaScript slide show)tei
(TEI Simple)typst
(typst)xwiki
(XWiki markup)zimwiki
(ZimWiki markup)- the path of a custom Lua writer, see Custom readers and writers below
Pandoc can also produce PDF output via LaTeX, Groff ms, or HTML.
Pandocâs enhanced version of Markdown includes syntax for tables, definition lists, metadata blocks, footnotes, citations, math, and much more. See the Userâs Manual below under Pandocâs Markdown.
Pandoc has a modular design: it consists of a set of readers, which parse text in a given format and produce a native representation of the document (an abstract syntax tree or AST), and a set of writers, which convert this native representation into a target format. Thus, adding an input or output format requires only adding a reader or writer. Users can also run custom pandoc filters to modify the intermediate AST (see the documentation for filters and Lua filters).
Because pandocâs intermediate representation of a document is less expressive than many of the formats it converts between, one should not expect perfect conversions between every format and every other. Pandoc attempts to preserve the structural elements of a document, but not formatting details such as margin size. And some document elements, such as complex tables, may not fit into pandocâs simple document model. While conversions from pandocâs Markdown to all formats aspire to be perfect, conversions from formats more expressive than pandocâs Markdown can be expected to be lossy.
Installing
Hereâs how to install pandoc.
Documentation
Pandocâs website contains a full Userâs Guide. It is also available here as pandoc-flavored Markdown. The website also contains some examples of the use of pandoc and a limited online demo.
Contributing
Pull requests, bug reports, and feature requests are welcome. Please make sure to read the contributor guidelines before opening a new issue.
License
© 2006-2024 John MacFarlane (jgm@berkeley.edu). Released under the GPL, version 2 or greater. This software carries no warranty of any kind. (See COPYRIGHT for full copyright and warranty notices.)
Top Related Projects
A Python implementation of John Gruber’s Markdown with Extension support.
CommonMark spec, with reference implementations in C and JavaScript
Blackfriday: a markdown processor for Go
Determines which markup library to use to render a content file (e.g. README) on GitHub
A bidirectional Markdown to HTML to Markdown converter written in Javascript
:gem: A fast, open source text processor and publishing toolchain, written in Ruby, for converting AsciiDoc content to HTML 5, DocBook 5, and other formats.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot