From e74a5a2041af7952451cbade27f65de8cfee492c Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 25 Aug 2020 22:31:02 +0200 Subject: [PATCH] Toggle markdown parsing with matrix.look.markdown_input --- matrix/colors.py | 8 ++++++-- matrix/config.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/matrix/colors.py b/matrix/colors.py index d1bfce1..70ab71b 100644 --- a/matrix/colors.py +++ b/matrix/colors.py @@ -88,6 +88,9 @@ class Formatted(object): substrings = [] # type: List[FormattedString] attributes = DEFAULT_ATTRIBUTES.copy() + # If this is false, only IRC formatting characters will be parsed. + do_markdown = G.CONFIG.look.markdown_input + # Disallow backticks in URLs so that code blocks are unaffected by the # URL handling url_regex = r"\b[a-z]+://[^\s`]+" @@ -169,7 +172,8 @@ class Formatted(object): in_url = True # Markdown escape - if i + 1 < len(line) and line[i] == "\\" \ + if do_markdown and \ + i + 1 < len(line) and line[i] == "\\" \ and (line[i + 1] in escapable_chars if not attributes["code"] else line[i + 1] == "`") \ @@ -235,7 +239,7 @@ class Formatted(object): attributes["bgcolor"] = None # Markdown wrapper (emphasis/bold/code) - elif line[i] in wrapper_init_chars and not in_url: + elif do_markdown and line[i] in wrapper_init_chars and not in_url: for l in range(wrapper_max_len, 0, -1): if i + l <= len(line) and line[i : i + l] in wrappers: descriptor = wrappers[line[i : i + l]] diff --git a/matrix/config.py b/matrix/config.py index b7f1419..f4ff40a 100644 --- a/matrix/config.py +++ b/matrix/config.py @@ -597,6 +597,16 @@ class MatrixConfig(WeechatConfig): "since conflicts can happen otherwise " "(requires a script reload)."), ), + Option( + "markdown_input", + "boolean", + "", + 0, + 0, + "on", + ("If turned on, markdown usage in messages will be converted " + "to actual markup (**bold**, *italic*, _italic_, `code`)."), + ), ] network_options = [