[Epydoc-commits] SF.net SVN: epydoc: [1453] trunk/epydoc/src/epydoc/markup/restructuredtext. py
Brought to you by:
edloper
|
From: <ed...@us...> - 2007-02-11 04:34:54
|
Revision: 1453
http://svn.sourceforge.net/epydoc/?rev=1453&view=rev
Author: edloper
Date: 2007-02-10 20:34:52 -0800 (Sat, 10 Feb 2007)
Log Message:
-----------
- Changed the 'python' code directive to be implemented via a function
rather than a class. Even though classes are the officially preferred
mechanism for defining directives in docutils 0.5, they are not
backwards compatible with docutils 0.3.7, which is still fairly
widely used. The new version is compatible with docutils 0.3.7+.
Modified Paths:
--------------
trunk/epydoc/src/epydoc/markup/restructuredtext.py
Modified: trunk/epydoc/src/epydoc/markup/restructuredtext.py
===================================================================
--- trunk/epydoc/src/epydoc/markup/restructuredtext.py 2007-02-11 04:23:35 UTC (rev 1452)
+++ trunk/epydoc/src/epydoc/markup/restructuredtext.py 2007-02-11 04:34:52 UTC (rev 1453)
@@ -77,7 +77,7 @@
from docutils.nodes import NodeVisitor, Text, SkipChildren
from docutils.nodes import SkipNode, TreeCopyVisitor
from docutils.frontend import OptionParser
-from docutils.parsers.rst import directives, Directive
+from docutils.parsers.rst import directives
import docutils.nodes
import docutils.transforms.frontmatter
import docutils.transforms
@@ -628,22 +628,29 @@
raise SkipNode()
-class PythonCodeDirective(Directive):
+def python_code_directive(name, arguments, options, content, lineno,
+ content_offset, block_text, state, state_machine):
+ """
+ A custom restructuredtext directive which can be used to display
+ syntax-highlighted Python code blocks. This directive takes no
+ arguments, and the body should contain only Python code. This
+ directive can be used instead of doctest blocks when it is
+ inconvenient to list prompts on each line, or when you would
+ prefer that the output not contain prompts (e.g., to make
+ copy/paste easier).
+ """
required_arguments = 0
optional_arguments = 0
- has_content = True
- def run(self):
- self.assert_has_content()
- text = '\n'.join(self.content)
+ text = '\n'.join(content)
+ node = docutils.nodes.doctest_block(text, text, codeblock=True)
+ return [ node ]
+
+python_code_directive.arguments = (0, 0, 0)
+python_code_directive.content = True
- #node = docutils.nodes.doctest_block(rawsource=text)
- #self.state.nested_parse(self.content, self.content_offset, node)
- node = docutils.nodes.doctest_block(text, text, codeblock=True)
- return [ node ]
+directives.register_directive('python', python_code_directive)
-directives.register_directive('python', PythonCodeDirective)
-
######################################################################
#{ Graph Generation Directives
######################################################################
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|