diff options
author | Florian Münchbach <182-FlorianMuenchbach@users.noreply.dev.gajim.org> | 2019-02-18 22:32:41 +0300 |
---|---|---|
committer | Florian Münchbach <182-FlorianMuenchbach@users.noreply.dev.gajim.org> | 2019-02-18 23:18:21 +0300 |
commit | 7e068624d874e67ebb12294d09af4f04e0dd2e88 (patch) | |
tree | ceecfd497099a07d7f131cb30dedb140085603dc | |
parent | f2c4368f87540ac78f8b7980ceb2c018dfff3ff4 (diff) |
[syntax_highlight] More strict checking for inline code spans
-rw-r--r-- | syntax_highlight/chat_syntax_highlighter.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/syntax_highlight/chat_syntax_highlighter.py b/syntax_highlight/chat_syntax_highlighter.py index 3d720dc..fea203b 100644 --- a/syntax_highlight/chat_syntax_highlighter.py +++ b/syntax_highlight/chat_syntax_highlighter.py @@ -84,8 +84,14 @@ class ChatSyntaxHighlighter: return matches def find_inline_matches(self, text): - return [(i.start(), i.end(), i.group(0)) for i in \ - re.finditer(r'(?<!`)`(?!`|\n).+(?<!`)`', text)] + """ + Inline code is highlighted if the start marker is precedded by a start + of line, a whitespace character or either of the other span markers + defined in XEP-0393. + The same applies mirrored to the end marker. + """ + return [(i.start(1), i.end(1), i.group(1)) for i in \ + re.finditer(r'(?:^|\s|\*|~|_)(`((?!`).+?)`)(?:\s|\*|~|_|$)', text)] def merge_match_groups(self, real_text, inline_matches, multiline_matches): it_inline = iter(inline_matches) |