| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Follow up on astanin#410; Refs astanin#260 and astanin#261.
Codecov Report❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
@@ Coverage Diff @@
## master #426 +/- ##
==========================================
+ Coverage 90.18% 90.20% +0.02%
==========================================
Files 3 3
Lines 958 960 +2
Branches 228 228
==========================================
+ Hits 864 866 +2
Misses 60 60
Partials 34 34 ☔ View full report in Codecov by Sentry.
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Follow-up to #410, which gave the github format alignment colons in separator rows by aliasing it to pipe.
This PR fixes a second inconsistency in pipe that #410 inherited: separator rows ignore the format's declared padding.
Problem
The pipe and github formats declare padding=1. Data rows honour this: _pad_row adds a space on each side of cell content. Separator rows do not: _pipe_segment_with_colons fills the full padded width with dashes, swallowing the padding positions.
The separator row is the only place in the table where padding=1 is silently ignored.
Fix
After this change, separator rows respect the format's padding, consistent with data rows:
Column widths are preserved: two padding spaces replace two dashes, keeping each segment the same total width.
The implementation adds a padding parameter to _pipe_segment_with_colons. When non-zero, it places spaces at the padding positions instead of filling them with dashes:
The padding parameter flows through the existing call chain:
Other callable line formats (_grid_line_with_colons, _html_begin_table_without_header, _latex_line_begin_tabular, _asciidoc_row) accept **kwargs for forward compatibility but do not use the parameter, so their output is unchanged.
Custom padding=0 formats are unaffected
The custom TableFormat with padding=0 shown in #195 (comment) is not affected by this change. That example uses non-callable Line objects (not _pipe_line_with_colons), so _build_line takes the else branch which is untouched. And with padding=0, the _pipe_segment_with_colons path produces zero-width padding strings, which is a no-op.
Original example from @astanin still produces the exact same output:
Discovery context
I found this while investigating an infinite formatting cycle in click-extra between two CI jobs: one regenerates a markdown table using tabulate with tablefmt="github", the other normalizes markdown files with mdformat. Each run undid the other's output on the separator row: tabulate produced |:---|, mdformat normalized it to | :-- |, and the cycle repeated.
The concrete fight is visible in https://github.com/kdeldycke/click-extra/pull/1603/changes#diff-21283f808de8251aeb373ddd7d30d906afbb0f4dfe168733afb14f7ae6137984 (table regeneration strips spaces) and https://github.com/kdeldycke/click-extra/pull/1611/changes#diff-21283f808de8251aeb373ddd7d30d906afbb0f4dfe168733afb14f7ae6137984 (mdformat re-adds them), both touching docs/pygments.md.
Neither tool was wrong: GFM accepts both forms. The root cause was that tabulate's pipe format declared padding=1 but only honoured it for data rows. With this fix, tabulate's output already matches what GFM normalizers expect, so the cycle stops.
History
This is the second half of a fix I started in 2023:
#410 solved the alignment colon problem but did not address the padding inconsistency in separator rows, because the pipe format itself had the same behaviour. This PR completes the chain by making separator rows respect the format's declared padding, just like data rows already do.