Source File
readme.go
Belonging Package
golang.org/x/pkgsite/internal/frontend
package frontend
import (
emoji
goldmarkHtml
gmtext
)
func ( context.Context, *internal.Unit) ( *Readme, error) {
defer derrors.WrapAndReport(&, "ProcessReadme(%q, %q, %q)", .Path, .ModulePath, .Version)
return processReadme(, .Readme, .SourceInfo)
}
func ( context.Context, *internal.Readme, *source.Info) ( *Readme, error) {
if == nil || .Contents == "" {
return &Readme{}, nil
}
if !isMarkdown(.Filepath) {
:= template.Must(template.New("").Parse(`<pre class="readme">{{.}}</pre>`))
, := .ExecuteToHTML(.Contents)
if != nil {
return nil,
}
return &Readme{HTML: }, nil
}
const = 10000
:= &extractLinks{ctx: }
:= &extractTOC{ctx: , removeTitle: true}
:= goldmark.New(
util.Prioritized(, +1),
util.Prioritized(, +1),
),
goldmark.WithRendererOptions(goldmarkHtml.WithUnsafe(), goldmarkHtml.WithXHTML()),
goldmark.WithExtensions(
extension.GFM, // Support Github Flavored Markdown.
emoji.Emoji, // Support Github markdown emoji markup.
),
)
.Renderer().AddOptions(
renderer.WithNodeRenderers(
util.Prioritized(newHTMLRenderer(, ), 100),
),
)
:= []byte(.Contents)
:= .Parser()
:= gmtext.NewReader()
:= parser.NewContext(parser.WithIDs(newIDs()))
:= .Parse(, parser.WithContext())
:= .Renderer()
var bytes.Buffer
if := .Render(&, , ); != nil {
return &Readme{}, nil
}
return &Readme{
HTML: sanitizeHTML(&),
Outline: .Headings,
Links: .links,
}, nil
}
func ( *bytes.Buffer) safehtml.HTML {
:= bluemonday.UGCPolicy()
.AllowAttrs("width", "align").OnElements("img")
.AllowAttrs("width", "align").OnElements("div")
.AllowAttrs("width", "align", "role", "aria-level").OnElements("div")
.AllowAttrs("class").OnElements()
}
:= string(.SanitizeBytes(.Bytes()))
return uncheckedconversions.HTMLFromStringKnownToSatisfyTypeContract()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |