[Epydoc-devel] Coloured syntax directive [was Re: Planning for 3.0]
Brought to you by:
edloper
|
From: Daniele V. <dan...@gm...> - 2007-02-07 01:52:08
|
Hello,
>> - docutils :python: directive to allow examples to appear as colored
>> Python code
>
> That would be fine. Is there a reason not to use doctest block? They
> already get colored.
I am trying to add a directive to parse a docstring such as the following,
generating a box with colored syntax::
class Foo:
"""A class like nothing else.
This is a test:
.. code:: python
def foo():
'''Hello world'''
for i in range(10):
print i
"""
i'd like to generate a doctest block, so that the visitors would already work.
No luck up to now: i tried to follow the example in [1], but it fails. The
directive i added is::
class CodeDirective(Directive):
required_arguments = 0
optional_arguments = 1
has_content = True
def run(self):
self.assert_has_content()
text = '\n'.join(self.content)
node = docutils.nodes.doctest_block(rawsource=text)
self.state.nested_parse(self.content, self.content_offset, node)
return [ node ]
directives.register_directive('code', CodeDirective)
but trying to parse the above snippet i receive errors "Unexpected
indentation". It seems that "nested_parse" parses the snippet::
def Foo():
'''Hello world'''
for i in range(10):
print i
as it were ordinary text, not a block, so indentations don't make sense for
it. It should really be parsed as a literal block.
I checked the docutils.parsers.rst.states module, but didn't find any
promising method to "parse" a literal block (for which, i know, there's not
much to parse)
Any hint?
Thanks
-- Daniele
[1] http://docutils.sourceforge.net/docs/howto/rst-directives.html#admonitions
|