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

Function linkReferenceDefinitions

internal/attachments/references.go:317–335  ·  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

315// destination. One inside a code fence or a code span is not parsed as a
316// definition at all, so both are excluded for free.
317func linkReferenceDefinitions(doc ast.Node, size int) map[string][]*ast.LinkReferenceDefinition {
318 out := map[string][]*ast.LinkReferenceDefinition{}
319 _ = ast.Walk(doc, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
320 if !entering {
321 return ast.WalkContinue, nil
322 }
323 def, ok := n.(*ast.LinkReferenceDefinition)
324 if !ok {
325 return ast.WalkContinue, nil
326 }
327 if _, _, ok := blockRange(def, size); !ok {
328 return ast.WalkContinue, nil
329 }
330 key := comparableDestination(string(def.Destination))
331 out[key] = append(out[key], def)
332 return ast.WalkContinue, nil
333 })
334 return out
335}
336
337// attachmentArgsByPath indexes the attached files by absolute path, ready for
338// 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