Skip to content

Rendering a markdown table #424

Closed
@mfridman

Description

@mfridman

Is your feature request related to a problem? Please describe.

I have a CLI that supports 3 table formats: plain (HiddenBorder), basic (RoundedBorder), and markdown (??). I used lipgloss/table to build a table and would like to output it in all those formats.

Output examples

Plain

  Status   Elapsed                     Package                    Cover   Pass   Fail   Skip  
                                                                                              
   PASS    (cached)   github.com/mfridman/tparse/internal/utils    --      12     0      0    
   PASS    (cached)   github.com/mfridman/tparse/parse             --      43     0      0    
   PASS    (cached)   github.com/mfridman/tparse/tests             --     137     0      0 

Basic (poorly named, "with border")

╭────────┬──────────┬───────────────────────────────────────────┬───────┬──────┬──────┬──────╮
│ Status │ Elapsed  │                  Package                  │ Cover │ Pass │ Fail │ Skip │
├────────┼──────────┼───────────────────────────────────────────┼───────┼──────┼──────┼──────┤
│  PASS  │ (cached) │ github.com/mfridman/tparse/internal/utils │  --   │  12  │  0   │  0   │
│  PASS  │ (cached) │ github.com/mfridman/tparse/parse          │  --   │  43  │  0   │  0   │
│  PASS  │ (cached) │ github.com/mfridman/tparse/tests          │  --   │ 137  │  0   │  0   │
╰────────┴──────────┴───────────────────────────────────────────┴───────┴──────┴──────┴──────╯

Markdown

| Status  | Elapsed  |                  Package                  | Cover | Pass | Fail | Skip |
|---------|----------|-------------------------------------------|-------|------|------|------|
| 🟢 PASS | (cached) | github.com/mfridman/tparse/internal/utils |  --   |  12  |  0   |  0   |
| 🟢 PASS | (cached) | github.com/mfridman/tparse/parse          |  --   |  43  |  0   |  0   |
| 🟢 PASS | (cached) | github.com/mfridman/tparse/tests          |  --   | 137  |  0   |  0   |

Describe the solution you'd like

I'd be nice if there was a lipglosss.MarkdownBorder(), which would allow converting a lipgloss table into a renderable markdown table.

Describe alternatives you've considered

This did the trick for me:

border := lipgloss.Border{
	Top:          "-",
	Bottom:       "-",
	Left:         "|",
	Right:        "|",
	TopLeft:      "", // empty for markdown
	TopRight:     "", // empty for markdown
	BottomLeft:   "", // empty for markdown
	BottomRight:  "", // empty for markdown
	MiddleLeft:   "|",
	MiddleRight:  "|",
	Middle:       "|",
	MiddleTop:    "|",
	MiddleBottom: "|",
}
t = t.Border(border).BorderBottom(false).BorderTop(false)

Additional context

This might be overly specific, but opening this up for discussion and/or if someone else finds this useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions