extractRuntimeImportPaths extracts all runtime-import file paths from markdown content. Returns a list of file paths (not URLs) referenced in {{#runtime-import}} macros. URLs (http:// or https://) are excluded since they are validated separately.
(markdownContent string)
| 38 | // Returns a list of file paths (not URLs) referenced in {{#runtime-import}} macros. |
| 39 | // URLs (http:// or https://) are excluded since they are validated separately. |
| 40 | func extractRuntimeImportPaths(markdownContent string) []string { |
| 41 | if markdownContent == "" { |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | var paths []string |
| 46 | seen := make(map[string]struct { |
| 47 | }) |
| 48 | |
| 49 | matches := runtimeImportMacroRe.FindAllStringSubmatch(markdownContent, -1) |
| 50 | |
| 51 | for _, match := range matches { |
| 52 | if len(match) > 1 { |
| 53 | pathWithRange := strings.TrimSpace(match[1]) |
| 54 | |
| 55 | // Skip macros with empty or whitespace-only targets |
| 56 | if pathWithRange == "" { |
| 57 | expressionValidationLog.Print("Skipping runtime-import macro with empty target") |
| 58 | continue |
| 59 | } |
| 60 | |
| 61 | // Remove line range if present (e.g., "file.md:10-20" -> "file.md") |
| 62 | importPath := pathWithRange |
| 63 | if colonIdx := strings.Index(pathWithRange, ":"); colonIdx > 0 { |
| 64 | // Check if what follows colon looks like a line range (digits-digits) |
| 65 | afterColon := pathWithRange[colonIdx+1:] |
| 66 | if lineRangeRe.MatchString(afterColon) { |
| 67 | importPath = pathWithRange[:colonIdx] |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // Skip URLs - they don't need file validation |
| 72 | if strings.HasPrefix(importPath, "http://") || strings.HasPrefix(importPath, "https://") { |
| 73 | continue |
| 74 | } |
| 75 | |
| 76 | // Add to list if not already seen |
| 77 | if !setutil.Contains(seen, importPath) { |
| 78 | paths = append(paths, importPath) |
| 79 | seen[importPath] = struct { |
| 80 | }{} |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return paths |
| 86 | } |
| 87 | |
| 88 | // validateRuntimeImportFiles validates expressions in all runtime-import files at compile time. |
| 89 | // This catches expression errors early, before the workflow runs. |