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

Function linkReferenceDefinitions

internal/attachments/references.go:303–321  ·  view source on GitHub ↗

linkReferenceDefinitions indexes every one in the document by its destination. One inside a code fence or a code span is not parsed as a definition at all, so both are excluded for free.

(doc ast.Node, size int)

Source from the content-addressed store, hash-verified

301// destination. One inside a code fence or a code span is not parsed as a
302// definition at all, so both are excluded for free.
303func linkReferenceDefinitions(doc ast.Node, size int) map[string][]*ast.LinkReferenceDefinition {
304 out := map[string][]*ast.LinkReferenceDefinition{}
305 _ = ast.Walk(doc, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
306 if !entering {
307 return ast.WalkContinue, nil
308 }
309 def, ok := n.(*ast.LinkReferenceDefinition)
310 if !ok {
311 return ast.WalkContinue, nil
312 }
313 if _, _, ok := blockRange(def, size); !ok {
314 return ast.WalkContinue, nil
315 }
316 key := comparableDestination(string(def.Destination))
317 out[key] = append(out[key], def)
318 return ast.WalkContinue, nil
319 })
320 return out
321}
322
323// attachmentArgsByPath indexes the attached files by absolute path, ready for
324// attachmentArgForDestination to look one up. An argument with no URL is

Callers 1

scanMarkdownRefsFunction · 0.85

Calls 2

blockRangeFunction · 0.85
comparableDestinationFunction · 0.85

Tested by

no test coverage detected