Use filepath.Ext to detect file extension in markdown renderer

Replaces manual string splitting with filepath.Ext for determining the file extension in renderFileContentAsMarkdown. This improves accuracy, especially for files with multiple dots in their names.
This commit is contained in:
Kynan Ware 2025-09-16 17:34:57 -06:00
parent 65b45adbd8
commit c0a2648436

View file

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"path/filepath"
"slices"
"strings"
@ -366,10 +367,9 @@ func stripDiffFormat(diff string) string {
// renderFileContentAsMarkdown renders the given content as markdown
// based on the file extension of the path.
func renderFileContentAsMarkdown(path, content string, w io.Writer, io *iostreams.IOStreams) error {
parts := strings.Split(path, ".")
lang := parts[len(parts)-1]
lang := filepath.Ext(filepath.ToSlash(path))
if lang == "md" {
if lang == ".md" {
return renderRawMarkdown(content, w, io)
}