(match)
| 12 | """ |
| 13 | |
| 14 | def include_replacer(match): |
| 15 | indentation = match.group(1) # Capture the indentation |
| 16 | prefix = match.group(2) # What comes before !include (like "<<: " or "key: ") |
| 17 | include_path = match.group(3) |
| 18 | full_path = base_dir / include_path |
| 19 | |
| 20 | included_content = full_path.read_text().strip() |
| 21 | |
| 22 | # Handle merge key specially |
| 23 | if prefix.strip() == "<<:": |
| 24 | # For merge keys, include the content with proper indentation |
| 25 | if indentation: |
| 26 | content_indent = indentation + " " |
| 27 | included_lines = included_content.splitlines() |
| 28 | indented_lines = [content_indent + line if line.strip() else line for line in included_lines] |
| 29 | return indentation + "<<:\n" + "\n".join(indented_lines) |
| 30 | else: |
| 31 | # Indent the included content by 2 spaces for proper merge format |
| 32 | included_lines = included_content.splitlines() |
| 33 | indented_lines = [" " + line if line.strip() else line for line in included_lines] |
| 34 | return "<<:\n" + "\n".join(indented_lines) |
| 35 | else: |
| 36 | # For regular includes, we need to handle indentation properly |
| 37 | # If the prefix ends with ': ', we need to add a newline and indent the content |
| 38 | if prefix.strip().endswith(":"): |
| 39 | # Calculate the indentation for the included content |
| 40 | content_indent = indentation + " " # Add 2 spaces for proper YAML nesting |
| 41 | included_lines = included_content.splitlines() |
| 42 | indented_lines = [content_indent + line if line.strip() else line for line in included_lines] |
| 43 | return indentation + prefix.strip() + "\n" + "\n".join(indented_lines) |
| 44 | else: |
| 45 | # For cases where it's not a key assignment, just replace with content |
| 46 | return indentation + prefix + included_content |
| 47 | |
| 48 | # Pattern to match !include directives with proper capture groups |
| 49 | # Group 1: indentation, Group 2: prefix (like "<<: " or "key: "), Group 3: file path |
nothing calls this directly
no outgoing calls
no test coverage detected