ext/rest.py
changeset 4483 918fd9931cb7
parent 4334 dda74c345b06
child 4719 aaed3f813ef8
--- a/ext/rest.py	Fri Feb 05 15:53:25 2010 +0100
+++ b/ext/rest.py	Sat Feb 06 08:45:14 2010 +0100
@@ -159,14 +159,16 @@
         try:
             lexer = get_lexer_by_name(arguments[0])
         except ValueError:
-            import traceback
-            traceback.print_exc()
-            print sorted(aliases for module_name, name, aliases, _, _  in LEXERS.itervalues())
             # no lexer found
             lexer = get_lexer_by_name('text')
         parsed = highlight(u'\n'.join(content), lexer, _PYGMENTS_FORMATTER)
-        context = state.document.settings.context
-        context._cw.add_css('pygments.css')
+        # don't fail if no context set on the sourcecode directive
+        try:
+            context = state.document.settings.context
+            context._cw.add_css('pygments.css')
+        except AttributeError:
+            # used outside cubicweb
+            pass
         return [nodes.raw('', parsed, format='html')]
 
     pygments_directive.arguments = (1, 0, 1)