Skip to content

Commit 13a07d2

Browse files
committed
Render multiline descriptions nicely
Fix rendering of description field which has multiple lines. Now it looks like this: https://tmt.testing-farm.io/?test-url=https://gitlab.com/testing-farm/tests&test-name=/container/build With these changes, it renders this way: https://imgur.com/a/S5cRLOj Generated-by: Claude Code <noreply@claude.com> Signed-off-by: Miroslav Vadkerti <mvadkert@redhat.com>
1 parent 5735021 commit 13a07d2

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

src/tmt_web/templates/_base.html.j2

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,27 @@ licensed under CC-BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/).
155155
color: var(--fedora-dark);
156156
font-weight: 600;
157157
}
158+
159+
.description {
160+
margin: 0.75rem 0;
161+
}
162+
163+
.description p {
164+
margin-bottom: 0.5rem;
165+
}
166+
167+
.description-text {
168+
background: white;
169+
padding: 1rem;
170+
border-radius: 4px;
171+
border-left: 4px solid var(--fedora-blue);
172+
margin: 0;
173+
font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
174+
font-size: 0.9rem;
175+
white-space: pre-wrap;
176+
word-wrap: break-word;
177+
overflow-x: auto;
178+
}
158179
</style>
159180
{% block head %}{% endblock %}
160181
</head>

src/tmt_web/templates/testandplan.html.j2

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
<p><strong>Summary:</strong> {{ test.summary }}</p>
1313
{% endif %}
1414
{% if test.description %}
15-
<p><strong>Description:</strong> {{ test.description }}</p>
15+
<div class="description">
16+
<p><strong>Description:</strong></p>
17+
<pre class="description-text">{{ test.description }}</pre>
18+
</div>
1619
{% endif %}
1720
{% if test.tier %}
1821
<p><strong>Tier:</strong> {{ test.tier }}</p>
@@ -66,7 +69,10 @@
6669
<p><strong>Summary:</strong> {{ plan.summary }}</p>
6770
{% endif %}
6871
{% if plan.description %}
69-
<p><strong>Description:</strong> {{ plan.description }}</p>
72+
<div class="description">
73+
<p><strong>Description:</strong></p>
74+
<pre class="description-text">{{ plan.description }}</pre>
75+
</div>
7076
{% endif %}
7177
{% if plan.tier %}
7278
<p><strong>Tier:</strong> {{ plan.tier }}</p>

src/tmt_web/templates/testorplan.html.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
<p><strong>Summary:</strong> {{ testorplan.summary }}</p>
1212
{% endif %}
1313
{% if testorplan.description %}
14-
<p><strong>Description:</strong> {{ testorplan.description }}</p>
14+
<div class="description">
15+
<p><strong>Description:</strong></p>
16+
<pre class="description-text">{{ testorplan.description }}</pre>
17+
</div>
1518
{% endif %}
1619
{% if testorplan.tier %}
1720
<p><strong>Tier:</strong> {{ testorplan.tier }}</p>

tests/unit/test_html_generator.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,47 @@ def mock_render(*args, **kwargs):
223223
html_generator._render_template("testorplan.html.j2", logger)
224224
assert "Failed to render template" in str(exc.value)
225225
assert "testorplan.html.j2" in str(exc.value)
226+
227+
def test_multiline_description_rendering(self, logger):
228+
"""Test that multiline descriptions are rendered correctly with line breaks preserved."""
229+
# Create test data with multiline description
230+
multiline_description = (
231+
"First line of description\n\nSecond line after empty line\nThird line\n\nFourth line"
232+
)
233+
test_data = TestData(
234+
name="multiline-test",
235+
summary="Test with multiline description",
236+
description=multiline_description,
237+
contact=["Test Contact <test@example.com>"],
238+
component=["component1"],
239+
enabled=True,
240+
environment={"KEY": "value"},
241+
duration="15m",
242+
framework="shell",
243+
manual=False,
244+
path="/path/to/test",
245+
tier="1",
246+
order=50,
247+
id="test-multiline",
248+
tag=["tag1"],
249+
fmf_id=FmfIdData(
250+
name="test",
251+
url="https://example.com/test",
252+
path="/path/to/test",
253+
ref="main",
254+
),
255+
)
256+
257+
data = html_generator.generate_html_page(test_data, logger)
258+
259+
# Check that the description is wrapped in proper HTML structure
260+
assert '<div class="description">' in data
261+
assert '<pre class="description-text">' in data
262+
assert "</pre>" in data
263+
assert "</div>" in data
264+
265+
# Check that the multiline content is preserved
266+
assert "First line of description" in data
267+
assert "Second line after empty line" in data
268+
assert "Third line" in data
269+
assert "Fourth line" in data

0 commit comments

Comments
 (0)