pkgsite: Index | Files | Directories

package dochtml

import ""

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

dochtml.go io.go legacy_body.go legacy_sidenav.go template.go template_body.go template_sidenav.go


const (
    IdentifierBodyStart = `<div class="Documentation-content js-docContent">`
    IdentifierBodyEnd   = `</div>`
const (
    IdentifierSidenavStart       = `<nav class="DocNav js-sideNav">`
    IdentifierSidenavMobileStart = `<nav class="DocNavMobile js-mobileNav">`
    IdentifierSidenavEnd         = `</nav>`


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 Uses

func Render(ctx context.Context, fset *token.FileSet, p *doc.Package, opt RenderOptions) (_ safehtml.HTML, err 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 Uses

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 Uses

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 Uses

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.


internal/renderPackage render formats Go documentation as HTML.

Package dochtml imports 20 packages (graph) and is imported by 1 packages. Updated 2020-10-28. Refresh now. Tools for package owners.