@@ -110,27 +110,29 @@ def _is_separating_line(row):
110
110
return is_sl
111
111
112
112
113
- def _pipe_segment_with_colons (align , colwidth ):
113
+ def _segment_with_colons (align , colwidth , sep = "-" ):
114
114
"""Return a segment of a horizontal line with optional colons which
115
115
indicate column's alignment (as in `pipe` output format)."""
116
116
w = colwidth
117
117
if align in ["right" , "decimal" ]:
118
- return ("-" * (w - 1 )) + ":"
118
+ return (sep * (w - 1 )) + ":"
119
119
elif align == "center" :
120
- return ":" + ("-" * (w - 2 )) + ":"
120
+ return ":" + (sep * (w - 2 )) + ":"
121
121
elif align == "left" :
122
- return ":" + ("-" * (w - 1 ))
122
+ return ":" + (sep * (w - 1 ))
123
123
else :
124
- return "-" * w
124
+ return sep * w
125
125
126
126
127
- def _pipe_line_with_colons (colwidths , colaligns ):
127
+ def _line_with_colons (colwidths , colaligns , begin = "|" , hline = "|" , sep = "-" , end = "|" ):
128
128
"""Return a horizontal line with optional colons to indicate column's
129
- alignment (as in `pipe` output format)."""
129
+ alignment (as in `pipe` and `github` output format)."""
130
130
if not colaligns : # e.g. printing an empty data frame (github issue #15)
131
131
colaligns = ["" ] * len (colwidths )
132
- segments = [_pipe_segment_with_colons (a , w ) for a , w in zip (colaligns , colwidths )]
133
- return "|" + "|" .join (segments ) + "|"
132
+ segments = [
133
+ _segment_with_colons (a , w , sep = sep ) for a , w in zip (colaligns , colwidths )
134
+ ]
135
+ return begin + hline .join (segments ) + end
134
136
135
137
136
138
def _mediawiki_row_with_attrs (separator , cell_values , colwidths , colaligns ):
@@ -470,8 +472,12 @@ def escape_empty(val):
470
472
with_header_hide = None ,
471
473
),
472
474
"github" : TableFormat (
473
- lineabove = Line ("|" , "-" , "|" , "|" ),
474
- linebelowheader = Line ("|" , "-" , "|" , "|" ),
475
+ lineabove = partial (
476
+ _line_with_colons , begin = "| " , hline = " | " , sep = "-" , end = " |"
477
+ ),
478
+ linebelowheader = partial (
479
+ _line_with_colons , begin = "| " , hline = " | " , sep = "-" , end = " |"
480
+ ),
475
481
linebetweenrows = None ,
476
482
linebelow = None ,
477
483
headerrow = DataRow ("|" , "|" , "|" ),
@@ -480,8 +486,10 @@ def escape_empty(val):
480
486
with_header_hide = ["lineabove" ],
481
487
),
482
488
"pipe" : TableFormat (
483
- lineabove = _pipe_line_with_colons ,
484
- linebelowheader = _pipe_line_with_colons ,
489
+ lineabove = partial (_line_with_colons , begin = "|" , hline = "|" , sep = "-" , end = "|" ),
490
+ linebelowheader = partial (
491
+ _line_with_colons , begin = "|" , hline = "|" , sep = "-" , end = "|"
492
+ ),
485
493
linebetweenrows = None ,
486
494
linebelow = None ,
487
495
headerrow = DataRow ("|" , "|" , "|" ),
0 commit comments