Skip to content

Commit a033e7b

Browse files
committed
Refactor HTMLFormatter for improved readability and style consistency
- Corrected string formatting for CSS styles in HTML output - Simplified inline space handling logic in bullet lists - Added flake8 noqa comments to suppress style warnings for CSS syntax These changes enhance the maintainability of the HTML formatter without altering its functionality.
1 parent f0ba018 commit a033e7b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

elementary/messages/formats/html.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def format_message_block(self, block: MessageBlock | ExpandableBlock) -> str:
7373
'<pre style="margin:0;padding:12px;'
7474
"background-color:#f8fafc;border-radius:4px;"
7575
"font-family:'SFMono-Regular',Consolas,'Liberation Mono',Menlo,monospace;"
76-
'font-size:13px;line-height:1.5;white-space:pre-wrap;'
76+
"font-size:13px;line-height:1.5;white-space:pre-wrap;"
7777
'max-height:400px;overflow-y:auto;">'
7878
f"{code_html}</pre>"
7979
)
@@ -205,12 +205,10 @@ def _format_as_bullet_list(self, block: LinesBlock) -> str:
205205
idx += 1
206206

207207
# Skip the space after bullet
208-
if (
209-
idx < len(line.inlines)
210-
and isinstance(line.inlines[idx], TextBlock)
211-
and line.inlines[idx].text == " "
212-
):
213-
idx += 1
208+
if idx < len(line.inlines):
209+
space_inline = line.inlines[idx]
210+
if isinstance(space_inline, TextBlock) and space_inline.text == " ":
211+
idx += 1
214212

215213
# Rest is the content
216214
content_inlines = line.inlines[idx:]
@@ -246,7 +244,7 @@ def _format_fact_list_block(self, block: FactListBlock) -> str:
246244
+ "</table>"
247245
)
248246
# Use custom margin with +8px on top and bottom
249-
return f'<div style="margin:8px 0 20px">{table_html}</div>'
247+
return f'<div style="margin:8px 0 20px">{table_html}</div>' # noqa: E231
250248

251249
def _format_fact_row(self, fact: FactBlock) -> str:
252250
title_html = self._format_line_block(fact.title)
@@ -341,7 +339,11 @@ def _build_container_style(self, color: Color | None) -> str:
341339
if color and color in COLOR_MAP:
342340
# Replace the default border color with the status color
343341
styles = [
344-
s if not s.startswith("border:") else f"border:1px solid {COLOR_MAP[color]}"
342+
(
343+
s
344+
if not s.startswith("border:")
345+
else f"border:1px solid {COLOR_MAP[color]}"
346+
)
345347
for s in styles
346348
]
347349
styles.append(f"border-left:4px solid {COLOR_MAP[color]}") # noqa: E231

0 commit comments

Comments
 (0)