From 23431eaf4e7b2efab67e31765575fc2ee40625c1 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 14 Feb 2016 09:36:42 +0100 Subject: [PATCH] viewcode: default to python3 highlighting if highlight_language is python3 --- sphinx/ext/viewcode.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sphinx/ext/viewcode.py b/sphinx/ext/viewcode.py index d64cc88f76..89e7a9965b 100644 --- a/sphinx/ext/viewcode.py +++ b/sphinx/ext/viewcode.py @@ -139,7 +139,11 @@ def collect_pages(app): # construct a page name for the highlighted source pagename = '_modules/' + modname.replace('.', '/') # highlight the source using the builder's highlighter - highlighted = highlighter.highlight_block(code, 'python', linenos=False) + if env.config.highlight_language == 'python3': + lexer = 'python3' + else: + lexer = 'python' + highlighted = highlighter.highlight_block(code, lexer, linenos=False) # split the code into lines lines = highlighted.splitlines() # split off wrap markup from the first line of the actual code