From: David G. <go...@us...> - 2002-10-11 02:01:02
|
Aahz wrote: > Here's some sample reST text:: > > Overall, my primary source for determining what to include in > this book was the netnews group ``comp.lang.python``. I've been > reading that group for several years, and the same questions > seem to show up over and over again. > > .. index:: > comp.lang.python > Usenet > netnews > > What am I doing wrong with this directive:: > > from docutils import nodes > from docutils.parsers.rst import directives > > registry = directives._directive_registry > registry['index'] = ('OOdirectives', 'index_directive') You must be importing this module explicitly somewhere, right? Otherwise, how does the registration code run before the directive is registered? ;-> > class index_entry(nodes.General, nodes.Element): pass This is the problem. Replace "nodes.Element" with "nodes.TextElement". Their __init__ signatures are different. > def index_directive(name, arguments, options, content, lineno, > content_offset, block_text, state, state_machine): > text = '\n'.join(content) > text_nodes, messages = state.inline_text(text, lineno) > node = index_entry(text, '', *text_nodes) ^^ Right here, the code is sending a string ('') as a child node. > return [node] + messages > > index_directive.content = 1 I'm guessing that this is a "first draft" of the directive, yes? You'll probably want to create an index_entry for each of the terms listed in the directive, and insert them at the beginning of the paragraph (therefore "index_entry" should be an inline element). In fact, the class declaration should probably be:: class index_entry(nodes.Inline, nodes.TextElement): pass > If I replace the code of index_directive() with "return []", I don't > get an exception. That's odd. Are you sure you made no other changes? This is where the error originates: > File "OOdirectives.py", line 17, in index_directive > node = index_entry(text, '', *text_nodes) -- David Goodger <go...@us...> Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ |