Skip to content

Commit da143f1

Browse files
committed
Adjust GCOVR_TREE_DATA injection
1 parent f94b90c commit da143f1

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

gcovr-templates/html/base.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
</footer>
125125
</main>
126126
</div>
127+
<script>
128+
window.GCOVR_TREE_DATA = {{ GCOVR_TREE_DATA | default([]) | tojson | safe }};
129+
</script>
127130
</body>
128131

129132
</html>

scripts/gcovr_build_tree.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ def inject_tree_data(output_dir, tree):
193193

194194
original = content
195195

196-
# Replace existing tree data if present
197-
if 'window.GCOVR_TREE_DATA=' in content:
196+
if 'window.GCOVR_TREE_DATA' in content:
197+
# Replace existing tree data if present
198198
content = re.sub(
199-
r'<script>window\.GCOVR_TREE_DATA=.*?;</script>',
200-
tree_script, content)
199+
r'<script>\s*window\.GCOVR_TREE_DATA\s*=\s*.*?;\s*</script>',
200+
tree_script, content, flags=re.DOTALL)
201201
elif '</body>' in content:
202-
# Inject before </body> if not present
202+
# First-time injection
203203
content = content.replace('</body>', f'{tree_script}\n</body>')
204204

205205
if content != original:

0 commit comments

Comments
 (0)