MCPcopy Create free account
hub / github.com/github/gh-aw / processIncludesForField

Function processIncludesForField

pkg/parser/include_expander.go:266–299  ·  view source on GitHub ↗

processIncludesForField processes import directives to extract a specific frontmatter field

(content, baseDir string, extractFunc func(string) (string, error), emptyValue string)

Source from the content-addressed store, hash-verified

264
265// processIncludesForField processes import directives to extract a specific frontmatter field
266func processIncludesForField(content, baseDir string, extractFunc func(string) (string, error), emptyValue string) ([]string, string, error) {
267 // Fast path: skip scanner allocation when no include/import directives are present.
268 if !hasIncludeDirectives(content) {
269 return nil, content, nil
270 }
271
272 scanner := bufio.NewScanner(strings.NewReader(content))
273 var result bytes.Buffer
274 var results []string
275
276 for scanner.Scan() {
277 line := scanner.Text()
278
279 // Parse import directive
280 directive := ParseImportDirective(line)
281 if directive != nil {
282 fieldJSON, shouldSkip, err := extractFieldFromDirectiveForField(directive, baseDir, extractFunc)
283 if err != nil {
284 return nil, "", err
285 }
286 if shouldSkip {
287 continue
288 }
289 if fieldJSON != "" && fieldJSON != emptyValue {
290 results = append(results, fieldJSON)
291 }
292 } else {
293 // Regular line, just pass through
294 result.WriteString(line + "\n")
295 }
296 }
297
298 return results, result.String(), nil
299}
300
301func extractFieldFromDirectiveForField(
302 directive *ImportDirectiveMatch,

Callers 1

expandIncludesForFieldFunction · 0.85

Calls 4

hasIncludeDirectivesFunction · 0.85
ParseImportDirectiveFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected