Merge pull request #10 from dkasak/master
Handle combination of strikethrough and other attributes.
This commit is contained in:
commit
6eec395254
3 changed files with 27 additions and 3 deletions
|
@ -288,6 +288,14 @@ class Formatted():
|
||||||
text = formatted_string.text
|
text = formatted_string.text
|
||||||
attributes = formatted_string.attributes
|
attributes = formatted_string.attributes
|
||||||
|
|
||||||
|
# We need to handle strikethrough first, since doing
|
||||||
|
# a strikethrough followed by other attributes succeeds in the
|
||||||
|
# terminal, but doing it the other way around results in garbage.
|
||||||
|
if 'strikethrough' in attributes:
|
||||||
|
text = add_attribute(text, 'strikethrough',
|
||||||
|
attributes['strikethrough'])
|
||||||
|
attributes.pop('strikethrough')
|
||||||
|
|
||||||
for key, value in attributes.items():
|
for key, value in attributes.items():
|
||||||
text = add_attribute(text, key, value)
|
text = add_attribute(text, key, value)
|
||||||
return text
|
return text
|
||||||
|
|
|
@ -815,7 +815,8 @@ class RoomRedactionEvent(RoomEvent):
|
||||||
new_message = ""
|
new_message = ""
|
||||||
|
|
||||||
if OPTIONS.redaction_type == RedactType.STRIKETHROUGH:
|
if OPTIONS.redaction_type == RedactType.STRIKETHROUGH:
|
||||||
new_message = string_strikethrough(message)
|
plaintext_msg = W.string_remove_color(message, '')
|
||||||
|
new_message = string_strikethrough(plaintext_msg)
|
||||||
elif OPTIONS.redaction_type == RedactType.NOTICE:
|
elif OPTIONS.redaction_type == RedactType.NOTICE:
|
||||||
new_message = message
|
new_message = message
|
||||||
elif OPTIONS.redaction_type == RedactType.DELETE:
|
elif OPTIONS.redaction_type == RedactType.DELETE:
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import webcolors
|
import webcolors
|
||||||
|
from collections import OrderedDict
|
||||||
from hypothesis import given
|
from hypothesis import given
|
||||||
from hypothesis.strategies import sampled_from
|
from hypothesis.strategies import sampled_from
|
||||||
|
|
||||||
from matrix.colors import (Formatted, color_html_to_weechat,
|
from matrix.colors import (Formatted, FormattedString,
|
||||||
color_weechat_to_html)
|
color_html_to_weechat, color_weechat_to_html)
|
||||||
|
|
||||||
html_prism = ("<font color=maroon>T</font><font color=red>e</font><font "
|
html_prism = ("<font color=maroon>T</font><font color=red>e</font><font "
|
||||||
"color=olive>s</font><font color=yellow>t</font>")
|
"color=olive>s</font><font color=yellow>t</font>")
|
||||||
|
@ -27,3 +30,15 @@ def test_color_conversion(color_name):
|
||||||
hex_color = color_weechat_to_html(color_html_to_weechat(color_name))
|
hex_color = color_weechat_to_html(color_html_to_weechat(color_name))
|
||||||
new_color_name = webcolors.hex_to_name(hex_color, spec='html4')
|
new_color_name = webcolors.hex_to_name(hex_color, spec='html4')
|
||||||
assert new_color_name == color_name
|
assert new_color_name == color_name
|
||||||
|
|
||||||
|
|
||||||
|
def test_handle_strikethrough_first():
|
||||||
|
valid_result = '\x1b[038;5;1mf̶o̶o̶\x1b[039m'
|
||||||
|
|
||||||
|
d1 = OrderedDict([('fgcolor', 'red'), ('strikethrough', True)])
|
||||||
|
d2 = OrderedDict([('strikethrough', True), ('fgcolor', 'red'), ])
|
||||||
|
f1 = Formatted([FormattedString('foo', d1)])
|
||||||
|
f2 = Formatted([FormattedString('foo', d2)])
|
||||||
|
|
||||||
|
assert f1.to_weechat() == valid_result
|
||||||
|
assert f2.to_weechat() == valid_result
|
||||||
|
|
Loading…
Reference in a new issue