[Checkins] SVN: Sandbox/ulif/grok-reference-with-rest3/doc/build/grokdocs.py Circumvent LaTeX problems.

Uli Fouquet uli at gnufix.de
Sun Feb 24 20:53:56 EST 2008


Log message for revision 84223:
  Circumvent LaTeX problems.

Changed:
  U   Sandbox/ulif/grok-reference-with-rest3/doc/build/grokdocs.py

-=-
Modified: Sandbox/ulif/grok-reference-with-rest3/doc/build/grokdocs.py
===================================================================
--- Sandbox/ulif/grok-reference-with-rest3/doc/build/grokdocs.py	2008-02-25 01:40:59 UTC (rev 84222)
+++ Sandbox/ulif/grok-reference-with-rest3/doc/build/grokdocs.py	2008-02-25 01:53:55 UTC (rev 84223)
@@ -17,6 +17,8 @@
 import os.path
 from shutil import copyfile
 import getopt
+from docutils import nodes
+from docutils.parsers.rst import directives
 from ulif.rest import pygments_directive
 import sphinx
 from sphinx.util.console import nocolor
@@ -27,6 +29,20 @@
 HTMLDIR_ALL = os.path.join(os.path.dirname(__file__), 'html')
 HTMLDIR_REF = os.path.join(os.path.dirname(__file__), 'html-reference')
 
+def simple_directive(
+    name, arguments, options, content, lineno,
+    content_offset, block_text, state, state_machine):
+    """A docutils directive, that feeds content as literal block.
+
+    This is needed to circumvent highlighting quirks when doing
+    non-HTML output. The pygments_directive delivers plain HTML, which
+    we must avoid when generating LaTeX for example.
+    """
+    return [nodes.literal_block('', '\n'.join(content), options=options)]
+
+simple_directive.arguments = (1, 0, 1)
+simple_directive.content = 1
+
 def usage(argv, msg=None, default_src=None, default_out=None):
     """Some hints for users.
 
@@ -91,6 +107,15 @@
         sphinx.usage(argv, msg=None)
         return 1
 
+    if opts and '-b' in [x for x,y in opts]:
+        val = filter(lambda x: x[0] == '-b', opts)
+        val = val[0][1]
+        if val == 'latex':
+            # disable code-block directive by substituting it with a
+            # simple version...
+            directives.register_directive('sourcecode', simple_directive)
+            directives.register_directive('code-block', simple_directive)
+
     if len(args) < 1:
         argv.append(srcdir)
     if len(args) < 2:



More information about the Checkins mailing list