I add some lines in rst2html.py just for testing my own 'mytable' directive and get this
/tmp/docutils-code/docutils/tools $ echo ".. mytable::" | PYTHONPATH="../" ./rst2html.py --trace
Traceback (most recent call last):
File "./rst2html.py", line 48, in <module>
publish_cmdline(writer_name='html', description=description)
File "/tmp/docutils-code/docutils/docutils/core.py", line 352, in publish_cmdline
config_section=config_section, enable_exit_status=enable_exit_status)
File "/tmp/docutils-code/docutils/docutils/core.py", line 219, in publish
output = self.writer.write(self.document, self.destination)
File "/tmp/docutils-code/docutils/docutils/writers/init.py", line 80, in write
self.translate()
File "/tmp/docutils-code/docutils/docutils/writers/html4css1/init.py", line 176, in translate
self.document.walkabout(visitor)
File "/tmp/docutils-code/docutils/docutils/nodes.py", line 174, in walkabout
if child.walkabout(visitor):
File "/tmp/docutils-code/docutils/docutils/nodes.py", line 174, in walkabout
if child.walkabout(visitor):
File "/tmp/docutils-code/docutils/docutils/nodes.py", line 174, in walkabout
if child.walkabout(visitor):
File "/tmp/docutils-code/docutils/docutils/nodes.py", line 174, in walkabout
if child.walkabout(visitor):
File "/tmp/docutils-code/docutils/docutils/nodes.py", line 174, in walkabout
if child.walkabout(visitor):
File "/tmp/docutils-code/docutils/docutils/nodes.py", line 166, in walkabout
visitor.dispatch_visit(self)
File "/tmp/docutils-code/docutils/docutils/nodes.py", line 1882, in dispatch_visit
return method(node)
File "/tmp/docutils-code/docutils/docutils/writers/html4css1/init.py", line 798, in visit_entry
if node.parent.parent.parent.stubs[node.parent.column]:
IndexError: list index out of range
My rst2html.py -- BOF -- #!/usr/bin/python try: import locale locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_cmdline, default_description from docutils.parsers.rst import directives from docutils.parsers.rst.directives.tables import Table from docutils import nodes class MyTable(Table): def run(self): table = nodes.table() tgroup = nodes.tgroup(cols=2) table += tgroup #colspec = nodes.colspec(colwidth=1) #tgroup += colspec tbody = nodes.tbody() row_node = nodes.row() entry = nodes.entry() cell = nodes.paragraph(text='a') entry += cell row_node += entry tbody += row_node tgroup += tbody return [table] directives.register_directive('mytable', MyTable) description = ('Generates (X)HTML documents from standalone reStructuredText ' 'sources. ' + default_description) publish_cmdline(writer_name='html', description=description) -- EOF --
If I uncomment two lines in rst2html.py then everything will work.
I think that 'colspec' node is not necessary.
And this line in "docutils/docutils/writers/html4css1/init.py"
...
if node.parent.parent.parent.stubs[node.parent.column]:
...
does not check things.
Docutils version: rst2html.py (Docutils 0.11 [repository], Python 2.7.3, on linux2)
While not necessary in your use case, the "colspec" node is a fixed part of a "table" node in a
Docutils document tree
. Unfortunately, the description of both, "table" and "colgroup" in http://docutils.sourceforge.net/docs/ref/doctree.htmlis "To be completed.", so that the norm is set by the implementation of "table"-generating directives in the Docutils source.
A more safe programming in writers/html4css1/init.py might be desirable, but would not prevent possible failure in our other writers, so for the time beeing it is more safe to declare the "colspec" node an obligatory part of a table node.
The tables in Docutils are CALS tables, which are well documented on the web. From docutils.dtd:
This DTD uses the Exchange subset of the CALS-table model (OASIS
Technical Memorandum 9901:1999 "XML Exchange Table Model DTD",
http://www.oasis-open.org/html/tm9901.htm).
Thanks for the report. However,
In Docutils tables, the 'colspec' node is mandatory.
In the next Docutils release, the documentation will make this more clear.