supportedContentType maps a file extension to the content type the endpoint expects. The extension is all gh checks, since the endpoint accepts mislabeled bytes anyway.
(path string)
| 170 | // expects. The extension is all gh checks, since the endpoint accepts |
| 171 | // mislabeled bytes anyway. |
| 172 | func supportedContentType(path string) (string, error) { |
| 173 | ext := strings.ToLower(filepath.Ext(path)) |
| 174 | for _, t := range contentTypes { |
| 175 | if t.ext == ext { |
| 176 | return t.contentType, nil |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | supported := make([]string, len(contentTypes)) |
| 181 | for i, t := range contentTypes { |
| 182 | supported[i] = strings.TrimPrefix(t.ext, ".") |
| 183 | } |
| 184 | return "", fmt.Errorf("%s is not a supported file type (supported: %s)", path, strings.Join(supported, ", ")) |
| 185 | } |
| 186 | |
| 187 | // altEscaper neutralizes the characters that let alt text break out of the |
| 188 | // image syntax. Without it, alt text containing `](url)` closes the image early |