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

Function isSingleImage

internal/attachments/references.go:834–847  ·  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

832// nothing besides. Asset validation uses it to confirm that escaped alt text
833// cannot restructure the markdown it is placed in.
834func isSingleImage(src, wantURL string) bool {
835 doc := goldmark.New().Parser().Parse(text.NewReader([]byte(src)))
836
837 block := doc.FirstChild()
838 if block == nil || block.NextSibling() != nil {
839 return false
840 }
841 inline := block.FirstChild()
842 if inline == nil || inline.NextSibling() != nil {
843 return false
844 }
845 image, ok := inline.(*ast.Image)
846 return ok && string(image.Destination) == wantURL
847}

Callers 2

TestIsSingleImageFunction · 0.85
checkAltStaysInsideFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIsSingleImageFunction · 0.68