merge
authorsylvain.thenault@logilab.fr
Wed, 04 Mar 2009 13:25:51 +0100
changeset 1003 be21d3d31ecf
parent 1002 9a8db0c59971 (current diff)
parent 996 9495a0594b95 (diff)
child 1004 625e59773119
merge
i18n/es.po
--- a/common/rest.py	Tue Mar 03 18:44:19 2009 +0100
+++ b/common/rest.py	Wed Mar 04 13:25:51 2009 +0100
@@ -1,9 +1,19 @@
 """rest publishing functions
 
-contains some functions and setup of docutils for cubicweb
+contains some functions and setup of docutils for cubicweb. Provides the
+following ReST directives:
+
+* `eid`, create link to entity in the repository by their eid
+
+* `card`, create link to card entity in the repository by their wikiid
+  (proposing to create it when the refered card doesn't exist yet)
+
+* `winclude`, reference to a web documentation file (in wdoc/ directories)
+
+* `sourcecode` (if pygments is installed), source code colorization
 
 :organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 __docformat__ = "restructuredtext en"
@@ -156,6 +166,36 @@
                               'encoding': directives.encoding}
 directives.register_directive('winclude', winclude_directive)
 
+try:
+    from pygments import highlight
+    from pygments.lexers import get_lexer_by_name, LEXERS
+    from pygments.formatters import HtmlFormatter
+except ImportError:
+    pass
+else:
+    _PYGMENTS_FORMATTER = HtmlFormatter()
+
+    def pygments_directive(name, arguments, options, content, lineno,
+                           content_offset, block_text, state, state_machine):
+        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')
+        print 'LEXER', lexer
+        parsed = highlight(u'\n'.join(content), lexer, _PYGMENTS_FORMATTER)
+        context = state.document.settings.context
+        context.req.add_css('pygments.css')
+        return [nodes.raw('', parsed, format='html')]
+     
+    pygments_directive.arguments = (1, 0, 1)
+    pygments_directive.content = 1
+    directives.register_directive('sourcecode', pygments_directive)
+
+
 class CubicWebReSTParser(Parser):
     """The (customized) reStructuredText parser."""
 
--- a/i18n/es.po	Tue Mar 03 18:44:19 2009 +0100
+++ b/i18n/es.po	Wed Mar 04 13:25:51 2009 +0100
@@ -76,8 +76,8 @@
 msgstr "%d semanas"
 
 #, python-format
-msgid "%d years"
-msgstr "%d años"
+msgid "%d years"
+msgstr "%d años"
 
 #, python-format
 msgid "%d days"