Make pygments style configurable.

This commit is contained in:
Denis Kasak 2018-11-07 12:05:46 +01:00
parent 1a796322f3
commit 560c8d0c54
2 changed files with 18 additions and 2 deletions

View file

@ -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),

View file

@ -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 = [