|
14 | 14 | from itertools import chain |
15 | 15 | from pathlib import Path |
16 | 16 |
|
17 | | -from lxml import etree |
18 | | - |
19 | 17 | from style_variant_builder.prune import CSLPruner |
20 | 18 |
|
21 | 19 | logging.basicConfig(level=logging.INFO, format="%(message)s") |
@@ -140,42 +138,13 @@ def _prune_variant(self, patched_file: Path, output_variant: Path) -> None: |
140 | 138 | # Flatten single-macro layouts before pruning so wrapper macros can be removed |
141 | 139 | pruner.flatten_layout_macros() |
142 | 140 | pruner.prune_macros() |
143 | | - self._insert_notice_comment_xml(pruner) |
144 | | - pruner.save() |
145 | | - |
146 | | - def _insert_notice_comment_xml(self, pruner: CSLPruner) -> None: |
147 | | - """Insert a contribution notice comment as the first child of the <style> element.""" |
148 | | - if pruner.root is None: |
149 | | - logging.error("Cannot insert notice comment: XML root is None.") |
150 | | - return |
151 | | - |
152 | | - comment_node = etree.Comment( |
153 | | - " This file was generated by the Style Variant Builder " |
| 141 | + # Set notice comment to be inserted during save |
| 142 | + pruner.notice_comment = ( |
| 143 | + "This file was generated by the Style Variant Builder " |
154 | 144 | "<https://github.com/citation-style-language/style-variant-builder>. " |
155 | | - "To contribute changes, modify the template and regenerate variants. " |
| 145 | + "To contribute changes, modify the template and regenerate variants." |
156 | 146 | ) |
157 | | - # Insert as the first child of the root <style> element |
158 | | - pruner.root.insert(0, comment_node) |
159 | | - # Insert a tail newline and indentation after the comment to ensure separation and correct indentation for <info> |
160 | | - # Detect the indentation used for children of <style> |
161 | | - if len(pruner.root) > 1: |
162 | | - # Try to infer indentation from the first real element (usually <info>) |
163 | | - next_elem = pruner.root[1] |
164 | | - # Find the preceding text (indentation) for the <info> element |
165 | | - # Default to 2 spaces if not found |
166 | | - indent = " " |
167 | | - # Try to find the indentation from the previous tail or from the element itself |
168 | | - if next_elem.tail and next_elem.tail.lstrip("\n") != next_elem.tail: |
169 | | - # If tail starts with a newline, use the rest as indent |
170 | | - indent = next_elem.tail.split("\n")[-1] |
171 | | - elif ( |
172 | | - pruner.root.text |
173 | | - and pruner.root.text.lstrip("\n") != pruner.root.text |
174 | | - ): |
175 | | - indent = pruner.root.text.split("\n")[-1] |
176 | | - pruner.root[0].tail = f"\n{indent}" |
177 | | - else: |
178 | | - pruner.root[0].tail = "\n " |
| 147 | + pruner.save() |
179 | 148 |
|
180 | 149 | def build_variants(self) -> tuple[int, int]: |
181 | 150 | try: |
|
0 commit comments