|
1 | 1 | import contextlib |
2 | 2 | import datetime |
3 | 3 | import os |
| 4 | +import re |
4 | 5 | import time |
5 | 6 | from functools import cached_property, total_ordering |
6 | 7 | import enum |
@@ -50,6 +51,25 @@ def decorated(*args, **kwargs): |
50 | 51 | class _WrappedAttributeError(Exception): pass |
51 | 52 |
|
52 | 53 |
|
| 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 | + |
53 | 73 | class DashboardObject: |
54 | 74 | """Base wrapper for a dashboard object. |
55 | 75 |
|
@@ -777,12 +797,15 @@ def _refresh_branch_info(self): |
777 | 797 | def get_release_status(self): |
778 | 798 | state = DashboardState(self) |
779 | 799 |
|
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 | + ) |
785 | 807 | ) |
786 | 808 |
|
| 809 | + |
787 | 810 | def get_release_status_app(buildernames=None, **kwargs): |
788 | 811 | return ReleaseDashboard(**kwargs).flask_app |
0 commit comments