From fbdee3abe781161f0421022fef6b1ff4bcbb9b97 Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Thu, 5 Mar 2026 16:41:35 +0900 Subject: [PATCH 1/2] go fix: header_styles.go markdown.go --- header_styles.go | 4 ++-- markdown.go | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/header_styles.go b/header_styles.go index 5a0a850..ff3324a 100644 --- a/header_styles.go +++ b/header_styles.go @@ -115,7 +115,7 @@ func (hs HeaderStyle) ApplyStyle(text string) string { } var prefix string - var suffix = AnsiReset + suffix := AnsiReset // Add custom prefix if specified if hs.CustomPrefix != "" { @@ -218,7 +218,7 @@ func (hs HeaderStyle) getSuffix() string { return "" } - var suffix = AnsiReset + suffix := AnsiReset // Add custom suffix if specified if hs.CustomSuffix != "" { diff --git a/markdown.go b/markdown.go index 3e940e9..b79a0a8 100644 --- a/markdown.go +++ b/markdown.go @@ -106,7 +106,8 @@ func (r *MarkdownRenderer) renderMarkdownHeader(table *Table) error { // renderMarkdownSeparator renders the separator row with alignment indicators. func (r *MarkdownRenderer) renderMarkdownSeparator(table *Table) error { - line := "|" + var line strings.Builder + line.WriteString("|") for _, col := range table.columns { separatorWidth := max(col.Width, 1) @@ -114,17 +115,18 @@ func (r *MarkdownRenderer) renderMarkdownSeparator(table *Table) error { separatorWidth += (table.padding * 2) } separator := r.getAlignmentSeparator(col.Align, separatorWidth) - line += separator + "|" + line.WriteString(separator + "|") } - line += "\n" - _, err := table.writer.Write([]byte(line)) + line.WriteString("\n") + _, err := table.writer.Write([]byte(line.String())) return err } // renderMarkdownRow renders a data row in Markdown format. func (r *MarkdownRenderer) renderMarkdownRow(table *Table, row Row) error { - line := "|" + var line strings.Builder + line.WriteString("|") // Ensure row.Cells has at least as many elements as table.columns cells := row.Cells @@ -137,7 +139,7 @@ func (r *MarkdownRenderer) renderMarkdownRow(table *Table, row Row) error { for i, col := range table.columns { if !table.autoAlign { - line += cells[i].Content + "|" + line.WriteString(cells[i].Content + "|") continue // Skip alignment if noAlign is set } @@ -149,11 +151,11 @@ func (r *MarkdownRenderer) renderMarkdownRow(table *Table, row Row) error { } // Format cell content with alignment content = table.formatCell(cells[i].Content, col.Width, cellAlign) - line += content + "|" + line.WriteString(content + "|") } - line += "\n" - _, err := table.writer.Write([]byte(line)) + line.WriteString("\n") + _, err := table.writer.Write([]byte(line.String())) return err } From eee2630a695a9f784018393ace1449ce308b1d8b Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Thu, 5 Mar 2026 16:51:04 +0900 Subject: [PATCH 2/2] Use strings.Builder for efficient string concatenation --- markdown.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/markdown.go b/markdown.go index b79a0a8..ab1803d 100644 --- a/markdown.go +++ b/markdown.go @@ -77,7 +77,7 @@ func (r *MarkdownRenderer) IsRendered() bool { // renderMarkdownHeader renders the header row in Markdown format. func (r *MarkdownRenderer) renderMarkdownHeader(table *Table) error { - var line string + var line strings.Builder var stylePrefix, styleSuffix string // Apply header style to the entire line if configured @@ -87,7 +87,8 @@ func (r *MarkdownRenderer) renderMarkdownHeader(table *Table) error { } // Start the line with style prefix - line = stylePrefix + "|" + line.WriteString(stylePrefix) + line.WriteString("|") for _, col := range table.columns { // Apply alignment to header content (headers are typically centered) @@ -95,12 +96,14 @@ func (r *MarkdownRenderer) renderMarkdownHeader(table *Table) error { if table.autoAlign { content = table.formatCell(col.Title, col.Width, Center) } - line += content + "|" + line.WriteString(content) + line.WriteString("|") } // End the line with style suffix - line += styleSuffix + "\n" - _, err := table.writer.Write([]byte(line)) + line.WriteString(styleSuffix) + line.WriteString("\n") + _, err := table.writer.Write([]byte(line.String())) return err } @@ -115,7 +118,8 @@ func (r *MarkdownRenderer) renderMarkdownSeparator(table *Table) error { separatorWidth += (table.padding * 2) } separator := r.getAlignmentSeparator(col.Align, separatorWidth) - line.WriteString(separator + "|") + line.WriteString(separator) + line.WriteString("|") } line.WriteString("\n") @@ -139,7 +143,8 @@ func (r *MarkdownRenderer) renderMarkdownRow(table *Table, row Row) error { for i, col := range table.columns { if !table.autoAlign { - line.WriteString(cells[i].Content + "|") + line.WriteString(cells[i].Content) + line.WriteString("|") continue // Skip alignment if noAlign is set } @@ -151,7 +156,8 @@ func (r *MarkdownRenderer) renderMarkdownRow(table *Table, row Row) error { } // Format cell content with alignment content = table.formatCell(cells[i].Content, col.Width, cellAlign) - line.WriteString(content + "|") + line.WriteString(content) + line.WriteString("|") } line.WriteString("\n")