func heading(line string) string {
	line = strings.TrimSpace(line)
	if len(line) == 0 {
		return ""
	}
	r, _ := utf8.DecodeRuneInString(line)
	if !unicode.IsLetter(r) || !unicode.IsUpper(r) {
		return ""
	}
	r, _ = utf8.DecodeLastRuneInString(line)
	if !unicode.IsLetter(r) && !unicode.IsDigit(r) {
		return ""
	}
	if strings.ContainsAny(line, ",.;:!?+*/=()[]{}_^°&§~%#@<\">\\") {
		return ""
	}
	for b := line; ; {
		i := strings.IndexRune(b, '\'')
		if i < 0 {
			break
		}
		if i+1 >= len(b) || b[i+1] != 's' || (i+2 < len(b) && b[i+2] != ' ') {
			return ""  
		}
		b = b[i+2:]
	}
	return line
}
heading returns the trimmed line if it passes as a section heading;
otherwise it returns the empty string.
package main
import (
	"io"
	"regexp"
	"strings"
	"text/template"  
	"unicode"
	"unicode/utf8"
)
const (
	identRx = `[a-zA-Z_][a-zA-Z_0-9]*`  
	protocol = `(https?|ftp|file|gopher|mailto|news|nntp|telnet|wais|prospero):`
	hostPart = `[a-zA-Z0-9_@\-]+`
	filePart = `[a-zA-Z0-9_?%#~&/\-+=]+`
	urlRx    = protocol + ` 
		hostPart + `([.:]` + hostPart + `)*/?` +  
		filePart + `([:.,]` + filePart + `)*`
)
var matchRx = regexp.MustCompile(`(` + urlRx + `)|(` + identRx + `)`)
var (
	htmlA    = []byte(`<a href="`)
	htmlAq   = []byte(`">`)
	htmlEnda = []byte("</a>")
	mdPre     = []byte("\t")
	mdNewline = []byte("\n")
	mdH3      = []byte("### ")
)
func emphasize(w io.Writer, line string) {
	for {
		m := matchRx.FindStringSubmatchIndex(line)
		if m == nil {
			break
		}
		_, _ = w.Write([]byte(line[0:m[0]]))
		match := line[m[0]:m[1]]
		if m[2] >= 0 {
			_, _ = w.Write(htmlA)
			template.HTMLEscape(w, []byte(match))
			_, _ = w.Write(htmlAq)
		}
		_, _ = w.Write([]byte(match))
		if m[2] >= 0 {
			_, _ = w.Write(htmlEnda)
		}
		line = line[m[1]:]
	}
	_, _ = w.Write([]byte(line))
}
func indentLen(s string) int {
	i := 0
	for i < len(s) && (s[i] == ' ' || s[i] == '\t') {
		i++
	}
	return i
}
func isBlank(s string) bool {
	return len(s) == 0 || (len(s) == 1 && s[0] == '\n')
}
func commonPrefix(a, b string) string {
	i := 0
	for i < len(a) && i < len(b) && a[i] == b[i] {
		i++
	}
	return a[0:i]
}
func unindent(block []string) {
	if len(block) == 0 {
		return
	}
	prefix := block[0][0:indentLen(block[0])]
	for _, line := range block {
		if !isBlank(line) {
			prefix = commonPrefix(prefix, line[0:indentLen(line)])
		}
	}
	n := len(prefix)
	for i, line := range block {
		if !isBlank(line) {
			block[i] = line[n:]
		}
	}
}