Respect padding in pipe/github separator rows#426
Open
kdeldycke wants to merge 1 commit intoastanin:masterfrom
Open
Respect padding in pipe/github separator rows#426kdeldycke wants to merge 1 commit intoastanin:masterfrom
padding in pipe/github separator rows#426kdeldycke wants to merge 1 commit intoastanin:masterfrom
Conversation
kdeldycke
added a commit
to kdeldycke/click-extra
that referenced
this pull request
Apr 6, 2026
a16c979 to
1e997d3
Compare
Follow up on astanin#410; Refs astanin#260 and astanin#261.
1e997d3 to
e647025
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #410, which gave the
githubformat alignment colons in separator rows by aliasing it topipe.This PR fixes a second inconsistency in
pipethat #410 inherited: separator rows ignore the format's declaredpadding.Problem
The
pipeandgithubformats declarepadding=1. Data rows honour this:_pad_rowadds a space on each side of cell content. Separator rows do not:_pipe_segment_with_colonsfills the full padded width with dashes, swallowing the padding positions.The separator row is the only place in the table where
padding=1is 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
paddingparameter to_pipe_segment_with_colons. When non-zero, it places spaces at the padding positions instead of filling them with dashes:paddingignored)padding=1honoured)|:--------|| :------ ||--------:|| ------: ||:-------:|| :-----: ||---------|| ------- |The
paddingparameter flows through the existing call chain:_format_tablealready haspad = fmt.padding._append_lineand_build_linenow accept an optionalpaddingkeyword and forward it to callable line formats._pipe_line_with_colonspasses it to_pipe_segment_with_colons.Other callable line formats (
_grid_line_with_colons,_html_begin_table_without_header,_latex_line_begin_tabular,_asciidoc_row) accept**kwargsfor forward compatibility but do not use the parameter, so their output is unchanged.Custom
padding=0formats are unaffectedThe custom
TableFormatwithpadding=0shown in #195 (comment) is not affected by this change. That example uses non-callableLineobjects (not_pipe_line_with_colons), so_build_linetakes theelsebranch which is untouched. And withpadding=0, the_pipe_segment_with_colonspath 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
tabulatewithtablefmt="github", the other normalizes markdown files with mdformat. Each run undid the other's output on the separator row: tabulate produced|:---|,mdformatnormalized 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 (
mdformatre-adds them), both touchingdocs/pygments.md.Neither tool was wrong: GFM accepts both forms. The root cause was that tabulate's
pipeformat declaredpadding=1but 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:
githubtables #410 finally landed the alignment colon fix by aliasinggithubtopipe. Merged 2026-03-05, after thev0.10.0tag.#410 solved the alignment colon problem but did not address the padding inconsistency in separator rows, because the
pipeformat 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.