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:
parent
65b45adbd8
commit
c0a2648436
1 changed files with 3 additions and 3 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue