cleanup, don't fail if no context set on the sourcecode directive
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Sat, 06 Feb 2010 08:45:14 +0100
changeset 4483 918fd9931cb7
parent 4482 1f4f33535d9a
child 4490 d45cde54d464
cleanup, don't fail if no context set on the sourcecode directive
ext/rest.py
--- 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)