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

Unified Diff: third_party/chrome/tools/highlighters/pygments_highlighter.py

Issue 12261015: Import chrome idl into third_party (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
« no previous file with comments | « third_party/chrome/tools/highlighters/none_highlighter.py ('k') | third_party/chrome/tools/idl_schema.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/chrome/tools/highlighters/pygments_highlighter.py
diff --git a/third_party/chrome/tools/highlighters/pygments_highlighter.py b/third_party/chrome/tools/highlighters/pygments_highlighter.py
new file mode 100644
index 0000000000000000000000000000000000000000..06abd33c7909d3f1c2b6173310ab62ebe6e8943e
--- /dev/null
+++ b/third_party/chrome/tools/highlighters/pygments_highlighter.py
@@ -0,0 +1,37 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import sys
+try:
+ import pygments
+ from pygments.lexers import CppLexer
+ from pygments.formatters import HtmlFormatter
+ PYGMENTS_IMPORTED = True
+except ImportError:
+ print('It appears that Pygments is not installed. '
+ 'Can be installed using easy_install Pygments or from http://pygments.org.')
+ 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):
+ formatter = HtmlFormatter(linenos=True,
+ style=pygments.styles.get_style_by_name(style))
+ return formatter.get_style_defs('.highlight')
+
+ def GetCodeElement(self, code, style):
+ 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)')
+
+ def GetStyles(self):
+ return list(pygments.styles.get_all_styles())
« no previous file with comments | « third_party/chrome/tools/highlighters/none_highlighter.py ('k') | third_party/chrome/tools/idl_schema.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698