MCPcopy Create free account
hub / github.com/cli/cli / appendUnreferenced

Function appendUnreferenced

internal/attachments/attach.go:243–258  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
243func 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.
261func appendParagraph(md, addition string) string {

Callers 1

attachMethod · 0.85

Calls 3

appendParagraphFunction · 0.85
PathMethod · 0.65
markdownMethod · 0.65

Tested by

no test coverage detected