CommonMark-compliant markdown parser and renderer in Go. Discontinued until CommonMark 1.0
Go
Latest commit 9e199b8 Oct 17, 2015 @c2h5oh c2h5oh Adds build status badge
Permalink
Failed to load latest commit information.
byteutil Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
html Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
linkify Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
spec Update spec to 0.21 Jul 22, 2015
AUTHORS Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
LICENSE Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
README.md Adds build status badge Oct 17, 2015
align.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
autolink.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
autolink_fsm.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
autolink_fsm_test.go Add the code Jun 12, 2015
backticks.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
blockquote.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
code.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
emphasis.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
entity.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
escape.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
fence.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
heading.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
helpers.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
helpers_test.go Add the code Jun 12, 2015
hr.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
html_block.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
html_block_test.go Add the code Jun 12, 2015
html_inline.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
html_inline_fsm.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
html_inline_fsm_test.go Rename file Jun 13, 2015
image.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
inline.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
lheading.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
link.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
linkify.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
list.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
markdown.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
markdown_benchmark_test.go Move blackfriday renderer instantiation outside of the benchmark loop Jun 28, 2015
markdown_test.go Update spec to 0.21 Jul 22, 2015
newline.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
normalize.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
normalize_test.go Add the code Jun 12, 2015
options.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
paragraph.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
parser_block.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
parser_inline.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
plugins.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
reference.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
render.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
replacements.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
replacements_test.go Add the code Jun 12, 2015
smartquotes.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
smartquotes_test.go Add the code Jun 12, 2015
state_block.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
state_core.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
state_inline.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
strikethrough.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
table.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
table_fsm.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
table_test.go Add the code Jun 12, 2015
text.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
token.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
urlschema.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
util.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015
util_test.go Remove all special characters from protocol when validating URLs Jun 13, 2015
writer.go Relicense under the BSD 2-clause license; fix imports Oct 11, 2015

README.md

markdown GoDoc License Build Status

golang-commonmark/markdown package provides CommonMark-compliant markdown parser and renderer, written in Go.

Installation

go get github.com/golang-commonmark/markdown

You can also go get mdtool, an example command-line tool:

go get github.com/golang-commonmark/mdtool

Standards support

Currently supported CommonMark spec: v0.20.

Extensions

Besides the features required by CommonMark, golang-commonmark/markdown supports:

  • Tables (GFM)
  • Strikethrough (GFM)
  • Autoconverting plain-text URLs to links
  • Typographic replacements (smart quotes and other)

Usage

md := markdown.New(markdown.XHTMLOutput(true), markdown.Nofollow(true))
fmt.Println(md.RenderToString([]byte("Header\n===\nText")))

Check out the source of mdtool for a more complete example.

The following options are currently supported:

Name Type Description Default
HTML bool whether to enable raw HTML false
Tables bool whether to enable GFM tables true
Linkify bool whether to autoconvert plain-text URLs to links true
Typographer bool whether to enable typographic replacements true
Quotes string double + single quote replacement pairs for the typographer “”‘’
MaxNesting int maximum nesting level 20
LangPrefix string CSS language prefix for fenced blocks language-
Breaks bool whether to convert newlines inside paragraphs into <br> false
Nofollow bool whether to add rel="nofollow" to links false
XHTMLOutput bool whether to output XHTML instead of HTML false

Benchmarks

Rendering spec/spec-0.20.txt on a Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz

BenchmarkRenderSpecNoHTML         300     5751062 ns/op    2696668 B/op     7861 allocs/op
BenchmarkRenderSpec               100    15423729 ns/op    4659899 B/op    38725 allocs/op
BenchmarkRenderSpecBlackFriday    200     7531597 ns/op    2750346 B/op    37247 allocs/op

TODO

  • Improve performance with the raw HTML option enabled
  • Write an URL parser/encoder that would support decoding punycode and counting matching [( and )] in URLs

References / Thanks

golang-commonmark/markdown is a partial port of an awesome JavaScript markdown parser markdown-it, written by Alex Kocharin and Vitaly Puzrin.

See also

https://github.com/jgm/CommonMark — the reference CommonMark implementations in C and JavaScript, also contains the latest spec and an online demo.

http://talk.commonmark.org — the CommonMark forum, a good place to join together the efforts of the developers.