Tables: Support widths: auto and make it the default - #20
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthrough
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/rst2typst/writer.py (1)
542-554: ⚡ Quick winCode clarity issue: confusing node-to-string comparison.
Line 549's condition
if colwidths_given and colspec != "auto":is semantically confusing. The variablecolspecis anodes.colspecobject, not a string, so the comparisoncolspec != "auto"will always evaluate toTrue. This makes the condition effectively identical toif colwidths_given:, rendering the second part redundant and unclear to readers.The logic is functionally correct and mirrors the pattern used by Sphinx's LaTeX writer, which checks if
'colwidths-given'is in the table's classes and uses fixed-width column specs in that case. However, the unnecessary comparison should be removed for clarity:Suggested simplification
def visit_tgroup(self, node: nodes.tgroup): # Only use fixed widths if explicitly specified. table_node = node.parent colwidths_given = 'colwidths-given' in table_node.get('classes', []) cols = [] for colspec in node.findall(nodes.colspec): - if colwidths_given and colspec != "auto": + if colwidths_given: cols.append(f"{colspec['colwidth']}fr") else: cols.append("auto")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/rst2typst/writer.py` around lines 542 - 554, In the visit_tgroup method, the condition on line 549 compares the colspec node object directly to the string "auto", which will always be True and makes the logic confusing. Replace the comparison `colspec != "auto"` with `colspec['colwidth'] != "auto"` to properly check the colwidth attribute value against the string literal, ensuring the code correctly applies fixed-width columns only when both colwidths_given is True and the specific column width is not "auto".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/rst2typst/writer.py`:
- Around line 542-554: In the visit_tgroup method, the condition on line 549
compares the colspec node object directly to the string "auto", which will
always be True and makes the logic confusing. Replace the comparison `colspec !=
"auto"` with `colspec['colwidth'] != "auto"` to properly check the colwidth
attribute value against the string literal, ensuring the code correctly applies
fixed-width columns only when both colwidths_given is True and the specific
column width is not "auto".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f3294a6c-65e7-4122-b548-ca84f697e2a5
📒 Files selected for processing (6)
docs/spec/tables/grid-table.typ.txtdocs/spec/tables/index.rstdocs/spec/tables/list-table-autolayout.rst.txtdocs/spec/tables/list-table-autolayout.typ.txtdocs/spec/tables/simple-table.typ.txtsrc/rst2typst/writer.py
|
I think our friend Code Rabbit has a point in #20 (review): Did you mean to write |
|
I had a closer look at the docutils spec at https://www.docutils.org/docs/ref/rst/directives.html and I think I now know what the original implementation intended :-) I added a couple more unit tests for I learned: Mixing explicit column widths with |
Support the `widths: auto` option of `table`, `csv-table` and `list-table` directives, as specified in https://www.docutils.org/docs/ref/rst/directives.html. Make the Typst writer use `widths: auto` by default, similar to the HTML5 or LaTeX writers, for cases where no `widths` option is given.
|
@CodeRabbit review |
✅ Action performedReview finished.
|
c595a29 to
7a0e867
Compare
|
Thank you! |
Support the
widths: autooption oftable,csv-tableandlist-tabledirectives, as specified in https://www.docutils.org/docs/ref/rst/directives.html.Make the Typst writer use
widths: autoby default, similar to the HTML5 or LaTeX writers, for cases where nowidthsoption is given.Summary by CodeRabbit
Documentation
Bug Fixes