blob: 0860f5a3865792fa6e07909e95b518a58adf30c3 [file] [log] [blame]
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package markdown provides a wrapper for rendering Markdown. It is intended
// to be used by x/website and x/blog so that we can use the same renderer
// with the same settings.
// This package is not intended for general use, and its API is not guaranteed
// to be stable.
package markdown
import (
// Render converts a limited and opinionated flavor of Markdown (compliant with
// CommonMark 0.29) to HTML for the purposes of websites. This should
// not be adjusted except for the needs of *
// The Markdown source may contain raw HTML and Go templates. Sanitization of
// untrusted content is not performed: the caller is responsible for ensuring
// that only trusted content is provided.
func Render(src []byte) ([]byte, error) {
// html.WithUnsafe allows use of raw HTML, which we need for tables.
md := goldmark.New(goldmark.WithRendererOptions(html.WithUnsafe()))
var buf bytes.Buffer
if err := md.Convert(src, &buf); err != nil {
return nil, err
return buf.Bytes(), nil