ExtractWikilinks returns unique [[wikilink]] targets, ignoring code.
(body string)
| 99 | |
| 100 | // ExtractWikilinks returns unique [[wikilink]] targets, ignoring code. |
| 101 | func ExtractWikilinks(body string) []string { |
| 102 | if !strings.Contains(body, "[[") { |
| 103 | return []string{} |
| 104 | } |
| 105 | stripped := stripCodeContent(body) |
| 106 | seen := map[string]bool{} |
| 107 | out := []string{} |
| 108 | for _, m := range wikilinkRe.FindAllStringSubmatch(stripped, -1) { |
| 109 | if len(m) >= 3 { |
| 110 | bang := m[1] |
| 111 | target := strings.TrimSpace(m[2]) |
| 112 | if target == "" { |
| 113 | continue |
| 114 | } |
| 115 | if bang == "!" && localAssetTargetKind(target) != "" { |
| 116 | continue |
| 117 | } |
| 118 | if !seen[target] { |
| 119 | seen[target] = true |
| 120 | out = append(out, target) |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | return out |
| 125 | } |
| 126 | |
| 127 | // BodyHasLocalAsset is the same cheap heuristic as the TS version. |
| 128 | func BodyHasLocalAsset(body string) bool { |