4
4
"fmt"
5
5
"html"
6
6
"strings"
7
+
8
+ "github.com/jedib0t/go-pretty/v6/text"
7
9
)
8
10
9
11
const (
@@ -113,9 +115,9 @@ func (t *Table) htmlRenderColumn(out *strings.Builder, colStr string) {
113
115
out .WriteString (colStr )
114
116
}
115
117
116
- func (t * Table ) htmlRenderColumnAttributes (out * strings.Builder , colIdx int , hint renderHint ) {
118
+ func (t * Table ) htmlRenderColumnAttributes (out * strings.Builder , colIdx int , hint renderHint , alignOverride text. Align ) {
117
119
// determine the HTML "align"/"valign" property values
118
- align := t . getAlign ( colIdx , hint ) .HTMLProperty ()
120
+ align := alignOverride .HTMLProperty ()
119
121
vAlign := t .getVAlign (colIdx , hint ).HTMLProperty ()
120
122
// determine the HTML "class" property values for the colors
121
123
class := t .getColumnColors (colIdx , hint ).HTMLProperty ()
@@ -158,11 +160,31 @@ func (t *Table) htmlRenderRow(out *strings.Builder, row rowStr, hint renderHint)
158
160
t .htmlRenderColumnAutoIndex (out , hint )
159
161
}
160
162
163
+ align := t .getAlign (colIdx , hint )
164
+ rowConfig := t .getRowConfig (hint )
165
+ extraColumnsRendered := 0
166
+ if rowConfig .AutoMerge && ! hint .isSeparatorRow {
167
+ // get the real row to consider all lines in each column instead of just
168
+ // looking at the current "line"
169
+ rowUnwrapped := t .getRow (hint .rowNumber - 1 , hint )
170
+ for idx := colIdx + 1 ; idx < len (rowUnwrapped ); idx ++ {
171
+ if rowUnwrapped [colIdx ] != rowUnwrapped [idx ] {
172
+ break
173
+ }
174
+ align = rowConfig .getAutoMergeAlign ()
175
+ extraColumnsRendered ++
176
+ }
177
+ }
178
+
161
179
colStr , colTagName := t .htmlGetColStrAndTag (row , colIdx , hint )
162
180
// write the row
163
181
out .WriteString (" <" )
164
182
out .WriteString (colTagName )
165
- t .htmlRenderColumnAttributes (out , colIdx , hint )
183
+ t .htmlRenderColumnAttributes (out , colIdx , hint , align )
184
+ if extraColumnsRendered > 0 {
185
+ out .WriteString (" colspan=" )
186
+ out .WriteString (fmt .Sprint (extraColumnsRendered + 1 ))
187
+ }
166
188
out .WriteString (">" )
167
189
if len (colStr ) == 0 {
168
190
out .WriteString (t .style .HTML .EmptyColumn )
@@ -172,6 +194,7 @@ func (t *Table) htmlRenderRow(out *strings.Builder, row rowStr, hint renderHint)
172
194
out .WriteString ("</" )
173
195
out .WriteString (colTagName )
174
196
out .WriteString (">\n " )
197
+ colIdx += extraColumnsRendered
175
198
}
176
199
out .WriteString (" </tr>\n " )
177
200
}
0 commit comments