Go to file
2012-04-30 10:07:49 +02:00
cmd/markdown new API: p := NewParser(&opts), p.Markdown(r, f) replaces d := Parse(r, opts), d.WriteHtml(w) 2012-04-28 22:57:55 +02:00
misc cmd: move profiling stuff into pprof.go 2012-04-20 13:49:21 +02:00
.hgignore initial import 2010-11-21 23:04:39 +01:00
.hgtags add tags go.r58 and go.r59 2011-12-03 00:47:57 +01:00
doc.go new API: p := NewParser(&opts), p.Markdown(r, f) replaces d := Parse(r, opts), d.WriteHtml(w) 2012-04-28 22:57:55 +02:00
elemheap.go mk_element: turn global allocation into a per-parser, reusable allocation. 2012-04-29 23:54:10 +02:00
LICENSE initial import 2010-11-21 23:04:39 +01:00
Makefile sync with peg 2012-04-24 00:15:47 +02:00
markdown.go Added ' and " to SpecialChars. [jgm/peg-markdown] 2012-04-30 10:07:49 +02:00
output.go cosmetics 2012-04-30 00:58:06 +02:00
parser.leg Added ' and " to SpecialChars. [jgm/peg-markdown] 2012-04-30 10:07:49 +02:00
parser.leg.go new API: p := NewParser(&opts), p.Markdown(r, f) replaces d := Parse(r, opts), d.WriteHtml(w) 2012-04-28 22:57:55 +02:00
portid Added ' and " to SpecialChars. [jgm/peg-markdown] 2012-04-30 10:07:49 +02:00
README.md README.markdown -> README.md + update 2012-04-30 00:56:41 +02:00

This is an implementation of John Gruber's markdown in Go. It is a translation of peg-markdown, written by John MacFarlane in C, into Go. It is using a modified version of Andrew J Snodgrass' PEG parser peg -- now supporting LEG grammars --, which is itself based on the parser used by peg-markdown.

Support for HTML output is implemented, but Groff and LaTeX output have not been ported. The output should be identical to that of peg-markdown.

A simple benchmark has been done by comparing the execution time of the Go binary (cmd/main.go) and the original C implementation's binary needed for processing a Markdown document, which had been created by concatenating ten Markdown syntax descriptions.

The C version is still around 1.2x faster than the Go version.

Installation

Provided you have a copy of Go 1, and git is available,

go get github.com/knieriem/markdown

should download and install the package according to your GOPATH settings.

See doc.go for an example how to use the package.

To create the command line program markdown, run

go build github.com/knieriem/markdown/cmd/markdown

the binary should then be available in the current directory.

To run the Markdown 1.0.3 test suite, type

make test

This will download peg-markdown, in case you have Mercurial and the hg-git extension available, build cmd/markdown, and run the test suite.

The test suite should fail on exactly one test Ordered and unordered lists , for the same reason which applies to peg-markdown, because the grammar is the same. See the original README for details.

Development

There is not yet a way to create a Go source file like parser.leg.go automatically from another file, parser.leg, when building packages and commands using the Go tool. To make markdown installable using go get, parser.leg.go has been added to the VCS.

Make parser will update parser.leg.go using leg, which is part of knieriem/peg at github, if parser.leg has been changed, or if the Go file is missing. If a copy of peg is not yet present on your system, run

go get github.com/knieriem/peg

Then make parser should succeed.

Extensions

In addition to the extensions already present in peg-markdown, this package also supports definition lists (option -dlists) similar to the way they are described in the documentation of PHP Markdown Extra.

Definitions (<dd>...</dd>) are implemented using ListTight and ListLoose, on which bullet lists and ordered lists are based already. If there is an empty line between the definition title and the first definition, a loose list is expected, a tight list otherwise.

As definition item markers both : and ~ can be used.

Todo

  • Implement tables

  • Where appropriate, use more idiomatic Go code

Subdirectory Index

  • cmd/markdown command line program markdown