attachmentArgForDestination is where the two halves of this package meet: it takes a markdown destination and answers which attached file, if any, it names. Only a local path can name one, and markdown offers several spellings for the same path, so each is resolved to an absolute path and looked up
(dest string, byPath map[string]int)
| 348 | // Only a local path can name one, and markdown offers several spellings for |
| 349 | // the same path, so each is resolved to an absolute path and looked up. |
| 350 | func attachmentArgForDestination(dest string, byPath map[string]int) (int, bool) { |
| 351 | if dest == "" || strings.HasPrefix(dest, "#") || isRemoteDestination(dest) { |
| 352 | return 0, false |
| 353 | } |
| 354 | for _, path := range candidatePaths(dest) { |
| 355 | abs, err := filepath.Abs(path) |
| 356 | if err != nil { |
| 357 | continue |
| 358 | } |
| 359 | if i, ok := byPath[abs]; ok { |
| 360 | return i, true |
| 361 | } |
| 362 | } |
| 363 | return 0, false |
| 364 | } |
| 365 | |
| 366 | // isRemoteDestination reports whether a destination addresses somewhere other |
| 367 | // than the filesystem, so that an attached file is never confused with a URI. |
no test coverage detected