# HG changeset patch # User Sylvain Thénault # Date 1265442314 -3600 # Node ID 918fd9931cb77ff3191c181eefbed12be36f9268 # Parent 1f4f33535d9a6deff45b851405e08bd766d2bee0 cleanup, don't fail if no context set on the sourcecode directive diff -r 1f4f33535d9a -r 918fd9931cb7 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)