Make displaying preformatted code as blocks configurable.

This commit is contained in:
Denis Kasak 2019-01-09 14:44:37 +01:00 committed by Damir Jelić
parent 26f7dae990
commit dcc5a3e530
2 changed files with 23 additions and 5 deletions

View file

@ -318,17 +318,24 @@ class Formatted(object):
try: try:
lexer = get_lexer_by_name(value) lexer = get_lexer_by_name(value)
except ClassNotFound: except ClassNotFound:
if G.CONFIG.look.code_blocks:
return colored_text_block( return colored_text_block(
string, string,
margin=margin, margin=margin,
color_pair=code_color_pair) color_pair=code_color_pair)
else:
return string_color_and_reset(string,
code_color_pair)
try: try:
style = get_style_by_name(G.CONFIG.look.pygments_style) style = get_style_by_name(G.CONFIG.look.pygments_style)
except ClassNotFound: except ClassNotFound:
style = "native" style = "native"
if G.CONFIG.look.code_blocks:
code_block = text_block(string, margin=margin) code_block = text_block(string, margin=margin)
else:
code_block = string
# highlight adds a newline to the end of the string, remove # highlight adds a newline to the end of the string, remove
# it from the output # it from the output

View file

@ -496,6 +496,17 @@ class MatrixConfig(WeechatConfig):
"native", "native",
"Pygments style to use for highlighting source code blocks", "Pygments style to use for highlighting source code blocks",
), ),
Option(
"code_blocks",
"boolean",
"",
0,
0,
"on",
("Display preformatted code blocks as rectangular areas by "
"padding them with whitespace up to the length of the longest "
"line (with optional margin)"),
),
Option( Option(
"code_block_margin", "code_block_margin",
"integer", "integer",