appendUnreferenced adds a paragraph for every attachment the author never referenced, in the order they were attached. Each one renders itself, since an image appends a markdown embed and a video appends a bare URL so that it plays, which is why this half does not live with the rewriting.
(attachedMD attachedMarkdown, assets []UserAsset)
| 241 | // an image appends a markdown embed and a video appends a bare URL so that it |
| 242 | // plays, which is why this half does not live with the rewriting. |
| 243 | func appendUnreferenced(attachedMD attachedMarkdown, assets []UserAsset) string { |
| 244 | urlByPath := make(map[string]string, len(attachedMD.ToAppend)) |
| 245 | for _, arg := range attachedMD.ToAppend { |
| 246 | urlByPath[arg.Path] = arg.URL |
| 247 | } |
| 248 | |
| 249 | out := attachedMD.Rewritten |
| 250 | for _, a := range assets { |
| 251 | url, ok := urlByPath[a.Path()] |
| 252 | if !ok { |
| 253 | continue |
| 254 | } |
| 255 | out = appendParagraph(out, a.markdown(url)) |
| 256 | } |
| 257 | return out |
| 258 | } |
| 259 | |
| 260 | // appendParagraph joins two pieces of markdown as separate paragraphs. |
| 261 | func appendParagraph(md, addition string) string { |
no test coverage detected