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)
| 478 | // A reference-style link carries no destination beside it and reports false, |
| 479 | // leaving it to the definitions. hi bounds the search to the block. |
| 480 | func inlineRanges(src []byte, n ast.Node, hi int) (refRanges, bool) { |
| 481 | start := n.Pos() |
| 482 | if start < 0 || start >= hi { |
| 483 | return refRanges{}, false |
| 484 | } |
| 485 | open := start |
| 486 | if src[open] == '!' { |
| 487 | open++ |
| 488 | } |
| 489 | if open >= hi || src[open] != '[' { |
| 490 | return refRanges{}, false |
| 491 | } |
| 492 | close, ok := closingBracket(src, open, hi, literalText(n)) |
| 493 | if !ok || close+1 >= hi || src[close+1] != '(' { |
| 494 | return refRanges{}, false |
| 495 | } |
| 496 | dest := inlineDestination(src, close+2, hi) |
| 497 | stop := skipSpace(src, dest.stop, hi) |
| 498 | if stop < hi && src[stop] != ')' { |
| 499 | if end, ok := scanTitle(src, stop, hi); ok { |
| 500 | stop = skipSpace(src, end, hi) |
| 501 | } |
| 502 | } |
| 503 | if stop >= hi || src[stop] != ')' { |
| 504 | return refRanges{}, false |
| 505 | } |
| 506 | return refRanges{ |
| 507 | node: byteRange{start, stop + 1}, |
| 508 | label: byteRange{open + 1, close}, |
| 509 | dest: dest, |
| 510 | }, true |
| 511 | } |
| 512 | |
| 513 | // closingBracket finds the "]" that ends a label opened at open, counting the |
| 514 | // brackets of anything nested inside it and ignoring those in literal. |
no test coverage detected