Documentation
¶
Overview ¶
Package dochtml renders Go package documentation into HTML.
This package and its API are under development (see golang.org/issue/39883). The plan is to iterate on the development internally for x/pkgsite needs first, before factoring it out somewhere non-internal where its API can no longer be easily modified.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTooLarge represents an error where the rendered documentation HTML // size exceeded the specified limit. See the RenderOptions.Limit field. ErrTooLarge = errors.New("rendered documentation HTML size exceeded the specified limit") )
Functions ¶
func IsDeprecated ¶
IsDeprecated reports whether the string has a "Deprecated" line.
func LoadTemplates ¶
LoadTemplates reads and parses the templates used to generate documentation. It is kept for API compatibility with pkgsite; llcppg normally relies on the embedded templates via ensureTemplates. The first caller wins (loadOnce).
Types ¶
type BuildContext ¶
type BuildContext struct {
GOOS, GOARCH string
}
BuildContext describes the GOOS/GOARCH a package was built for. It is a trimmed local replacement for golang.org/x/pkgsite/internal.BuildContext: the renderer only reads GOOS to add a "?GOOS=" suffix to package links, so the full pkgsite type (with its matching/precedence helpers) is not needed.
type ModuleInfo ¶
type ModuleInfo struct {
ModulePath string
ResolvedVersion string
// ModulePackages is the set of all full package paths in the module.
ModulePackages map[string]bool
}
ModuleInfo contains all the information a package needs about the module it belongs to in order to render its documentation.
type Parts ¶
type Parts struct {
Body safehtml.HTML // main body of doc
Outline safehtml.HTML // outline for large screens
MobileOutline safehtml.HTML // outline for mobile
Links []render.Link // "Links" section of package doc
}
Parts contains HTML for each part of the documentation.
func Render ¶
func Render(ctx context.Context, fset *token.FileSet, p *doc.Package, opt RenderOptions) (_ *Parts, err error)
Render renders package documentation HTML for the provided file set and package, in separate parts.
If any of the rendered documentation part HTML sizes exceeds the specified limit, an error with ErrTooLarge in its chain will be returned.
type RenderOptions ¶
type RenderOptions struct {
// FileLinkFunc optionally specifies a function that
// returns a URL where file should be linked to.
// file is the name component of a .go file in the package,
// including the .go qualifier.
// As a special case, FileLinkFunc may return the empty
// string to indicate that a given file should not be linked.
FileLinkFunc func(file string) (url string)
SourceLinkFunc func(ast.Node) string
SinceVersionFunc func(name string) string
// ModInfo optionally specifies information about the module the package
// belongs to in order to render module-related documentation.
ModInfo *ModuleInfo
Limit int64 // If zero, a default limit of 10 megabytes is used.
BuildContext BuildContext
}
RenderOptions are options for Render.