From 207fb44bdce515cc4d67207c3e40bdd4a1bdcd1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Tue, 6 Mar 2018 22:57:57 +0100 Subject: [PATCH] colors: Add markdown style italics support. --- matrix/colors.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/matrix/colors.py b/matrix/colors.py index 59f2323..8afb005 100644 --- a/matrix/colors.py +++ b/matrix/colors.py @@ -73,6 +73,33 @@ class Formatted(): attributes["bold"] = not attributes["bold"] i = i + 1 + # Markdown bold + elif line[i] == "*": + if attributes["italic"] and not line[i-1].isspace(): + if text: + substrings.append(FormattedString( + text, attributes.copy())) + text = "" + attributes["italic"] = not attributes["italic"] + i = i + 1 + continue + + elif attributes["italic"] and line[i-1].isspace(): + text = text + line[i] + i = i + 1 + continue + + elif i+1 > len(line) or line[i+1].isspace(): + text = text + line[i] + i = i + 1 + continue + + if text: + substrings.append(FormattedString(text, attributes.copy())) + text = "" + attributes["italic"] = not attributes["italic"] + i = i + 1 + # Color elif line[i] == "\x03": if text: