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

Function applyFrontmatterLineTransform

pkg/cli/yaml_frontmatter_utils.go:111–124  ·  view source on GitHub ↗

applyFrontmatterLineTransform parses frontmatter from content, applies a transform function to the frontmatter lines, and reconstructs the content if any changes were made. The transform function receives the frontmatter lines and returns the modified lines and a boolean indicating whether any chang

(content string, transform func([]string) ([]string, bool))

Source from the content-addressed store, hash-verified

109// The transform function receives the frontmatter lines and returns the modified lines
110// and a boolean indicating whether any changes were made.
111func applyFrontmatterLineTransform(content string, transform func([]string) ([]string, bool)) (string, bool, error) {
112 frontmatterLines, markdown, err := parseFrontmatterLines(content)
113 if err != nil {
114 return content, false, err
115 }
116
117 result, modified := transform(frontmatterLines)
118 if !modified {
119 return content, false, nil
120 }
121
122 yamlUtilsLog.Print("Frontmatter transformation applied successfully")
123 return reconstructContent(result, markdown), true, nil
124}
125
126// removeParentBlockIfTrulyEmpty removes a bare "parentBlock:" header line only
127// when there are no nested lines at all underneath it — not even comments.

Calls 3

parseFrontmatterLinesFunction · 0.85
reconstructContentFunction · 0.85
PrintMethod · 0.80

Tested by 1