func docstring(doc string) string {
	doc = reNewline.ReplaceAllString(doc, "")
	doc = reMultiSpace.ReplaceAllString(doc, " ")
	doc = reComments.ReplaceAllString(doc, "")
	doc = reExamples.ReplaceAllString(doc, "")
	doc = rePara.ReplaceAllString(doc, "$1\n\n")
	doc = reLink.ReplaceAllString(doc, "$2 ($1)")
	doc = reTag.ReplaceAllString(doc, "$1")
	doc = reEndNL.ReplaceAllString(doc, "")
	doc = strings.TrimSpace(doc)
	if doc == "" {
		return "\n"
	}
	doc = html.UnescapeString(doc)
	doc = wrap(doc, 72)
	return commentify(doc)
}
docstring rewrites a string to insert godocs formatting.
package api
import (
	"bytes"
	"html"
	"regexp"
	"strings"
)
var reNewline = regexp.MustCompile(`\r?\n`)
var reMultiSpace = regexp.MustCompile(`\s+`)
var reComments = regexp.MustCompile(`<!--.*?-->`)
var reExamples = regexp.MustCompile(`<examples?>.+?<\/examples?>`)
var rePara = regexp.MustCompile(`<(?:p|h\d)>(.+?)</(?:p|h\d)>`)
var reLink = regexp.MustCompile(`<a href="(.+?)">(.+?)</a>`)
var reTag = regexp.MustCompile(`<.+?>`)
var reEndNL = regexp.MustCompile(`\n+$`)