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))
| 109 | // The transform function receives the frontmatter lines and returns the modified lines |
| 110 | // and a boolean indicating whether any changes were made. |
| 111 | func 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. |