Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text builder can't handle all tables #12273

Open
eirrgang opened this issue Apr 12, 2024 · 1 comment
Open

Text builder can't handle all tables #12273

eirrgang opened this issue Apr 12, 2024 · 1 comment

Comments

@eirrgang
Copy link

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.

@picnixz
Copy link
Member

picnixz commented Apr 16, 2024

The HTML builder works fine because it doesn't care about the colwidth I think (we are just creating an HTML table and width is automatic).

The text builder doesn't compute its column width and plainly assumes that it's been given upon construction. So there is no dynamic recomputation every time you create a table. It's something we can easily fix, namely, you write everything in a matrix buffer, compute the colwidth if 'auto' and then voilà.

I diagnose the task's difficulty as "medium". You don't need expert skills but I wouldn't call the task 'easy'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants