MCPcopy Create free account
hub / github.com/cli/cli / isSingleImage

Function isSingleImage

internal/attachments/references.go:797–810  ·  view source on GitHub ↗

isSingleImage reports whether src is one image pointing at wantURL and nothing besides. Asset validation uses it to confirm that escaped alt text cannot restructure the markdown it is placed in.

(src, wantURL string)

Source from the content-addressed store, hash-verified

795// nothing besides. Asset validation uses it to confirm that escaped alt text
796// cannot restructure the markdown it is placed in.
797func isSingleImage(src, wantURL string) bool {
798 doc := goldmark.New().Parser().Parse(text.NewReader([]byte(src)))
799
800 block := doc.FirstChild()
801 if block == nil || block.NextSibling() != nil {
802 return false
803 }
804 inline := block.FirstChild()
805 if inline == nil || inline.NextSibling() != nil {
806 return false
807 }
808 image, ok := inline.(*ast.Image)
809 return ok && string(image.Destination) == wantURL
810}

Callers 2

TestIsSingleImageFunction · 0.85
checkAltStaysInsideFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIsSingleImageFunction · 0.68