def matrix_me_command_cb(data, buffer, args): for server in SERVERS.values(): if buffer in server.buffers.values(): if not server.connected: message = ("{prefix}matrix: you are not connected to " "the server").format(prefix=W.prefix("error")) W.prnt(server.server_buffer, message) return W.WEECHAT_RC_ERROR room_id = key_from_value(server.buffers, buffer) if not args: return W.WEECHAT_RC_OK formatted_data = Formatted.from_input_line(args) message = MatrixEmoteMessage(server.client, room_id=room_id, formatted_message=formatted_data) server.send_or_queue(message) return W.WEECHAT_RC_OK elif buffer == server.server_buffer: message = ("{prefix}matrix: command \"me\" must be " "executed on a Matrix channel buffer").format( prefix=W.prefix("error")) W.prnt("", message) return W.WEECHAT_RC_OK
def test_input_line_markdown_various(): inp = "**bold* bold *bital etc* bold **bold** * *italic*" formatted = Formatted.from_input_line(inp) assert "<strong>bold* bold </strong>" \ "<em><strong>bital etc</strong></em><strong> bold **bold</strong>" \ " * <em>italic</em>" \ == formatted.to_html()
def test_normalize_spaces_in_inline_code(): """Normalize spaces in inline code blocks. Strips leading and trailing spaces and compress consecutive infix spaces. """ valid_result = '\x1b[0m* a *\x1b[00m' formatted = Formatted.from_input_line('` * a * `') assert formatted.to_weechat() == valid_result
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
def from_dict(cls, event): event_id = sanitize_id(event["event_id"]) sender = sanitize_id(event["sender"]) timestamp = sanitize_ts(event["origin_server_ts"]) msg = "" formatted_msg = None msg = sanitize_text(event['content']['body']) if ('format' in event['content'] and 'formatted_body' in event['content']): if event['content']['format'] == "org.matrix.custom.html": formatted_msg = Formatted.from_html( sanitize_text(event['content']['formatted_body'])) return cls(event_id, sender, timestamp, msg, formatted_msg)
def test_prism(): formatted = Formatted.from_html(html_prism) assert formatted.to_weechat() == weechat_prism
def test_input_line_markdown_bold(): formatted = Formatted.from_input_line("**Hello**") assert "\x1b[01mHello\x1b[021m" == formatted.to_weechat() assert "<strong>Hello</strong>" == formatted.to_html()
def test_input_line_markdown_emph(): formatted = Formatted.from_input_line("*Hello*") assert "\x1b[03mHello\x1b[023m" == formatted.to_weechat() assert "<em>Hello</em>" == formatted.to_html()
def test_input_line_underline(): formatted = Formatted.from_input_line("\x1FHello") assert "\x1b[04mHello\x1b[024m" == formatted.to_weechat() assert "<u>Hello</u>" == formatted.to_html()
def test_input_line_color(): formatted = Formatted.from_input_line("\x0304Hello") assert "\x1b[038;5;9mHello\x1b[039m" == formatted.to_weechat() assert "<font data-mx-color=#ff0000>Hello</font>" == formatted.to_html()
def test_unpaired_prefix_asterisk_without_space_is_literal(text): """An unpaired asterisk at the beginning of the line, without a space after it, is considered literal. """ formatted = Formatted.from_input_line(text) assert text.strip() == formatted.to_weechat()
def test_conversion(): formatted = Formatted.from_input_line("*Hello*") formatted2 = Formatted.from_html(formatted.to_html()) formatted.to_weechat() == formatted2.to_weechat()
def convert(s): return Formatted.from_input_line(s).to_html() assert "pre <em>italic* ital</em> norm" == convert("pre *italic\\* ital* norm")
def test_input_line_markdown_various2(): inp = "norm** `code **code *code` norm `norm" formatted = Formatted.from_input_line(inp) assert "norm** <code>code **code *code</code> norm `norm" \ == formatted.to_html()
def convert(s): return Formatted.from_input_line(s).to_html()