1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "github.com/yuin/goldmark"
11 "github.com/yuin/goldmark/parser"
12 "github.com/yuin/goldmark/renderer/html"
15 // renderMarkdown converts a limited and opinionated flavor of Markdown (compliant with
16 // CommonMark 0.29) to HTML for the purposes of Go websites.
18 // The Markdown source may contain raw HTML,
19 // but Go templates have already been processed.
20 func renderMarkdown(src []byte) ([]byte, error) {
21 // parser.WithHeadingAttribute allows custom ids on headings.
22 // html.WithUnsafe allows use of raw HTML, which we need for tables.
24 goldmark.WithParserOptions(parser.WithHeadingAttribute()),
25 goldmark.WithRendererOptions(html.WithUnsafe()))
27 if err := md.Convert(src, &buf); err != nil {
30 return buf.Bytes(), nil