From 26f7dae9908a008749b1e5b9a765a82140e5a108 Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Wed, 9 Jan 2019 14:14:16 +0100 Subject: [PATCH] Make code block margin configurable. --- matrix/colors.py | 10 ++++++---- matrix/config.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/matrix/colors.py b/matrix/colors.py index 218cfe2..2f51936 100644 --- a/matrix/colors.py +++ b/matrix/colors.py @@ -310,6 +310,8 @@ class Formatted(object): G.CONFIG.color.untagged_code_bg ) + margin = G.CONFIG.look.code_block_margin + if attributes["preformatted"]: # code block @@ -318,7 +320,7 @@ class Formatted(object): except ClassNotFound: return colored_text_block( string, - margin=2, + margin=margin, color_pair=code_color_pair) try: @@ -326,10 +328,10 @@ class Formatted(object): except ClassNotFound: style = "native" - code_block = text_block(string, margin=2) + code_block = text_block(string, margin=margin) - # highlight adds a newline to the end of the string, remove it - # from the output + # highlight adds a newline to the end of the string, remove + # it from the output highlighted_code = highlight( code_block, lexer, diff --git a/matrix/config.py b/matrix/config.py index 98f51c2..d16d456 100644 --- a/matrix/config.py +++ b/matrix/config.py @@ -496,6 +496,16 @@ class MatrixConfig(WeechatConfig): "native", "Pygments style to use for highlighting source code blocks", ), + Option( + "code_block_margin", + "integer", + "", + 0, + 100, + "2", + ("Number of spaces to add as a margin around around a code " + "block"), + ), ] network_options = [