From 15cb51b2b67157665156805070caf34c2355e2ea Mon Sep 17 00:00:00 2001 From: joncrall Date: Thu, 10 Sep 2020 21:24:16 -0400 Subject: [PATCH] Fix code highlighting on linux --- xdoctest/utils/util_str.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xdoctest/utils/util_str.py b/xdoctest/utils/util_str.py index 3e107405..d376b216 100644 --- a/xdoctest/utils/util_str.py +++ b/xdoctest/utils/util_str.py @@ -194,10 +194,14 @@ def highlight_code(text, lexer_name='python', **kwargs): 'cxx': 'cpp', 'c': 'cpp', }.get(lexer_name.replace('.', ''), lexer_name) - import os - if os.environ.get('XDOC_WIN32_COLORS', 'False') == 'False': - # hack: dont color on windows by default, but do init colorama - return text + + if sys.platform.startswith('win32'): # nocover + # Hack on win32 to support colored output + import os + if os.environ.get('XDOC_WIN32_COLORS', 'False') == 'False': + # hack: dont color on windows by default, but do init colorama + return text + try: import pygments import pygments.lexers