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

Function inlineRanges

internal/attachments/references.go:517–548  ·  view source on GitHub ↗

inlineRanges locates the source of an inline link or image. goldmark reports where every inline node starts, so the only thing left to find is where it ends, inside a node goldmark has already accepted. A reference-style link carries no destination beside it and reports false, leaving it to the def

(src []byte, n ast.Node, hi int)

Source from the content-addressed store, hash-verified

515// A reference-style link carries no destination beside it and reports false,
516// leaving it to the definitions. hi bounds the search to the block.
517func inlineRanges(src []byte, n ast.Node, hi int) (refRanges, bool) {
518 start := n.Pos()
519 if start < 0 || start >= hi {
520 return refRanges{}, false
521 }
522 open := start
523 if src[open] == '!' {
524 open++
525 }
526 if open >= hi || src[open] != '[' {
527 return refRanges{}, false
528 }
529 close, ok := closingBracket(src, open, hi, literalText(n))
530 if !ok || close+1 >= hi || src[close+1] != '(' {
531 return refRanges{}, false
532 }
533 dest := inlineDestination(src, close+2, hi)
534 stop := skipSpace(src, dest.stop, hi)
535 if stop < hi && src[stop] != ')' {
536 if end, ok := scanTitle(src, stop, hi); ok {
537 stop = skipSpace(src, end, hi)
538 }
539 }
540 if stop >= hi || src[stop] != ')' {
541 return refRanges{}, false
542 }
543 return refRanges{
544 node: byteRange{start, stop + 1},
545 label: byteRange{open + 1, close},
546 dest: dest,
547 }, true
548}
549
550// closingBracket finds the "]" that ends a label opened at open, counting the
551// brackets of anything nested inside it and ignoring those in literal.

Callers 1

scanMarkdownRefsFunction · 0.85

Calls 5

closingBracketFunction · 0.85
literalTextFunction · 0.85
inlineDestinationFunction · 0.85
skipSpaceFunction · 0.85
scanTitleFunction · 0.85

Tested by

no test coverage detected