func pairedParensPrefixLen(s string) int {
	parens := 0
	l := len(s)
	for i, ch := range s {
		switch ch {
		case '(':
			if parens == 0 {
				l = i
			}
			parens++
		case ')':
			parens--
			if parens == 0 {
				l = len(s)
			} else if parens < 0 {
				return i
			}
		}
	}
	return l
}
pairedParensPrefixLen returns the length of the longest prefix of s containing paired parentheses.
package doc
import (
	"io"
	"regexp"
	"strings"
	"text/template"  
	"unicode"
	"unicode/utf8"
)
var (
	ldquo = []byte("&ldquo;")
	rdquo = []byte("&rdquo;")
)
func commentEscape(w io.Writer, text string, nice bool) {
	last := 0
	if nice {
		for i := 0; i < len(text)-1; i++ {
			ch := text[i]
			if ch == text[i+1] && (ch == '`' || ch == '\'') {
				template.HTMLEscape(w, []byte(text[last:i]))
				last = i + 2
				switch ch {
				case '`':
					w.Write(ldquo)
				case '\'':
					w.Write(rdquo)
				}
				i++  
			}
		}
	}
	template.HTMLEscape(w, []byte(text[last:]))
}
const (
	identRx = `[\pL_][\pL_0-9]*`
	protoPart = `(https?|ftp|file|gopher|mailto|nntp)`
	hostPart = `([a-zA-Z0-9_@\-.\[\]:]+)`
	pathPart = `([.,:;?!]*[a-zA-Z0-9$'()*+&#=@~_/\-\[\]%])*`
	urlRx = protoPart + `: 
)
var matchRx = regexp.MustCompile(`(` + urlRx + `)|(` + identRx + `)`)
var (
	html_a      = []byte(`<a href="`)
	html_aq     = []byte(`">`)
	html_enda   = []byte("</a>")
	html_i      = []byte("<i>")
	html_endi   = []byte("</i>")
	html_p      = []byte("<p>\n")
	html_endp   = []byte("</p>\n")
	html_pre    = []byte("<pre>")
	html_endpre = []byte("</pre>\n")
	html_h      = []byte(`<h3 id="`)
	html_hq     = []byte(`">`)
	html_endh   = []byte("</h3>\n")
)