From 150ea33d20b8d0b9f1591ff6d54c19adb84882e3 Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 14:41:40 -0500 Subject: [PATCH 01/15] table: add `padColumns` option to tables This option will allow the user to specify if tables should include the visual padding or just include the minimum required amount of characters to render properly as a table. Addresses https://github.com/JohannesKaufmann/html-to-markdown/issues/145 --- plugin/table/table.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugin/table/table.go b/plugin/table/table.go index 4058d9d..736ac85 100644 --- a/plugin/table/table.go +++ b/plugin/table/table.go @@ -71,6 +71,16 @@ func WithNewlineBehavior(behavior NewlineBehavior) option { } } +// WithPadColumns configures how to handle padding in table cells. +// When set to true (default), every column's text is padded to the width of the largest column in its row. +// When set to false, no extra padding is applied to columns. +func WithPadColumns(pad bool) option { + return func(p *tablePlugin) error { + p.padColumns = pad + return nil + } +} + // WithSkipEmptyRows configures the table plugin to omit empty rows from the output. // An empty row is defined as a row where all cells contain no content or only whitespace. // When set to true, empty rows will be omitted from the output. When false (default), @@ -113,6 +123,7 @@ type tablePlugin struct { skipEmptyRows bool promoteFirstRowToHeader bool convertPresentationTables bool + padColumns bool } func (p *tablePlugin) setError(err error) { From 3591da55efddf109e904dde5a08bd42d0ebc7a68 Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 14:44:54 -0500 Subject: [PATCH 02/15] table renderer: add logic to account for `padColumns` option Adds conditions to the logic that writes the extra padding characters. Doesn't write the extra characters if the `padColumns` option is false. --- plugin/table/3_render.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/table/3_render.go b/plugin/table/3_render.go index d941487..abe3abb 100644 --- a/plugin/table/3_render.go +++ b/plugin/table/3_render.go @@ -73,7 +73,11 @@ func (s *tablePlugin) writeHeaderUnderline(w converter.Writer, alignments []stri w.WriteString("-") } - w.WriteString(strings.Repeat("-", maxLength)) + if s.padColumns { + w.WriteString(strings.Repeat("-", maxLength)) + } else { + w.WriteString("-") + } if align == "right" || align == "center" { w.WriteString(":") @@ -96,7 +100,7 @@ func (s *tablePlugin) writeRow(w converter.Writer, counts []int, cells [][]byte) currentCount := utf8.RuneCount(cell) filler := counts[i] - currentCount - if filler > 0 { + if s.padColumns && filler > 0 { w.WriteString(strings.Repeat(" ", filler)) } From e5681ff5d290c59df3331360a39ed0a7caed7126 Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 14:47:26 -0500 Subject: [PATCH 03/15] cli: add `tablePadColumns` option to cli, default `true` Adds flag to the CLI for the new `padColumns` option. Default value should be true to preserve the original expected behavior of html2mardown. --- cli/html2markdown/cmd/cmd_convert.go | 1 + cli/html2markdown/cmd/exec.go | 1 + cli/html2markdown/cmd/flags.go | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/cli/html2markdown/cmd/cmd_convert.go b/cli/html2markdown/cmd/cmd_convert.go index a5447e7..d7c8876 100644 --- a/cli/html2markdown/cmd/cmd_convert.go +++ b/cli/html2markdown/cmd/cmd_convert.go @@ -112,6 +112,7 @@ func (cli *CLI) convert(input []byte) ([]byte, error) { table.WithSpanCellBehavior(table.SpanCellBehavior(cli.config.tableSpanCellBehavior)), table.WithPresentationTables(cli.config.tablePresentationTables), table.WithNewlineBehavior(table.NewlineBehavior(cli.config.tableNewlineBehavior)), + table.WithPadColumns(cli.config.tablePadColumns), ), ) } diff --git a/cli/html2markdown/cmd/exec.go b/cli/html2markdown/cmd/exec.go index dfc0ed8..7e35df3 100644 --- a/cli/html2markdown/cmd/exec.go +++ b/cli/html2markdown/cmd/exec.go @@ -46,6 +46,7 @@ type Config struct { tableSpanCellBehavior string tablePresentationTables bool tableNewlineBehavior string + tablePadColumns bool } // Release holds the information (from the 3 ldflags) that goreleaser sets. diff --git a/cli/html2markdown/cmd/flags.go b/cli/html2markdown/cmd/flags.go index 623294c..3096d04 100644 --- a/cli/html2markdown/cmd/flags.go +++ b/cli/html2markdown/cmd/flags.go @@ -94,6 +94,7 @@ func (cli *CLI) initFlags(progname string) { cli.flags.StringVar(&cli.config.tableSpanCellBehavior, "opt-table-span-cell-behavior", "", `[for --plugin-table] how colspan/rowspan should be rendered: "empty" or "mirror"`) cli.flags.BoolVar(&cli.config.tablePresentationTables, "opt-table-presentation-tables", false, `[for --plugin-table] whether tables with role="presentation" should be converted`) cli.flags.StringVar(&cli.config.tableNewlineBehavior, "opt-table-newline-behavior", "", `[for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve"`) + cli.flags.BoolVar(&cli.config.tablePadColumns, "opt-table-pad-columns", true, `[for --plugin-table] whether columns in the tables should include extra padding for visual continuity`) } func (cli *CLI) parseFlags(args []string) error { @@ -120,6 +121,9 @@ func (cli *CLI) parseFlags(args []string) error { if cli.config.tableNewlineBehavior != "" && !cli.config.enablePluginTable { return fmt.Errorf("--opt-table-newline-behavior requires --plugin-table to be enabled") } + if cli.config.tablePadColumns && !cli.config.enablePluginTable { + return fmt.Errorf("--opt-table-pad-columns requires --plugin-table to be enabled") + } // TODO: use constant for flag name & use formatFlag // var keyStrongDelimiter = "opt-strong-delimiter" From 9f8f22521acdfe91c5b6e21cfdcc5e4e85cb1c38 Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 14:49:00 -0500 Subject: [PATCH 04/15] cli: update stdout golden files with new cli option --- .../cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden | 3 +++ .../testdata/TestExecute/[general]_help_terminal/stdout.golden | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden index 7d5025e..0fb58c2 100644 --- a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden +++ b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden @@ -78,6 +78,9 @@ Use a HTML sanitizer before displaying the HTML in the browser! --opt-table-newline-behavior [for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve" + --opt-table-pad-columns + [for --plugin-table] whether columns in the tables should include extra padding for visual continuity + --opt-table-presentation-tables [for --plugin-table] whether tables with role="presentation" should be converted diff --git a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden index 7d5025e..0fb58c2 100644 --- a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden +++ b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden @@ -78,6 +78,9 @@ Use a HTML sanitizer before displaying the HTML in the browser! --opt-table-newline-behavior [for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve" + --opt-table-pad-columns + [for --plugin-table] whether columns in the tables should include extra padding for visual continuity + --opt-table-presentation-tables [for --plugin-table] whether tables with role="presentation" should be converted From 28eb6ae00141ce8ca5c72c95f34c08810556d319 Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 15:23:36 -0500 Subject: [PATCH 05/15] padColumns: switch to using string option instead of bool With bool, the way the logic is constructed means there's not an easy way to have the option default to true. Would need to check if the flag was set in the CLI, then if not (and if plugin-table was enabled), set the value to true. It's just way easier to do a string and default to "on", so that's how we're doing things! --- cli/html2markdown/cmd/cmd_convert.go | 2 +- cli/html2markdown/cmd/exec.go | 2 +- cli/html2markdown/cmd/flags.go | 4 ++-- plugin/table/3_render.go | 4 ++-- plugin/table/table.go | 28 ++++++++++++++++++++++++---- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/cli/html2markdown/cmd/cmd_convert.go b/cli/html2markdown/cmd/cmd_convert.go index d7c8876..8997c16 100644 --- a/cli/html2markdown/cmd/cmd_convert.go +++ b/cli/html2markdown/cmd/cmd_convert.go @@ -112,7 +112,7 @@ func (cli *CLI) convert(input []byte) ([]byte, error) { table.WithSpanCellBehavior(table.SpanCellBehavior(cli.config.tableSpanCellBehavior)), table.WithPresentationTables(cli.config.tablePresentationTables), table.WithNewlineBehavior(table.NewlineBehavior(cli.config.tableNewlineBehavior)), - table.WithPadColumns(cli.config.tablePadColumns), + table.WithPadColumns(table.PadColumnsBehavior(cli.config.tablePadColumns)), ), ) } diff --git a/cli/html2markdown/cmd/exec.go b/cli/html2markdown/cmd/exec.go index 7e35df3..a63249e 100644 --- a/cli/html2markdown/cmd/exec.go +++ b/cli/html2markdown/cmd/exec.go @@ -46,7 +46,7 @@ type Config struct { tableSpanCellBehavior string tablePresentationTables bool tableNewlineBehavior string - tablePadColumns bool + tablePadColumns string } // Release holds the information (from the 3 ldflags) that goreleaser sets. diff --git a/cli/html2markdown/cmd/flags.go b/cli/html2markdown/cmd/flags.go index 3096d04..1adf816 100644 --- a/cli/html2markdown/cmd/flags.go +++ b/cli/html2markdown/cmd/flags.go @@ -94,7 +94,7 @@ func (cli *CLI) initFlags(progname string) { cli.flags.StringVar(&cli.config.tableSpanCellBehavior, "opt-table-span-cell-behavior", "", `[for --plugin-table] how colspan/rowspan should be rendered: "empty" or "mirror"`) cli.flags.BoolVar(&cli.config.tablePresentationTables, "opt-table-presentation-tables", false, `[for --plugin-table] whether tables with role="presentation" should be converted`) cli.flags.StringVar(&cli.config.tableNewlineBehavior, "opt-table-newline-behavior", "", `[for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve"`) - cli.flags.BoolVar(&cli.config.tablePadColumns, "opt-table-pad-columns", true, `[for --plugin-table] whether columns in the tables should include extra padding for visual continuity`) + cli.flags.StringVar(&cli.config.tablePadColumns, "opt-table-pad-columns", "", `[for --plugin-table] whether columns in the tables should include extra padding for visual continuity`) } func (cli *CLI) parseFlags(args []string) error { @@ -121,7 +121,7 @@ func (cli *CLI) parseFlags(args []string) error { if cli.config.tableNewlineBehavior != "" && !cli.config.enablePluginTable { return fmt.Errorf("--opt-table-newline-behavior requires --plugin-table to be enabled") } - if cli.config.tablePadColumns && !cli.config.enablePluginTable { + if cli.config.tablePadColumns != "" && !cli.config.enablePluginTable { return fmt.Errorf("--opt-table-pad-columns requires --plugin-table to be enabled") } diff --git a/plugin/table/3_render.go b/plugin/table/3_render.go index abe3abb..b0ccd6d 100644 --- a/plugin/table/3_render.go +++ b/plugin/table/3_render.go @@ -73,7 +73,7 @@ func (s *tablePlugin) writeHeaderUnderline(w converter.Writer, alignments []stri w.WriteString("-") } - if s.padColumns { + if s.padColumns == "on" { w.WriteString(strings.Repeat("-", maxLength)) } else { w.WriteString("-") @@ -100,7 +100,7 @@ func (s *tablePlugin) writeRow(w converter.Writer, counts []int, cells [][]byte) currentCount := utf8.RuneCount(cell) filler := counts[i] - currentCount - if s.padColumns && filler > 0 { + if s.padColumns == "on" && filler > 0 { w.WriteString(strings.Repeat(" ", filler)) } diff --git a/plugin/table/table.go b/plugin/table/table.go index 736ac85..df22f4f 100644 --- a/plugin/table/table.go +++ b/plugin/table/table.go @@ -71,13 +71,33 @@ func WithNewlineBehavior(behavior NewlineBehavior) option { } } +type PadColumnsBehavior string + +const ( + // PadColumnsBehaviorOn adds visual padding to cells to make each column equal width (default). + PadColumnsBehaviorOn PadColumnsBehavior = "on" + // PadColumnsBehaviorOff refrains from adding the padding to the cells. + PadColumnsBehaviorOff PadColumnsBehavior = "off" +) + // WithPadColumns configures how to handle padding in table cells. // When set to true (default), every column's text is padded to the width of the largest column in its row. // When set to false, no extra padding is applied to columns. -func WithPadColumns(pad bool) option { +func WithPadColumns(behavior PadColumnsBehavior) option { return func(p *tablePlugin) error { - p.padColumns = pad - return nil + switch behavior { + case "": + // Allow empty string to default to "on" + p.padColumns = PadColumnsBehavior(PadColumnsBehaviorOn) + return nil + + case PadColumnsBehaviorOn, PadColumnsBehaviorOff: + p.padColumns = behavior + return nil + + default: + return fmt.Errorf("unknown value %q for pad columns behavior", behavior) + } } } @@ -123,7 +143,7 @@ type tablePlugin struct { skipEmptyRows bool promoteFirstRowToHeader bool convertPresentationTables bool - padColumns bool + padColumns PadColumnsBehavior } func (p *tablePlugin) setError(err error) { From 9c072f3a8eb618f4c9a9ce32b1e4242a1331e7ac Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 15:28:00 -0500 Subject: [PATCH 06/15] cli: Update flag to mention "on" and "off" values in cli output --- cli/html2markdown/cmd/flags.go | 2 +- .../cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden | 2 +- .../testdata/TestExecute/[general]_help_terminal/stdout.golden | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/html2markdown/cmd/flags.go b/cli/html2markdown/cmd/flags.go index 1adf816..6605b1a 100644 --- a/cli/html2markdown/cmd/flags.go +++ b/cli/html2markdown/cmd/flags.go @@ -94,7 +94,7 @@ func (cli *CLI) initFlags(progname string) { cli.flags.StringVar(&cli.config.tableSpanCellBehavior, "opt-table-span-cell-behavior", "", `[for --plugin-table] how colspan/rowspan should be rendered: "empty" or "mirror"`) cli.flags.BoolVar(&cli.config.tablePresentationTables, "opt-table-presentation-tables", false, `[for --plugin-table] whether tables with role="presentation" should be converted`) cli.flags.StringVar(&cli.config.tableNewlineBehavior, "opt-table-newline-behavior", "", `[for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve"`) - cli.flags.StringVar(&cli.config.tablePadColumns, "opt-table-pad-columns", "", `[for --plugin-table] whether columns in the tables should include extra padding for visual continuity`) + cli.flags.StringVar(&cli.config.tablePadColumns, "opt-table-pad-columns", "", `[for --plugin-table] whether columns in the tables should include extra padding for visual continuity: "on" or "off"`) } func (cli *CLI) parseFlags(args []string) error { diff --git a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden index 0fb58c2..84202b7 100644 --- a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden +++ b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden @@ -79,7 +79,7 @@ Use a HTML sanitizer before displaying the HTML in the browser! [for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve" --opt-table-pad-columns - [for --plugin-table] whether columns in the tables should include extra padding for visual continuity + [for --plugin-table] whether columns in the tables should include extra padding for visual continuity: "on" or "off" --opt-table-presentation-tables [for --plugin-table] whether tables with role="presentation" should be converted diff --git a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden index 0fb58c2..84202b7 100644 --- a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden +++ b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden @@ -79,7 +79,7 @@ Use a HTML sanitizer before displaying the HTML in the browser! [for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve" --opt-table-pad-columns - [for --plugin-table] whether columns in the tables should include extra padding for visual continuity + [for --plugin-table] whether columns in the tables should include extra padding for visual continuity: "on" or "off" --opt-table-presentation-tables [for --plugin-table] whether tables with role="presentation" should be converted From 6d21f2802b2dd33df1276d3000686c56db9d3107 Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 16:02:18 -0500 Subject: [PATCH 07/15] render: switch to specific PadColumnsBehavior type for comparison --- plugin/table/3_render.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/table/3_render.go b/plugin/table/3_render.go index b0ccd6d..b1f3b5b 100644 --- a/plugin/table/3_render.go +++ b/plugin/table/3_render.go @@ -73,7 +73,7 @@ func (s *tablePlugin) writeHeaderUnderline(w converter.Writer, alignments []stri w.WriteString("-") } - if s.padColumns == "on" { + if s.padColumns == PadColumnsBehaviorOn { w.WriteString(strings.Repeat("-", maxLength)) } else { w.WriteString("-") @@ -100,7 +100,7 @@ func (s *tablePlugin) writeRow(w converter.Writer, counts []int, cells [][]byte) currentCount := utf8.RuneCount(cell) filler := counts[i] - currentCount - if s.padColumns == "on" && filler > 0 { + if s.padColumns == PadColumnsBehaviorOn && filler > 0 { w.WriteString(strings.Repeat(" ", filler)) } From 13571caabbc7e6fc2f0097a210c3e9ba8bb979d3 Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 16:02:45 -0500 Subject: [PATCH 08/15] table_test: add tests for new table option I'm not too familiar with Go, so forgive me if I made a bunch of changes I wasn't supposed to here. When compiling and running it from the command line, the option would correctly default to the value of "on" in my manual testing. However, I couldn't for the life of me get it to behave like that in the tests without specifically going into each one's options and explicltly adding `WithPadColumns(PadColumnBehaviorOn)`. I assumed it would default without that, but evidently not, and this was the only way that the tests would work as expected. --- plugin/table/table_test.go | 121 ++++++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 7 deletions(-) diff --git a/plugin/table/table_test.go b/plugin/table/table_test.go index 592f258..32e958b 100644 --- a/plugin/table/table_test.go +++ b/plugin/table/table_test.go @@ -17,7 +17,9 @@ func TestGoldenFiles(t *testing.T) { converter.WithPlugins( base.NewBasePlugin(), commonmark.NewCommonmarkPlugin(), - NewTablePlugin(), + NewTablePlugin( + WithPadColumns(PadColumnsBehaviorOn), + ), ), ) @@ -34,6 +36,7 @@ func TestOptionFunc_Validation(t *testing.T) { commonmark.NewCommonmarkPlugin(), NewTablePlugin( WithSpanCellBehavior("random"), + WithPadColumns(PadColumnsBehaviorOn), ), ), ) @@ -63,6 +66,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "default", options: []option{ WithSpanCellBehavior(SpanBehaviorEmpty), + WithPadColumns(PadColumnsBehaviorOn), }, input: ` @@ -84,6 +88,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "colspan=3", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -104,6 +109,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "rowspan=3", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -127,6 +133,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "cell with colspan and rowspan", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -149,6 +156,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "shifting content", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -176,6 +184,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "rowspans overlap with colspans", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -236,8 +245,10 @@ func TestOptionFunc_EmptyRows(t *testing.T) { }{ // - - - - - - - - - - default - - - - - - - - - - // { - desc: "by default keep empty rows", - options: []option{}, + desc: "by default keep empty rows", + options: []option{ + WithPadColumns(PadColumnsBehaviorOn), + }, input: `
@@ -266,6 +277,7 @@ func TestOptionFunc_EmptyRows(t *testing.T) { desc: "some rows are empty", options: []option{ WithSkipEmptyRows(true), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -298,6 +310,7 @@ func TestOptionFunc_EmptyRows(t *testing.T) { desc: "all rows are empty", options: []option{ WithSkipEmptyRows(true), + WithPadColumns(PadColumnsBehaviorOn), }, input: `

Before

@@ -332,6 +345,7 @@ After desc: "element that is not rendered", options: []option{ WithSkipEmptyRows(true), + WithPadColumns(PadColumnsBehaviorOn), }, input: `

Before

@@ -387,8 +401,10 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { }{ // - - - - - - - - - - default - - - - - - - - - - // { - desc: "default", - options: []option{}, + desc: "default", + options: []option{ + WithPadColumns(PadColumnsBehaviorOn), + }, input: `
@@ -412,6 +428,7 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { desc: "not needed", options: []option{ WithHeaderPromotion(true), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -441,6 +458,7 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { desc: "promote first row", options: []option{ WithHeaderPromotion(true), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -464,6 +482,7 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { desc: "promote first row (but it is empty)", options: []option{ WithHeaderPromotion(true), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -493,6 +512,7 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { options: []option{ WithHeaderPromotion(true), WithSkipEmptyRows(true), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -550,8 +570,10 @@ func TestOptionFunc_PresentationTable(t *testing.T) { expected string }{ { - desc: "default", - options: []option{}, + desc: "default", + options: []option{ + WithPadColumns(PadColumnsBehaviorOn), + }, input: `
@@ -574,6 +596,7 @@ B1 B2 desc: "keep the presentation table", options: []option{ WithPresentationTables(true), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -631,6 +654,7 @@ func TestTableWithNewlines(t *testing.T) { desc: "with skip behavior (default)", options: []option{ WithNewlineBehavior(NewlineBehaviorSkip), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -648,6 +672,7 @@ A12 desc: "with preserve behavior", options: []option{ WithNewlineBehavior(NewlineBehaviorPreserve), + WithPadColumns(PadColumnsBehaviorOn), }, input: `
@@ -689,3 +714,85 @@ A12 }) } } + +func TestOptionFunc_PadColumns(t *testing.T) { + testCases := []struct { + desc string + input string + options []option + expected string + }{ + { + desc: "with padding behavior (default)", + options: []option{ + WithPadColumns(PadColumnsBehaviorOn), + }, + input: ` +
+ + + + + + + + +
This line has some way longer text than the other line below it.A2
B1This one has longer text than the line above.
+ `, + expected: ` +| | | +|------------------------------------------------------------------|-----------------------------------------------| +| This line has some way longer text than the other line below it. | A2 | +| B1 | This one has longer text than the line above. | + `, + }, + { + desc: "without padding behavior", + options: []option{ + WithPadColumns(PadColumnsBehaviorOff), + }, + input: ` + + + + + + + + + +
This line has some way longer text than the other line below it.A2
B1This one has longer text than the line above.
+ `, + expected: ` +| | | +|---|---| +| This line has some way longer text than the other line below it. | A2 | +| B1 | This one has longer text than the line above. | +`, + }, + } + + for _, tC := range testCases { + t.Run(tC.desc, func(t *testing.T) { + conv := converter.NewConverter( + converter.WithPlugins( + base.NewBasePlugin(), + commonmark.NewCommonmarkPlugin(), + NewTablePlugin(tC.options...), + ), + ) + + output, err := conv.ConvertString(tC.input) + if err != nil { + t.Error(err) + } + + actual := strings.TrimSpace(output) + expected := strings.TrimSpace(tC.expected) + + if actual != expected { + t.Errorf("expected\n%s\nbut got\n%s\n", expected, actual) + } + }) + } +} From e2ea5d9590ef48b12896c9a80779286fdf51204f Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 16:30:54 -0500 Subject: [PATCH 09/15] renderer: remove extra spaces if padding option is off There would always be 2 spaces between `|` characters if there was no text in the cell. Now it checks if the padding option is turned on, and if it isn't then the spaces aren't necessary for this to render properly --- plugin/table/3_render.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugin/table/3_render.go b/plugin/table/3_render.go index b1f3b5b..9693198 100644 --- a/plugin/table/3_render.go +++ b/plugin/table/3_render.go @@ -94,16 +94,24 @@ func (s *tablePlugin) writeRow(w converter.Writer, counts []int, cells [][]byte) if isFirstCell { w.WriteString("|") } - w.WriteString(" ") - w.Write(cell) currentCount := utf8.RuneCount(cell) filler := counts[i] - currentCount + if s.padColumns == PadColumnsBehaviorOn { + w.WriteString(" ") + } + + w.Write(cell) + if s.padColumns == PadColumnsBehaviorOn && filler > 0 { w.WriteString(strings.Repeat(" ", filler)) } - w.WriteString(" |") + if s.padColumns == PadColumnsBehaviorOn { + w.WriteString(" ") + } + + w.WriteString("|") } } From 5fd8cf8bafc450ae53357b148dc6cece34e16ecb Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 16:57:24 -0500 Subject: [PATCH 10/15] table_test: update test to work with changed behavior Now when the padding option is off, it won't include any spaces in between `|` characters, since they aren't necessary for the output to render properly. --- plugin/table/table_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/table/table_test.go b/plugin/table/table_test.go index 32e958b..2c70e21 100644 --- a/plugin/table/table_test.go +++ b/plugin/table/table_test.go @@ -764,10 +764,10 @@ func TestOptionFunc_PadColumns(t *testing.T) { `, expected: ` -| | | +||| |---|---| -| This line has some way longer text than the other line below it. | A2 | -| B1 | This one has longer text than the line above. | +|This line has some way longer text than the other line below it.|A2| +|B1|This one has longer text than the line above.| `, }, } From 1f84cf9fa1f7406660d6ac80faa9d76717dd88bd Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 17:10:34 -0500 Subject: [PATCH 11/15] padColumns: add value `some` to options Now we have "on", "off", and "some". "some" will add a space at the beginning and end of each cell to balance between readability while still trying to minimize token count. --- cli/html2markdown/cmd/flags.go | 2 +- plugin/table/3_render.go | 4 ++-- plugin/table/table.go | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cli/html2markdown/cmd/flags.go b/cli/html2markdown/cmd/flags.go index 6605b1a..2faa38a 100644 --- a/cli/html2markdown/cmd/flags.go +++ b/cli/html2markdown/cmd/flags.go @@ -94,7 +94,7 @@ func (cli *CLI) initFlags(progname string) { cli.flags.StringVar(&cli.config.tableSpanCellBehavior, "opt-table-span-cell-behavior", "", `[for --plugin-table] how colspan/rowspan should be rendered: "empty" or "mirror"`) cli.flags.BoolVar(&cli.config.tablePresentationTables, "opt-table-presentation-tables", false, `[for --plugin-table] whether tables with role="presentation" should be converted`) cli.flags.StringVar(&cli.config.tableNewlineBehavior, "opt-table-newline-behavior", "", `[for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve"`) - cli.flags.StringVar(&cli.config.tablePadColumns, "opt-table-pad-columns", "", `[for --plugin-table] whether columns in the tables should include extra padding for visual continuity: "on" or "off"`) + cli.flags.StringVar(&cli.config.tablePadColumns, "opt-table-pad-columns", "", `[for --plugin-table] whether columns in the tables should include extra padding for visual continuity: "on", "some", or "off"`) } func (cli *CLI) parseFlags(args []string) error { diff --git a/plugin/table/3_render.go b/plugin/table/3_render.go index 9693198..7cc5bf7 100644 --- a/plugin/table/3_render.go +++ b/plugin/table/3_render.go @@ -98,7 +98,7 @@ func (s *tablePlugin) writeRow(w converter.Writer, counts []int, cells [][]byte) currentCount := utf8.RuneCount(cell) filler := counts[i] - currentCount - if s.padColumns == PadColumnsBehaviorOn { + if s.padColumns == PadColumnsBehaviorOn || s.padColumns == PadColumnsBehaviorSome { w.WriteString(" ") } @@ -108,7 +108,7 @@ func (s *tablePlugin) writeRow(w converter.Writer, counts []int, cells [][]byte) w.WriteString(strings.Repeat(" ", filler)) } - if s.padColumns == PadColumnsBehaviorOn { + if s.padColumns == PadColumnsBehaviorOn || s.padColumns == PadColumnsBehaviorSome { w.WriteString(" ") } diff --git a/plugin/table/table.go b/plugin/table/table.go index df22f4f..c744c69 100644 --- a/plugin/table/table.go +++ b/plugin/table/table.go @@ -76,13 +76,16 @@ type PadColumnsBehavior string const ( // PadColumnsBehaviorOn adds visual padding to cells to make each column equal width (default). PadColumnsBehaviorOn PadColumnsBehavior = "on" + // PadColumnsBehaviorSome keeps a very small amount of padding to balance table readability with reducing character count. + PadColumnsBehaviorSome PadColumnsBehavior = "some" // PadColumnsBehaviorOff refrains from adding the padding to the cells. PadColumnsBehaviorOff PadColumnsBehavior = "off" ) // WithPadColumns configures how to handle padding in table cells. -// When set to true (default), every column's text is padded to the width of the largest column in its row. -// When set to false, no extra padding is applied to columns. +// When set to "on" (default), every column's text is padded to the width of the largest column in its row. +// When set to "some", every column gets a space at the beginning and end of the column for some minimal padding. +// When set to "off", no extra padding is applied to columns. func WithPadColumns(behavior PadColumnsBehavior) option { return func(p *tablePlugin) error { switch behavior { @@ -91,7 +94,7 @@ func WithPadColumns(behavior PadColumnsBehavior) option { p.padColumns = PadColumnsBehavior(PadColumnsBehaviorOn) return nil - case PadColumnsBehaviorOn, PadColumnsBehaviorOff: + case PadColumnsBehaviorOn, PadColumnsBehaviorSome, PadColumnsBehaviorOff: p.padColumns = behavior return nil From fe23ef01fbac82a4e75e8c8aabd6f6d8b917647b Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Thu, 29 May 2025 17:17:13 -0500 Subject: [PATCH 12/15] table_test: add test for the new `some` option --- plugin/table/table_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugin/table/table_test.go b/plugin/table/table_test.go index 2c70e21..7ccc753 100644 --- a/plugin/table/table_test.go +++ b/plugin/table/table_test.go @@ -768,6 +768,30 @@ func TestOptionFunc_PadColumns(t *testing.T) { |---|---| |This line has some way longer text than the other line below it.|A2| |B1|This one has longer text than the line above.| +`, + }, + { + desc: "without padding behavior", + options: []option{ + WithPadColumns(PadColumnsBehaviorSome), + }, + input: ` + + + + + + + + + +
This line has some way longer text than the other line below it.A2
B1This one has longer text than the line above.
+ `, + expected: ` +| | | +|---|---| +| This line has some way longer text than the other line below it. | A2 | +| B1 | This one has longer text than the line above. | `, }, } From 9880166a3af7e1c8c95ed505af072fe3e93e5355 Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Tue, 3 Jun 2025 09:57:02 -0500 Subject: [PATCH 13/15] table plugin: adjust naming convention for table padding option https://github.com/JohannesKaufmann/html-to-markdown/pull/161#issuecomment-2932147969 Adjusted naming convention from the old "PadColumns" with options "on", "off", and "some" to the new "CellPadding" with options "aligned", "minimal", and "none". --- cli/html2markdown/cmd/cmd_convert.go | 2 +- cli/html2markdown/cmd/exec.go | 14 ++++++------ cli/html2markdown/cmd/flags.go | 6 +++--- plugin/table/3_render.go | 8 +++---- plugin/table/table.go | 32 ++++++++++++++-------------- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/cli/html2markdown/cmd/cmd_convert.go b/cli/html2markdown/cmd/cmd_convert.go index 8997c16..43bdacf 100644 --- a/cli/html2markdown/cmd/cmd_convert.go +++ b/cli/html2markdown/cmd/cmd_convert.go @@ -112,7 +112,7 @@ func (cli *CLI) convert(input []byte) ([]byte, error) { table.WithSpanCellBehavior(table.SpanCellBehavior(cli.config.tableSpanCellBehavior)), table.WithPresentationTables(cli.config.tablePresentationTables), table.WithNewlineBehavior(table.NewlineBehavior(cli.config.tableNewlineBehavior)), - table.WithPadColumns(table.PadColumnsBehavior(cli.config.tablePadColumns)), + table.WithCellPadding(table.CellPaddingBehavior(cli.config.tableCellPaddingBehavior)), ), ) } diff --git a/cli/html2markdown/cmd/exec.go b/cli/html2markdown/cmd/exec.go index a63249e..558eec2 100644 --- a/cli/html2markdown/cmd/exec.go +++ b/cli/html2markdown/cmd/exec.go @@ -40,13 +40,13 @@ type Config struct { // - - - - - Plugins - - - - - // enablePluginStrikethrough bool - enablePluginTable bool - tableSkipEmptyRows bool - tableHeaderPromotion bool - tableSpanCellBehavior string - tablePresentationTables bool - tableNewlineBehavior string - tablePadColumns string + enablePluginTable bool + tableSkipEmptyRows bool + tableHeaderPromotion bool + tableSpanCellBehavior string + tablePresentationTables bool + tableNewlineBehavior string + tableCellPaddingBehavior string } // Release holds the information (from the 3 ldflags) that goreleaser sets. diff --git a/cli/html2markdown/cmd/flags.go b/cli/html2markdown/cmd/flags.go index 2faa38a..f99b3a9 100644 --- a/cli/html2markdown/cmd/flags.go +++ b/cli/html2markdown/cmd/flags.go @@ -94,7 +94,7 @@ func (cli *CLI) initFlags(progname string) { cli.flags.StringVar(&cli.config.tableSpanCellBehavior, "opt-table-span-cell-behavior", "", `[for --plugin-table] how colspan/rowspan should be rendered: "empty" or "mirror"`) cli.flags.BoolVar(&cli.config.tablePresentationTables, "opt-table-presentation-tables", false, `[for --plugin-table] whether tables with role="presentation" should be converted`) cli.flags.StringVar(&cli.config.tableNewlineBehavior, "opt-table-newline-behavior", "", `[for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve"`) - cli.flags.StringVar(&cli.config.tablePadColumns, "opt-table-pad-columns", "", `[for --plugin-table] whether columns in the tables should include extra padding for visual continuity: "on", "some", or "off"`) + cli.flags.StringVar(&cli.config.tableCellPaddingBehavior, "opt-table-cell-padding", "", `[for --plugin-table] whether cells in the tables should include extra padding for visual continuity: "aligned", "minimal", or "none"`) } func (cli *CLI) parseFlags(args []string) error { @@ -121,8 +121,8 @@ func (cli *CLI) parseFlags(args []string) error { if cli.config.tableNewlineBehavior != "" && !cli.config.enablePluginTable { return fmt.Errorf("--opt-table-newline-behavior requires --plugin-table to be enabled") } - if cli.config.tablePadColumns != "" && !cli.config.enablePluginTable { - return fmt.Errorf("--opt-table-pad-columns requires --plugin-table to be enabled") + if cli.config.tableCellPaddingBehavior != "" && !cli.config.enablePluginTable { + return fmt.Errorf("--opt-table-cell-padding requires --plugin-table to be enabled") } // TODO: use constant for flag name & use formatFlag diff --git a/plugin/table/3_render.go b/plugin/table/3_render.go index 7cc5bf7..92d79ee 100644 --- a/plugin/table/3_render.go +++ b/plugin/table/3_render.go @@ -73,7 +73,7 @@ func (s *tablePlugin) writeHeaderUnderline(w converter.Writer, alignments []stri w.WriteString("-") } - if s.padColumns == PadColumnsBehaviorOn { + if s.cellPaddingBehavior == CellPaddingAligned { w.WriteString(strings.Repeat("-", maxLength)) } else { w.WriteString("-") @@ -98,17 +98,17 @@ func (s *tablePlugin) writeRow(w converter.Writer, counts []int, cells [][]byte) currentCount := utf8.RuneCount(cell) filler := counts[i] - currentCount - if s.padColumns == PadColumnsBehaviorOn || s.padColumns == PadColumnsBehaviorSome { + if s.cellPaddingBehavior == CellPaddingAligned || s.cellPaddingBehavior == CellPaddingMinimal { w.WriteString(" ") } w.Write(cell) - if s.padColumns == PadColumnsBehaviorOn && filler > 0 { + if s.cellPaddingBehavior == CellPaddingAligned && filler > 0 { w.WriteString(strings.Repeat(" ", filler)) } - if s.padColumns == PadColumnsBehaviorOn || s.padColumns == PadColumnsBehaviorSome { + if s.cellPaddingBehavior == CellPaddingAligned || s.cellPaddingBehavior == CellPaddingMinimal { w.WriteString(" ") } diff --git a/plugin/table/table.go b/plugin/table/table.go index c744c69..e5e3cdd 100644 --- a/plugin/table/table.go +++ b/plugin/table/table.go @@ -71,31 +71,31 @@ func WithNewlineBehavior(behavior NewlineBehavior) option { } } -type PadColumnsBehavior string +type CellPaddingBehavior string const ( - // PadColumnsBehaviorOn adds visual padding to cells to make each column equal width (default). - PadColumnsBehaviorOn PadColumnsBehavior = "on" - // PadColumnsBehaviorSome keeps a very small amount of padding to balance table readability with reducing character count. - PadColumnsBehaviorSome PadColumnsBehavior = "some" - // PadColumnsBehaviorOff refrains from adding the padding to the cells. - PadColumnsBehaviorOff PadColumnsBehavior = "off" + // CellPaddingAligned adds visual padding to cells to make each column equal width (default). + CellPaddingAligned CellPaddingBehavior = "aligned" + // CellPaddingMinimal keeps a very small amount of padding to balance table readability while also reducing character count. + CellPaddingMinimal CellPaddingBehavior = "minimal" + // CellPaddingNone refrains from adding the padding to the cells. + CellPaddingNone CellPaddingBehavior = "none" ) // WithPadColumns configures how to handle padding in table cells. -// When set to "on" (default), every column's text is padded to the width of the largest column in its row. -// When set to "some", every column gets a space at the beginning and end of the column for some minimal padding. -// When set to "off", no extra padding is applied to columns. -func WithPadColumns(behavior PadColumnsBehavior) option { +// When set to "aligned" (default), every cell's text is padded to the width of the largest cell in its column. +// When set to "minimal", every cell gets a space at the beginning and end of the cell for some minimal padding. +// When set to "none", no extra padding is applied to cells. +func WithCellPadding(behavior CellPaddingBehavior) option { return func(p *tablePlugin) error { switch behavior { case "": - // Allow empty string to default to "on" - p.padColumns = PadColumnsBehavior(PadColumnsBehaviorOn) + // Allow empty string to default to "aligned" + p.cellPaddingBehavior = CellPaddingBehavior(CellPaddingAligned) return nil - case PadColumnsBehaviorOn, PadColumnsBehaviorSome, PadColumnsBehaviorOff: - p.padColumns = behavior + case CellPaddingAligned, CellPaddingMinimal, CellPaddingNone: + p.cellPaddingBehavior = behavior return nil default: @@ -146,7 +146,7 @@ type tablePlugin struct { skipEmptyRows bool promoteFirstRowToHeader bool convertPresentationTables bool - padColumns PadColumnsBehavior + cellPaddingBehavior CellPaddingBehavior } func (p *tablePlugin) setError(err error) { From 2c7d79fde789c7460c23a79121c63bf4f917c58d Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Tue, 3 Jun 2025 09:59:16 -0500 Subject: [PATCH 14/15] testdata: update stdout golden files with new expected output --- .../testdata/TestExecute/[general]_help_pipe/stdout.golden | 6 +++--- .../TestExecute/[general]_help_terminal/stdout.golden | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden index 84202b7..8cbd8a5 100644 --- a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden +++ b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_pipe/stdout.golden @@ -72,15 +72,15 @@ Use a HTML sanitizer before displaying the HTML in the browser! Make bold text. Should be indicated by two asterisks or two underscores? "**" or "__" (default: "**") + --opt-table-cell-padding + [for --plugin-table] whether cells in the tables should include extra padding for visual continuity: "aligned", "minimal", or "none" + --opt-table-header-promotion [for --plugin-table] first row should be treated as a header --opt-table-newline-behavior [for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve" - --opt-table-pad-columns - [for --plugin-table] whether columns in the tables should include extra padding for visual continuity: "on" or "off" - --opt-table-presentation-tables [for --plugin-table] whether tables with role="presentation" should be converted diff --git a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden index 84202b7..8cbd8a5 100644 --- a/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden +++ b/cli/html2markdown/cmd/testdata/TestExecute/[general]_help_terminal/stdout.golden @@ -72,15 +72,15 @@ Use a HTML sanitizer before displaying the HTML in the browser! Make bold text. Should be indicated by two asterisks or two underscores? "**" or "__" (default: "**") + --opt-table-cell-padding + [for --plugin-table] whether cells in the tables should include extra padding for visual continuity: "aligned", "minimal", or "none" + --opt-table-header-promotion [for --plugin-table] first row should be treated as a header --opt-table-newline-behavior [for --plugin-table] how tables containing newlines should be handled: "skip" or "preserve" - --opt-table-pad-columns - [for --plugin-table] whether columns in the tables should include extra padding for visual continuity: "on" or "off" - --opt-table-presentation-tables [for --plugin-table] whether tables with role="presentation" should be converted From 0cfec2da93a9dc8999f10ab81477079d51b0234c Mon Sep 17 00:00:00 2001 From: datalogics-jacksonm Date: Tue, 3 Jun 2025 09:59:50 -0500 Subject: [PATCH 15/15] table_test: update table tests with new naming conventions --- plugin/table/table_test.go | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/plugin/table/table_test.go b/plugin/table/table_test.go index 7ccc753..81e1028 100644 --- a/plugin/table/table_test.go +++ b/plugin/table/table_test.go @@ -18,7 +18,7 @@ func TestGoldenFiles(t *testing.T) { base.NewBasePlugin(), commonmark.NewCommonmarkPlugin(), NewTablePlugin( - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), ), ), ) @@ -36,7 +36,7 @@ func TestOptionFunc_Validation(t *testing.T) { commonmark.NewCommonmarkPlugin(), NewTablePlugin( WithSpanCellBehavior("random"), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), ), ), ) @@ -66,7 +66,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "default", options: []option{ WithSpanCellBehavior(SpanBehaviorEmpty), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: ` @@ -88,7 +88,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "colspan=3", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -109,7 +109,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "rowspan=3", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -133,7 +133,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "cell with colspan and rowspan", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -156,7 +156,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "shifting content", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -184,7 +184,7 @@ func TestOptionFunc_ColRowSpan(t *testing.T) { desc: "rowspans overlap with colspans", options: []option{ WithSpanCellBehavior(SpanBehaviorMirror), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -247,7 +247,7 @@ func TestOptionFunc_EmptyRows(t *testing.T) { { desc: "by default keep empty rows", options: []option{ - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -277,7 +277,7 @@ func TestOptionFunc_EmptyRows(t *testing.T) { desc: "some rows are empty", options: []option{ WithSkipEmptyRows(true), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -310,7 +310,7 @@ func TestOptionFunc_EmptyRows(t *testing.T) { desc: "all rows are empty", options: []option{ WithSkipEmptyRows(true), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `

Before

@@ -345,7 +345,7 @@ After desc: "element that is not rendered", options: []option{ WithSkipEmptyRows(true), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `

Before

@@ -403,7 +403,7 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { { desc: "default", options: []option{ - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -428,7 +428,7 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { desc: "not needed", options: []option{ WithHeaderPromotion(true), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -458,7 +458,7 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { desc: "promote first row", options: []option{ WithHeaderPromotion(true), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -482,7 +482,7 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { desc: "promote first row (but it is empty)", options: []option{ WithHeaderPromotion(true), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -512,7 +512,7 @@ func TestOptionFunc_PromoteHeader(t *testing.T) { options: []option{ WithHeaderPromotion(true), WithSkipEmptyRows(true), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -572,7 +572,7 @@ func TestOptionFunc_PresentationTable(t *testing.T) { { desc: "default", options: []option{ - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -596,7 +596,7 @@ B1 B2 desc: "keep the presentation table", options: []option{ WithPresentationTables(true), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -654,7 +654,7 @@ func TestTableWithNewlines(t *testing.T) { desc: "with skip behavior (default)", options: []option{ WithNewlineBehavior(NewlineBehaviorSkip), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -672,7 +672,7 @@ A12 desc: "with preserve behavior", options: []option{ WithNewlineBehavior(NewlineBehaviorPreserve), - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -725,7 +725,7 @@ func TestOptionFunc_PadColumns(t *testing.T) { { desc: "with padding behavior (default)", options: []option{ - WithPadColumns(PadColumnsBehaviorOn), + WithCellPadding(CellPaddingAligned), }, input: `
@@ -749,7 +749,7 @@ func TestOptionFunc_PadColumns(t *testing.T) { { desc: "without padding behavior", options: []option{ - WithPadColumns(PadColumnsBehaviorOff), + WithCellPadding(CellPaddingNone), }, input: `
@@ -771,9 +771,9 @@ func TestOptionFunc_PadColumns(t *testing.T) { `, }, { - desc: "without padding behavior", + desc: "with minimal padding behavior", options: []option{ - WithPadColumns(PadColumnsBehaviorSome), + WithCellPadding(CellPaddingMinimal), }, input: `