Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions humanfriendly/terminal/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ def parse_color(self, value):
elif length == 3:
# Three hex digits (shorthand).
return (
int(value[0], 16),
int(value[1], 16),
int(value[2], 16),
int(value[0] * 2, 16),
int(value[1] * 2, 16),
int(value[2] * 2, 16),
)
# Try to recognize a named color.
value = value.lower()
Expand Down
12 changes: 12 additions & 0 deletions humanfriendly/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,18 @@ def callback(text):
title="VPS hosting" rel="external"&gt;True</a>
''')

def test_html_shorthand_colors(self):
"""CSS short hex colors expand each digit before ANSI rendering."""
from humanfriendly.terminal.html import HTMLConverter
converter = HTMLConverter()
for short, full, rgb in [('#fff', '#ffffff', (255, 255, 255)),
('#aBc', '#aaBBcc', (170, 187, 204)),
('#123', '#112233', (17, 34, 51))]:
self.assertEqual(converter.parse_color(short), rgb)
for prop in ('color', 'background-color'):
template = '<span style="%s: %%s">text</span>' % prop
self.assertEqual(html_to_ansi(template % short), html_to_ansi(template % full))

def test_generate_output(self):
"""Test the :func:`humanfriendly.terminal.output()` function."""
text = "Standard output generated by output()"
Expand Down