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)
| 795 | // nothing besides. Asset validation uses it to confirm that escaped alt text |
| 796 | // cannot restructure the markdown it is placed in. |
| 797 | func 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 | } |
no outgoing calls