sphinx-doc/sphinx

Text builder can't handle all tables

Open

#12,273 创建于 2024年4月12日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)Python (1,985 fork)batch import
builder:texthelp wantedtype:bug

仓库指标

Star
 (5,625 star)
PR 合并指标
 (平均合并 10天 11小时) (30 天内合并 11 个 PR)

描述

Describe the bug

It seems like the text builder can't handle all of the same tables that the html builder can. It is apparently possible for Table.colwidth elements to have a string value of 'auto', but Table.cell_width() assumes integer values.

...
  File ".../docutils/nodes.py", line 199, in walkabout
    visitor.dispatch_departure(self)
  File ".../sphinx/util/docutils.py", line 599, in dispatch_departure
    method(node)
  File ".../sphinx/writers/text.py", line 903, in depart_table
    self.add_text(str(self.table))
                  ^^^^^^^^^^^^^^^
  File ".../sphinx/writers/text.py", line 202, in __str__
    self.rewrap()
  File ".../sphinx/writers/text.py", line 181, in rewrap
    cell.wrap(width=self.cell_width(cell, self.colwidth))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../sphinx/writers/text.py", line 163, in cell_width
    width += source[cell.col + i]
TypeError: unsupported operand type(s) for +=: 'int' and 'str'

The problem occurs with a table provided through the Breathe extension, but the html builder handles it just fine.

How to Reproduce

I'm sorry for the complexity of the example. I don't know what determines whether a table node has column widths that are integers versus 'auto'. In pure RsT parts of my doctree, a Table produces Table.colwidth == [50, 50]. For the table that comes through Breathe, I see Table.colwidth = ['auto', 'auto'], which builds fine for the html builder, but can't be processed by the text builder.

  1. Create a doxygen comment block with a table using syntax like the following.
 *
 * colA    | colB
 * -------   | -------
 * term1     | definition1
 * term2    | definition2
  1. Produce Doxygen XML. Process with Breathe with a call like sphinx-build -b text . output/text

Environment Information

Platform:              darwin; (macOS-14.4.1-arm64-arm-64bit)
Python version:        3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)])
Python implementation: CPython
Sphinx version:        7.2.6
Docutils version:      0.20.1
Jinja2 version:        3.1.3
Pygments version:      2.17.2

Sphinx extensions

notably: breathe (4.35.0)

Additional context

The content that is being processed when the error occurs is extracted by breathe (4.35.0) from XML produced by Doxygen 1.10.0.

贡献者指南