newImageAsset applies what only holds for an image: the author may write alt text, and the fallback mirrors the web uploader by stripping the extension and replacing the remaining dots with spaces.
(f asset, alt string)
| 67 | // text, and the fallback mirrors the web uploader by stripping the extension |
| 68 | // and replacing the remaining dots with spaces. |
| 69 | func newImageAsset(f asset, alt string) (UserAsset, error) { |
| 70 | a := &imageAsset{f} |
| 71 | if err := checkMaxSize(a.asset, maxImageBytes, "images"); err != nil { |
| 72 | return nil, err |
| 73 | } |
| 74 | |
| 75 | if alt == "" { |
| 76 | base := filepath.Base(a.path) |
| 77 | alt = strings.ReplaceAll(strings.TrimSuffix(base, filepath.Ext(base)), ".", " ") |
| 78 | } |
| 79 | a.alt = alt |
| 80 | |
| 81 | if err := checkAltStaysInside(a); err != nil { |
| 82 | return nil, err |
| 83 | } |
| 84 | |
| 85 | return a, nil |
| 86 | } |
| 87 | |
| 88 | func (a *imageAsset) markdown(assetURL string) string { |
| 89 | return fmt.Sprintf("", escapeAlt(a.alt), assetURL) |
no test coverage detected