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)
| 59 | // an image appends a markdown embed and a video appends a bare URL so that it |
| 60 | // plays, which is why this half does not live with the rewriting. |
| 61 | func appendUnreferenced(attachedMD attachedMarkdown, assets []UserAsset) string { |
| 62 | urlByPath := make(map[string]string, len(attachedMD.ToAppend)) |
| 63 | for _, arg := range attachedMD.ToAppend { |
| 64 | urlByPath[arg.Path] = arg.URL |
| 65 | } |
| 66 | |
| 67 | out := attachedMD.Rewritten |
| 68 | for _, a := range assets { |
| 69 | url, ok := urlByPath[a.Path()] |
| 70 | if !ok { |
| 71 | continue |
| 72 | } |
| 73 | out = appendParagraph(out, a.markdown(url)) |
| 74 | } |
| 75 | return out |
| 76 | } |
| 77 | |
| 78 | // appendParagraph joins two pieces of markdown as separate paragraphs. |
| 79 | func appendParagraph(md, addition string) string { |
no test coverage detected