Source File
overview.go
Belonging Package
golang.org/x/pkgsite/internal/frontend
package frontend
import (
)
:= &bytes.Buffer{}
:= bytes.ReplaceAll([]byte(.Contents), []byte("\r"), nil)
:= .Parse()
var error
.Walk(func( *blackfriday.Node, bool) blackfriday.WalkStatus {
switch .Type {
case blackfriday.Heading:
.HeadingID = "readme-" + .HeadingID
}
case blackfriday.Image, blackfriday.Link:
:= .Type == blackfriday.Image
if := translateLink(string(.LinkData.Destination), .SourceInfo, , ); != "" {
.LinkData.Destination = []byte()
}
case blackfriday.HTMLBlock, blackfriday.HTMLSpan:
, := translateHTML(.Literal, .SourceInfo, )
if != nil {
= fmt.Errorf("couldn't transform html block(%s): %w", .Literal, )
return blackfriday.Terminate
}
.Literal =
}
return .RenderNode(, , )
})
if != nil {
return safehtml.HTML{},
}
return legacySanitizeHTML(), nil
}
func ( context.Context, *internal.ModuleInfo, *internal.Readme) ( safehtml.HTML, error) {
defer derrors.Wrap(&, "LegacyReadmeHTML(%s@%s)", .ModulePath, .Version)
if == nil || .Contents == "" {
return safehtml.HTML{}, nil
}
if !isMarkdown(.Filepath) {
:= template.Must(template.New("").Parse(`<pre class="readme">{{.}}</pre>`))
, := .ExecuteToHTML(.Contents)
if != nil {
return safehtml.HTML{},
}
return , nil
}
return blackfridayReadmeHTML(, )
}
:= bluemonday.UGCPolicy()
.AllowAttrs("width", "align").OnElements("img")
.AllowAttrs("width", "align").OnElements("div")
.AllowAttrs("width", "align").OnElements("p")
return == ".md" || == ".markdown"
}
return "#readme-" + .Fragment
if .FirstChild == nil || .FirstChild.NextSibling == nil || .FirstChild.NextSibling.DataAtom != atom.Body {
return , nil
}
return , nil
}
func ( *html.Node, *source.Info, *internal.Readme) bool {
:= false
if .Type == html.ElementNode && .DataAtom == atom.Img {
var []html.Attribute
for , := range .Attr {
if .Key == "src" {
if := translateLink(.Val, , true, ); != "" {
.Val =
= true
}
}
= append(, )
}
.Attr =
}
for := .FirstChild; != nil; = .NextSibling {
if (, , ) {
= true
}
}
return
![]() |
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. |