GoPLS Viewer

Home|gopls/godoc/markdown.go
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.
4
5package godoc
6
7import (
8    "bytes"
9
10    "github.com/yuin/goldmark"
11    "github.com/yuin/goldmark/parser"
12    "github.com/yuin/goldmark/renderer/html"
13)
14
15// renderMarkdown converts a limited and opinionated flavor of Markdown (compliant with
16// CommonMark 0.29) to HTML for the purposes of Go websites.
17//
18// The Markdown source may contain raw HTML,
19// but Go templates have already been processed.
20func renderMarkdown(src []byte) ([]byteerror) {
21    // parser.WithHeadingAttribute allows custom ids on headings.
22    // html.WithUnsafe allows use of raw HTML, which we need for tables.
23    md := goldmark.New(
24        goldmark.WithParserOptions(parser.WithHeadingAttribute()),
25        goldmark.WithRendererOptions(html.WithUnsafe()))
26    var buf bytes.Buffer
27    if err := md.Convert(src, &buf); err != nil {
28        return nilerr
29    }
30    return buf.Bytes(), nil
31}
32
MembersX
renderMarkdown
renderMarkdown.src
renderMarkdown.md
renderMarkdown.buf
renderMarkdown.err
goldmark
html
Members
X