Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Haskell implementation of markdown using a PEG grammar

tree: 8a4f5a17d9

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 Text
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 Markdown.hs
Octocat-spinner-32 README
Octocat-spinner-32 test.sh
README
Markdown.hs - an implementation of markdown in Haskell, using a PEG grammar.
(c) 2008 John MacFarlane, released under the GPL.

Markdown is a plain-text syntax for writing HTML (and potentially other
formats), by John Gruber (<http://daringfireball.net/projects/markdown/>).

To build (using the GHC Haskell compiler):

    ghc -O2 --make Markdown.hs

or just:

    make

Markdown.hs uses John Meacham's Frisby PEG parsing library.  This can
be found at <http://repetae.net/computer/frisby>, but for convenience
the required files are included in this directory.  The XML formatting
library from Pandoc (<http://johnmacfarlane.net/pandoc>).
is also included for convenience.

This is a first draft.  I'm sure there are many ways in which it can be
improved. Currently it passes the Markdown 1.0.3 test suite, with the
exception of two small corner cases.

The grammar definition is the function 'doc' in Markdown.hs. It should
be easy to change and extend it. If you want to add new block or
inline elements, you'll also need to modify the definitions of 'Block'
and 'Inline', and add clauses to handle these to 'inlineToHtml' and
'blockToHtml'.

There are a couple of features of markdown that cannot be handled
straightforwardly in a PEG grammar; workarounds have been provided here.
The first is the syntax for code spans: text enclosed by equal-sized
sequences of backticks. I have simulated this by including separate
rules for sequences of backticks of length 1 to 10, but this doesn't
precisely capture the markdown rule. The second is the syntax for
indented blocks, e.g. in block quotes and lists.  I have handled these
by having the parser return unparsed markdown text for the block
contents; the parser is then called again by the function 'blockToHtml'.

See LICENSE for license information for Markdown.hs and the other included
files.

Something went wrong with that request. Please try again.