Package doc
import "go/doc"
The doc package extracts source code documentation from a Go AST.
Package files
comment.go doc.gofunc CommentText
func CommentText(comment *ast.CommentGroup) string
CommentText returns the text of comment, with the comment markers - //, /*, and */ - removed.
func ToHTML
func ToHTML(w io.Writer, s []byte)
Convert comment text to formatted HTML. The comment was prepared by DocReader, so it is known not to have leading, trailing blank lines nor to have trailing spaces at the end of lines. The comment markers have already been removed.
Turn each run of multiple \n into </p><p> Turn each run of indented lines into <pre> without indent.
TODO(rsc): I'd like to pass in an array of variable names []string and then italicize those strings when they appear as words.
type FuncDoc
FuncDoc is the documentation for a func declaration, either a top-level function or a method function.
type FuncDoc struct {
Doc string
Recv ast.Expr // TODO(rsc): Would like string here
Name string
Decl *ast.FuncDecl
}
type PackageDoc
PackageDoc is the documentation for an entire package.
type PackageDoc struct {
PackageName string
ImportPath string
Filenames []string
Doc string
Consts []*ValueDoc
Types []*TypeDoc
Vars []*ValueDoc
Funcs []*FuncDoc
Bugs []string
}
func NewFileDoc
func NewFileDoc(file *ast.File) *PackageDoc
func NewPackageDoc
func NewPackageDoc(pkg *ast.Package, importpath string) *PackageDoc
func (*PackageDoc) Filter
func (p *PackageDoc) Filter(names []string)
Filter eliminates information from d that is not about one of the given names. TODO: Recognize "Type.Method" as a name. TODO(r): maybe precompile the regexps.
type TypeDoc
TypeDoc is the documentation for a declared type. Consts and Vars are sorted lists of constants and variables of (mostly) that type. Factories is a sorted list of factory functions that return that type. Methods is a sorted list of method functions on that type.
type TypeDoc struct {
Doc string
Type *ast.TypeSpec
Consts []*ValueDoc
Vars []*ValueDoc
Factories []*FuncDoc
Methods []*FuncDoc
Decl *ast.GenDecl
// contains unexported fields
}
type ValueDoc
ValueDoc is the documentation for a group of declared values, either vars or consts.
type ValueDoc struct {
Doc string
Decl *ast.GenDecl
// contains unexported fields
}
