From 560c8d0c54c7058cfa912ee2652e8cacf3f6b4fd Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Wed, 7 Nov 2018 12:05:46 +0100 Subject: [PATCH] Make pygments style configurable. --- matrix/colors.py | 10 ++++++++-- matrix/config.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/matrix/colors.py b/matrix/colors.py index 88df27e..41c2600 100644 --- a/matrix/colors.py +++ b/matrix/colors.py @@ -29,7 +29,7 @@ from typing import List import webcolors from pygments import highlight -from pygments.formatter import Formatter +from pygments.formatter import Formatter, get_style_by_name from pygments.lexers import get_lexer_by_name, guess_lexer from pygments.util import ClassNotFound @@ -298,9 +298,15 @@ class Formatted(object): except ClassNotFound: lexer = guess_lexer(string) + try: + style = get_style_by_name(G.CONFIG.look.pygments_style) + except ClassNotFound: + style = "native" + # highlight adds a newline to the end of the string, remove it # from the output - return highlight(string, lexer, WeechatFormatter())[:-1] + return highlight(string, lexer, + WeechatFormatter(style=style))[:-1] elif name == "fgcolor": return "{color_on}{text}{color_off}".format( color_on=W.color(value), diff --git a/matrix/config.py b/matrix/config.py index 4d69c76..b7ac695 100644 --- a/matrix/config.py +++ b/matrix/config.py @@ -357,6 +357,16 @@ class MatrixConfig(WeechatConfig): "rooms (note: content is evaluated, see /help eval)"), eval_cast, ), + Option( + "pygments_style", + "string", + "", + 0, + 0, + "native", + "Pygments style to use for highlighting source code blocks", + eval_cast, + ), ] network_options = [