package markdown
Import Path
github.com/gomarkdown/markdown (on go.dev)
Dependency Relation
imports 5 packages, and imported by one package
Involved Source Files
Package markdown implements markdown parser and HTML renderer.
It parses markdown into AST format which can be serialized to HTML
(using html.Renderer) or possibly other formats (using alternate renderers).
Convert markdown to HTML
The simplest way to convert markdown document to HTML
md := []byte("## markdown document")
html := markdown.ToHTML(md, nil, nil)
Customizing parsing and HTML rendering
You can customize parser and HTML renderer:
import (
"github.com/gomarkdown/markdown/parser"
"github.com/gomarkdown/markdown/renderer"
"github.com/gomarkdown/markdown"
)
extensions := parser.CommonExtensions | parser.AutoHeadingIDs
p := parser.NewWithExtensions(extensions)
htmlFlags := html.CommonFlags | html.HrefTargetBlank
opts := html.RendererOptions{Flags: htmlFlags}
renderer := html.NewRenderer(opts)
md := []byte("markdown text")
html := markdown.ToHTML(md, p, renderer)
For a cmd-line tool see https://github.com/gomarkdown/mdtohtml
markdown.go
Package-Level Type Names (only one)
Renderer is an interface for implementing custom renderers.
RenderHeader is a method that allows the renderer to produce some
content preceding the main body of the output document. The header is
understood in the broad sense here. For example, the default HTML
renderer will write not only the HTML document preamble, but also the
table of contents if it was requested.
The method will be passed an entire document tree, in case a particular
implementation needs to inspect it to produce output.
The output should be written to the supplied writer w. If your
implementation has no header to write, supply an empty implementation.
RenderNode renders markdown node to w.
It's called once for a leaf node.
It's called twice for non-leaf nodes:
* first with entering=true
* then with entering=false
Return value is a way to tell the calling walker to adjust its walk
pattern: e.g. it can terminate the traversal by returning Terminate. Or it
can ask the walker to skip a subtree of this node by returning SkipChildren.
The typical behavior is to return GoToNext, which asks for the usual
traversal to the next node.
*github.com/gomarkdown/markdown/html.Renderer
func Render(doc ast.Node, renderer Renderer) []byte
func ToHTML(markdown []byte, p *parser.Parser, renderer Renderer) []byte
Package-Level Functions (total 3)
Parse parsers a markdown document using provided parser. If parser is nil,
we use parser configured with parser.CommonExtensions.
It returns AST (abstract syntax tree) that can be converted to another
format using Render function.
Render uses renderer to convert parsed markdown document into a different format.
To convert to HTML, pass html.Renderer
ToHTML converts markdownDoc to HTML.
You can optionally pass a parser and renderer. This allows to customize
a parser, use a customized html render or use completely custom renderer.
If you pass nil for both, we use parser configured with parser.CommonExtensions
and html.Renderer configured with html.CommonFlags.
Package-Level Variables (only one)
NormalizeNewlines converts Windows and Mac newlines to Unix newlines.
The parser only supports Unix newlines. If your markdown content
might contain Windows or Mac newlines, use this function to convert to Unix newlines
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |