BodyHasLocalAsset is the same cheap heuristic as the TS version.
(body string)
| 126 | |
| 127 | // BodyHasLocalAsset is the same cheap heuristic as the TS version. |
| 128 | func BodyHasLocalAsset(body string) bool { |
| 129 | if !strings.Contains(body, "](") && !strings.Contains(body, "![[") { |
| 130 | return false |
| 131 | } |
| 132 | stripped := stripCodeContent(body) |
| 133 | for _, m := range linkRe.FindAllStringSubmatch(stripped, -1) { |
| 134 | if len(m) < 3 { |
| 135 | continue |
| 136 | } |
| 137 | href := strings.TrimSpace(m[2]) |
| 138 | if href == "" || strings.HasPrefix(href, "#") || strings.HasPrefix(href, "//") { |
| 139 | continue |
| 140 | } |
| 141 | if matched, _ := regexpMatchScheme(href); matched { |
| 142 | continue |
| 143 | } |
| 144 | if localAssetTargetKind(href) != "" { |
| 145 | return true |
| 146 | } |
| 147 | } |
| 148 | for _, m := range embedRe.FindAllStringSubmatch(stripped, -1) { |
| 149 | if len(m) < 2 { |
| 150 | continue |
| 151 | } |
| 152 | if localAssetTargetKind(strings.TrimSpace(m[1])) != "" { |
| 153 | return true |
| 154 | } |
| 155 | } |
| 156 | return false |
| 157 | } |
| 158 | |
| 159 | var schemeRe = regexp.MustCompile(`^[a-zA-Z][a-zA-Z\d+.\-]*:`) |
| 160 |