This Go package provides a CommonMark parser, a specific dialect of Markdown. It allows you to parse, analyze, and render CommonMark/Markdown documents with an abstract syntax tree API.
This implementation conforms to Version 0.30 of the CommonMark Specification.
A few other Markdown/CommonMark packages exist for Go. This package prioritizes (in order):
- Ability to connect the parse tree to CommonMark input losslessly in order to enable creation of tools that reformat or manipulate CommonMark documents.
- Adherence to CommonMark specification.
- Comprehensibility of implementation.
- Performance.
go get zombiezen.com/go/commonmarkpackage main
import (
"fmt"
"io"
"os"
"zombiezen.com/go/commonmark"
)
func main() {
commonmarkSource, err := io.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
blocks, refMap := commonmark.Parse(commonmarkSource)
commonmark.RenderHTML(os.Stdout, blocks, refMap)
}