Skip to content

Commit 0866ca1

Browse files
committed
Strip indentation of release dashboard HTML
1 parent 662a9e3 commit 0866ca1

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

‎master/custom/release_dashboard.py‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import datetime
33
import os
4+
import re
45
import time
56
from functools import cached_property, total_ordering
67
import enum
@@ -50,6 +51,25 @@ def decorated(*args, **kwargs):
5051
class _WrappedAttributeError(Exception): pass
5152

5253

54+
_PRE_BLOCK_RE = re.compile(r"(<pre\b.*?</pre>)", re.DOTALL)
55+
56+
57+
def strip_indentation(html):
58+
"""Remove line indentation and blank lines, except inside <pre> blocks.
59+
60+
The template is deeply indented for readability, and that indentation
61+
makes up more than half of the rendered page. Browsers collapse
62+
whitespace between tags anyway, so this doesn't change how the page
63+
renders. Only <pre> content is whitespace-sensitive and is left alone.
64+
"""
65+
parts = _PRE_BLOCK_RE.split(html)
66+
for i in range(0, len(parts), 2):
67+
lines = map(str.lstrip, parts[i].split("\n"))
68+
parts[i] = "\n".join(line for line in lines if line)
69+
70+
return "\n".join(parts)
71+
72+
5373
class DashboardObject:
5474
"""Base wrapper for a dashboard object.
5575
@@ -777,12 +797,15 @@ def _refresh_branch_info(self):
777797
def get_release_status(self):
778798
state = DashboardState(self)
779799

780-
return render_template(
781-
"releasedashboard.html",
782-
state=state,
783-
Severity=Severity,
784-
generated_at=state.now,
800+
return strip_indentation(
801+
render_template(
802+
"releasedashboard.html",
803+
state=state,
804+
Severity=Severity,
805+
generated_at=state.now,
806+
)
785807
)
786808

809+
787810
def get_release_status_app(buildernames=None, **kwargs):
788811
return ReleaseDashboard(**kwargs).flask_app

0 commit comments

Comments
 (0)