func Render(fset *token.FileSet, p *doc.Package, opt RenderOptions) (string, error) {
	if opt.Limit == 0 {
		const megabyte = 1000 * 1000
		opt.Limit = 10 * megabyte
	}

	// Make a copy to avoid modifying caller's *doc.Package.
	p2 := *p
	p = &p2

	// When rendering documentation for commands, display
	// the package comment and notes, but no declarations.
	if p.Name == "main" {
		// Clear top-level declarations.
		p.Consts = nil
		p.Types = nil
		p.Vars = nil
		p.Funcs = nil
		p.Examples = nil
	}

	// Remove everything from the notes section that is not a bug. This
	// includes TODOs and other arbitrary notes.
	for k := range p.Notes {
		if k == "BUG" {
			continue
		}
		delete(p.Notes, k)
	}

	r := render.New(fset, p, &render.Options{
		PackageURL: func(path string) (url string) {
			return pathpkg.Join("/pkg", path)
		},
		DisableHotlinking: true,
	})

	fileLink := func(name string) template.HTML {
		return fileLinkHTML(name, opt.FileLinkFunc(name))
	}
	sourceLink := func(name string, node ast.Node) template.HTML {
		link := opt.SourceLinkFunc(node)
		if link == "" {
			return template.HTML(name)
		}
		return template.HTML(fmt.Sprintf(`<a class="Documentation-source" href="%s">%s</a>`, link, name))
	}
	playURLFunc := opt.PlayURLFunc
	if playURLFunc == nil {
		playURLFunc = func(*doc.Example) string {
			return ""
		}
	}
	buf := &limitBuffer{
		B:      new(bytes.Buffer),
		Remain: opt.Limit,
	}
	err := template.Must(htmlPackage.Clone()).Funcs(map[string]interface{}{
		"render_short_synopsis": r.ShortSynopsis,
		"render_synopsis":       r.Synopsis,
		"render_doc":            r.DocHTML,
		"render_decl":           r.DeclHTML,
		"render_code":           r.CodeHTML,
		"file_link":             fileLink,
		"source_link":           sourceLink,
		"play_url":              playURLFunc,
	}).Execute(buf, struct {
		RootURL string
		*doc.Package
		Examples *examples
	}{
		RootURL:  "/pkg",
		Package:  p,
		Examples: collectExamples(p),
	})
	if buf.Remain < 0 {
		return "", fmt.Errorf("dochtml.Render: %w", ErrTooLarge)
	} else if err != nil {
		return "", fmt.Errorf("dochtml.Render: %v", err)
	}
	return buf.B.String(), nil
}
// 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.
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.
// 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 Render(fset *token.FileSet, p *doc.Package, opt RenderOptions) (string, error) {
	if opt.Limit == 0 {
		const megabyte = 1000 * 1000
		opt.Limit = 10 * megabyte
	}
	p2 := *p
	p = &p2
	if p.Name == "main" {
		p.Consts = nil
		p.Types = nil
		p.Vars = nil
		p.Funcs = nil
		p.Examples = nil
	}
	for k := range p.Notes {
		if k == "BUG" {
			continue
		}
		delete(p.Notes, k)
	}
	r := render.New(fset, p, &render.Options{
		PackageURL: func(path string) (url string) {
			return pathpkg.Join("/pkg", path)
		},
		DisableHotlinking: true,
	})
	fileLink := func(name string) template.HTML {
		return fileLinkHTML(name, opt.FileLinkFunc(name))
	}
	sourceLink := func(name string, node ast.Node) template.HTML {
		link := opt.SourceLinkFunc(node)
		if link == "" {
			return template.HTML(name)
		}
		return template.HTML(fmt.Sprintf(`<a class="Documentation-source" href="%s">%s</a>`, link, name))
	}
	playURLFunc := opt.PlayURLFunc
	if playURLFunc == nil {
		playURLFunc = func(*doc.Example) string {
			return ""
		}
	}
	buf := &limitBuffer{
		B:      new(bytes.Buffer),
		Remain: opt.Limit,
	}
	err := template.Must(htmlPackage.Clone()).Funcs(map[string]interface{}{
		"render_short_synopsis": r.ShortSynopsis,
		"render_synopsis":       r.Synopsis,
		"render_doc":            r.DocHTML,
		"render_decl":           r.DeclHTML,
		"render_code":           r.CodeHTML,
		"file_link":             fileLink,
		"source_link":           sourceLink,
		"play_url":              playURLFunc,
	}).Execute(buf, struct {
		RootURL string
		*doc.Package
		Examples *examples
	}{
		RootURL:  "/pkg",
		Package:  p,
		Examples: collectExamples(p),
	})
	if buf.Remain < 0 {
		return "", fmt.Errorf("dochtml.Render: %w", ErrTooLarge)
	} else if err != nil {
		return "", fmt.Errorf("dochtml.Render: %v", err)
	}
	return buf.B.String(), nil
}
func Render ( fset * token . FileSet , p * doc . Package , opt RenderOptions ) ( string , error ) { if opt . Limit == 0 { const megabyte = 1000 * 1000 opt . Limit = 10 * megabyte } p2 := * p p = & p2 if p . Name == " " { p . Consts = nil p . Types = nil p . Vars = nil p . Funcs = nil p . Examples = nil } for k := range p . Notes { if k == " " { continue } delete ( p . Notes , k ) } r := render . New ( fset , p , & render . Options { PackageURL : func ( path string ) ( url string ) { return pathpkg . Join ( " " , path ) } , DisableHotlinking : true , } ) fileLink := func ( name string ) template . HTML { return fileLinkHTML ( name , opt . FileLinkFunc ( name ) ) } sourceLink := func ( name string , node ast . Node ) template . HTML { link := opt . SourceLinkFunc ( node ) if link == " " { return template . HTML ( name ) } return template . HTML ( fmt . Sprintf ( `<a class="Documentation-source" href="%s">%s</a>` , link , name ) ) } playURLFunc := opt . PlayURLFunc if playURLFunc == nil { playURLFunc = func ( * doc . Example ) string { return " " } } buf := & limitBuffer { B : new ( bytes . Buffer ) , Remain : opt . Limit , } err := template . Must ( htmlPackage . Clone ( ) ) . Funcs ( map [ string ] interface { } { " " : r . ShortSynopsis , " " : r . Synopsis , " " : r . DocHTML , " " : r . DeclHTML , " " : r . CodeHTML , " " : fileLink , " " : sourceLink , " " : playURLFunc , } ) . Execute ( buf , struct { RootURL string * doc . Package Examples * examples } { RootURL : " " , Package : p , Examples : collectExamples ( p ) , } ) if buf . Remain < 0 { return " " , fmt . Errorf ( " " , ErrTooLarge ) } else if err != nil { return " " , fmt . Errorf ( " " , err ) } return buf . B . String ( ) , nil }
Render renders package documentation HTML for the
provided file set and package.
Render renders package documentation HTML for the provided file set and package .
// Make a copy to avoid modifying caller's *doc.Package. // When rendering documentation for commands, display // the package comment and notes, but no declarations. // Clear top-level declarations. // Remove everything from the notes section that is not a bug. This // includes TODOs and other arbitrary notes.