14 | 14 |
|
15 | 15 |
// Options provide toggles and overrides to control specific rendering behaviors.
|
16 | 16 |
type Options struct {
|
17 | |
PrettyTables bool // Turns on pretty ASCII rendering for table elements.
|
18 | |
OmitLinks bool // Turns on omitting links
|
|
17 |
PrettyTables bool // Turns on pretty ASCII rendering for table elements.
|
|
18 |
PrettyTablesOptions *PrettyTablesOptions // Configures pretty ASCII rendering for table elements.
|
|
19 |
OmitLinks bool // Turns on omitting links
|
|
20 |
}
|
|
21 |
|
|
22 |
// PrettyTablesOptions overrides tablewriter behaviors
|
|
23 |
type PrettyTablesOptions struct {
|
|
24 |
AutoFormatHeader bool
|
|
25 |
AutoWrapText bool
|
|
26 |
ReflowDuringAutoWrap bool
|
|
27 |
ColWidth int
|
|
28 |
ColumnSeparator string
|
|
29 |
RowSeparator string
|
|
30 |
CenterSeparator string
|
|
31 |
HeaderAlignment int
|
|
32 |
FooterAlignment int
|
|
33 |
Alignment int
|
|
34 |
ColumnAlignment []int
|
|
35 |
NewLine string
|
|
36 |
HeaderLine bool
|
|
37 |
RowLine bool
|
|
38 |
AutoMergeCells bool
|
|
39 |
Borders tablewriter.Border
|
|
40 |
}
|
|
41 |
|
|
42 |
// NewPrettyTablesOptions creates PrettyTablesOptions with default settings
|
|
43 |
func NewPrettyTablesOptions() *PrettyTablesOptions {
|
|
44 |
return &PrettyTablesOptions{
|
|
45 |
AutoFormatHeader: true,
|
|
46 |
AutoWrapText: true,
|
|
47 |
ReflowDuringAutoWrap: true,
|
|
48 |
ColWidth: tablewriter.MAX_ROW_WIDTH,
|
|
49 |
ColumnSeparator: tablewriter.COLUMN,
|
|
50 |
RowSeparator: tablewriter.ROW,
|
|
51 |
CenterSeparator: tablewriter.CENTER,
|
|
52 |
HeaderAlignment: tablewriter.ALIGN_DEFAULT,
|
|
53 |
FooterAlignment: tablewriter.ALIGN_DEFAULT,
|
|
54 |
Alignment: tablewriter.ALIGN_DEFAULT,
|
|
55 |
ColumnAlignment: []int{},
|
|
56 |
NewLine: tablewriter.NEWLINE,
|
|
57 |
HeaderLine: true,
|
|
58 |
RowLine: false,
|
|
59 |
AutoMergeCells: false,
|
|
60 |
Borders: tablewriter.Border{Left: true, Right: true, Bottom: true, Top: true},
|
|
61 |
}
|
19 | 62 |
}
|
20 | 63 |
|
21 | 64 |
// FromHTMLNode renders text output from a pre-parsed HTML document.
|
|
276 | 319 |
|
277 | 320 |
buf := &bytes.Buffer{}
|
278 | 321 |
table := tablewriter.NewWriter(buf)
|
|
322 |
if ctx.options.PrettyTablesOptions != nil {
|
|
323 |
options := ctx.options.PrettyTablesOptions
|
|
324 |
table.SetAutoFormatHeaders(options.AutoFormatHeader)
|
|
325 |
table.SetAutoWrapText(options.AutoWrapText)
|
|
326 |
table.SetReflowDuringAutoWrap(options.ReflowDuringAutoWrap)
|
|
327 |
table.SetColWidth(options.ColWidth)
|
|
328 |
table.SetColumnSeparator(options.ColumnSeparator)
|
|
329 |
table.SetRowSeparator(options.RowSeparator)
|
|
330 |
table.SetCenterSeparator(options.CenterSeparator)
|
|
331 |
table.SetHeaderAlignment(options.HeaderAlignment)
|
|
332 |
table.SetFooterAlignment(options.FooterAlignment)
|
|
333 |
table.SetAlignment(options.Alignment)
|
|
334 |
table.SetColumnAlignment(options.ColumnAlignment)
|
|
335 |
table.SetNewLine(options.NewLine)
|
|
336 |
table.SetHeaderLine(options.HeaderLine)
|
|
337 |
table.SetRowLine(options.RowLine)
|
|
338 |
table.SetAutoMergeCells(options.AutoMergeCells)
|
|
339 |
table.SetBorders(options.Borders)
|
|
340 |
}
|
279 | 341 |
table.SetHeader(ctx.tableCtx.header)
|
280 | 342 |
table.SetFooter(ctx.tableCtx.footer)
|
281 | 343 |
table.AppendBulk(ctx.tableCtx.body)
|