Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme files are always rendered in Markdown format #463

Closed
LindsayZhou opened this issue Jan 19, 2024 · 0 comments · Fixed by #467
Closed

Readme files are always rendered in Markdown format #463

LindsayZhou opened this issue Jan 19, 2024 · 0 comments · Fixed by #467
Labels
bug Something isn't working

Comments

@LindsayZhou
Copy link

Describe the bug
Regardless the actual format, readme files are always rendered in Markdown format.
Included in the service's About tab and the repository's readme page

To Reproduce
Create a repository and commit a readme file.

Expected behavior
For non-Markdown readme files, represent them as normal files.

I personally like to use orgmode files as readme files.
If the service cannot parse the orgmode file, then I export it as a plain text file (emacs built-in feature).

Screenshots
Current:
2024-01-19_16:21:15
What I want:
2024-01-19_16:23:04

Environment (please complete the following information):

  • OS: Alpine Linux 3.19.0
  • Terminal: foot
  • Version: 0.7.4

Additional context
Here is my rough patch:

diff --git a/pkg/ui/pages/repo/readme.go b/pkg/ui/pages/repo/readme.go
index e977bb9..1b12560 100644
--- a/pkg/ui/pages/repo/readme.go
+++ b/pkg/ui/pages/repo/readme.go
@@ -3,6 +3,7 @@ package repo
 import (
 	"fmt"
 	"path/filepath"
+	"strings"
 
 	"github.com/charmbracelet/bubbles/key"
 	"github.com/charmbracelet/bubbles/spinner"
@@ -34,7 +35,6 @@ type Readme struct {
 func NewReadme(common common.Common) *Readme {
 	readme := code.New(common, "", "")
 	readme.NoContentStyle = readme.NoContentStyle.Copy().SetString("No readme found.")
-	readme.UseGlamour = true
 	s := spinner.New(spinner.WithSpinner(spinner.Dot),
 		spinner.WithStyle(common.Styles.Spinner))
 	return &Readme{
@@ -114,6 +114,13 @@ func (r *Readme) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	case ReadmeMsg:
 		r.isLoading = false
 		r.readmePath = msg.Path
+		readmeExt := strings.ToLower(filepath.Ext(msg.Path))
+		r.code.UseGlamour = (readmeExt == ".md" ||
+			readmeExt == ".markdown" ||
+			readmeExt == ".mdown" ||
+			readmeExt == "mkdn" ||
+			readmeExt == "mdwn" ||
+			readmeExt == "mkd")
 		r.code.GotoTop()
 		cmds = append(cmds, r.code.SetContent(msg.Content, msg.Path))
 	case spinner.TickMsg:
diff --git a/pkg/ui/pages/selection/selection.go b/pkg/ui/pages/selection/selection.go
index 4b9b72a..9f0d884 100644
--- a/pkg/ui/pages/selection/selection.go
+++ b/pkg/ui/pages/selection/selection.go
@@ -2,7 +2,9 @@ package selection
 
 import (
 	"fmt"
+	"path/filepath"
 	"sort"
+	"strings"
 
 	"github.com/charmbracelet/bubbles/key"
 	"github.com/charmbracelet/bubbles/list"
@@ -62,7 +64,6 @@ func New(c common.Common) *Selection {
 		tabs:       t,
 	}
 	readme := code.New(c, "", "")
-	readme.UseGlamour = true
 	readme.NoContentStyle = c.Styles.NoContent.Copy().
 		SetString(defaultNoContent)
 	selector := selector.New(c,
@@ -206,6 +207,13 @@ func (s *Selection) Init() tea.Cmd {
 			if err != nil {
 				continue
 			}
+			readmeExt := strings.ToLower(filepath.Ext(path))
+			s.readme.UseGlamour = (readmeExt == ".md" ||
+				readmeExt == ".markdown" ||
+				readmeExt == ".mdown" ||
+				readmeExt == "mkdn" ||
+				readmeExt == "mdwn" ||
+				readmeExt == "mkd")
 
 			readmeCmd = s.readme.SetContent(readme, path)
 		}
@aymanbagabas aymanbagabas added the bug Something isn't working label Jan 29, 2024
aymanbagabas added a commit that referenced this issue Jan 29, 2024
Use Glamour to render readmes when file is markdown formatted

Fixes: #463
aymanbagabas added a commit that referenced this issue Jan 30, 2024
Use Glamour to render readmes when file is markdown formatted

Fixes: #463
aymanbagabas added a commit that referenced this issue Feb 5, 2024
Use Glamour to render readmes when file is markdown formatted

Fixes: #463
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants