Categorygitlab.com/golang-commonmark/markdown
repositorypackage
0.0.0-20211110145824-bf3e522c626a
Repository: https://gitlab.com/golang-commonmark/markdown.git
Documentation: pkg.go.dev

# README

markdown GoDoc License Pipeline status Coverage report

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

Installation

go get -u gitlab.com/golang-commonmark/markdown

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

go get -u gitlab.com/golang-commonmark/mdtool

Standards support

Currently supported CommonMark spec: v0.28.

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))
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:

NameTypeDescriptionDefault
HTMLboolwhether to enable raw HTMLfalse
Tablesboolwhether to enable GFM tablestrue
Linkifyboolwhether to autoconvert plain-text URLs to linkstrue
Typographerboolwhether to enable typographic replacementstrue
Quotesstring / []stringdouble + single quote replacement pairs for the typographer“”‘’
MaxNestingintmaximum nesting level20
LangPrefixstringCSS language prefix for fenced blockslanguage-
Breaksboolwhether to convert newlines inside paragraphs into <br>false
XHTMLOutputboolwhether to output XHTML instead of HTMLfalse

Benchmarks

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

BenchmarkRenderSpecNoHTML-4       158     7830071 ns/op    2893954 B/op    18361 allocs/op
BenchmarkRenderSpec-4             145     8189870 ns/op    2896310 B/op    18351 allocs/op
BenchmarkRenderSpecBlackFriday2-4 169     7211729 ns/op    2938768 B/op    19214 allocs/op

See also

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

https://github.com/yuin/goldmark - another CommonMark-compliant markdown parser in Go.

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