Back to

Package dochtml

v0.0.0 (f17b25a)
Latest Go to latest
Published: today | License: BSD-3-Clause | Module:


Package dochtml renders Go package documentation into HTML.

This package and its API are under development (see 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.


Package Files


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")

func Render

func Render(ctx context.Context, fset *token.FileSet, p *doc.Package, opt RenderOptions) (safehtml.HTML, error)

Render renders package documentation HTML for the provided file set and package.

If the rendered documentation HTML size exceeds the specified limit, an error with ErrTooLarge in its chain will be returned.

func WalkExamples

func WalkExamples(p *doc.Package, fn func(id string, ex *doc.Example))

WalkExamples calls fn for each Example in p, setting id to the name of the parent structure.

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 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
	// 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.

RenderOptions are options for Render.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier