Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Unified Diff: tools/json_schema_compiler/highlighters/pygments_highlighter.py

Issue 10833024: Fix syntax highlighting in JSON Schema Compiler's preview server: don't crash (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/highlighters/pygments_highlighter.py
diff --git a/tools/json_schema_compiler/highlighters/pygments_highlighter.py b/tools/json_schema_compiler/highlighters/pygments_highlighter.py
index 569fcc5f8b2674ca49c0c647c81bc26a82675b27..06abd33c7909d3f1c2b6173310ab62ebe6e8943e 100644
--- a/tools/json_schema_compiler/highlighters/pygments_highlighter.py
+++ b/tools/json_schema_compiler/highlighters/pygments_highlighter.py
@@ -14,21 +14,21 @@ except ImportError:
PYGMENTS_IMPORTED = False
class PygmentsHighlighter(object):
+ def __init__(self):
+ if not PYGMENTS_IMPORTED:
+ raise ImportError('Pygments not installed')
+
"""Highlighter that uses the python pygments library to highlight code.
"""
def GetCSS(self, style):
- if PYGMENTS_IMPORTED:
- formatter = HtmlFormatter(linenos=True,
- style=pygments.styles.get_style_by_name(style))
- return formatter.get_style_defs('.highlight')
+ formatter = HtmlFormatter(linenos=True,
+ style=pygments.styles.get_style_by_name(style))
+ return formatter.get_style_defs('.highlight')
def GetCodeElement(self, code, style):
- if PYGMENTS_IMPORTED:
- formatter = HtmlFormatter(linenos=True,
- style=pygments.styles.get_style_by_name(style))
- return pygments.highlight(code, CppLexer(), formatter)
- else:
- return '<pre>Pygments highlighter not installed</pre>'
+ formatter = HtmlFormatter(linenos=True,
+ style=pygments.styles.get_style_by_name(style))
+ return pygments.highlight(code, CppLexer(), formatter)
def DisplayName(self):
return 'pygments' + ('' if PYGMENTS_IMPORTED else ' (not installed)')
« no previous file with comments | « tools/json_schema_compiler/highlighters/none_highlighter.py ('k') | tools/json_schema_compiler/previewserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698