charmbracelet / glamour

Stylesheet-based markdown rendering for your CLI apps 💇🏻‍♀️
MIT License
2.43k stars 179 forks source link

Question: are code blocks in a table supposed to be supported? #109

Open AndrewSav opened 3 years ago

AndrewSav commented 3 years ago

It does not look to me like code blocks are rendered as code blocks where they are inside a table? Is this intentional?

ChristianChiarulli commented 3 years ago

Inline seems to work: image

Blocks are formatted but not in there own highlighted code block: image

AndrewSav commented 3 years ago

Just to re-iterate / clarify this issue is about rendering code blocks inside a table:

Header 1 Header 2
This is code: hello This is not code
er4hn commented 2 years ago

+1 to this, it would be very useful to have this.

michaeltlombardi commented 2 years ago

More broadly, it looks like no spans within a table are picking up their format, e.g:

in := `
| First | Second | Third  |
| ----- | -------| ------ |
| **A** | _B_    | **_C_**|

- [ ] **strong**
- [ ] _emphasized_
- [ ] **_strongly emphasized_**
`

out, err := glamour.Render(in, "dracula")
if err != nil {
    panic(err)
}

fmt.Print(out)

Results in:

image

michaeltlombardi commented 2 years ago

This comment elucidates why this might not be working, I think:

The spurious output is fixed by 5a1a0f6.

To render AST children (like links) within table cells we still need to change the table renderer a bit. This is sadly not as trivial or straight-forward as I'd like, because the table rendering (by tablewriter) doesn't properly handle ANSI escape sequences. I'll probably move that to a separate ticket.

Poking around in tablewriter, it seems like support for in-cell styling might be out of scope for what the maintainers want, though there is a possible workaround.

Further research indicates that go-pretty/table might be a functional replacement which would enable this functionality, but that would both require a spike to confirm and be a reimplementation of the existing table implementation in glamour. It does seem like go-pretty is more actively maintained and released fwiw.

Time/availability depending, I might give this a shot. As an aside, I think this might also help resolve #117, #87, #83, #65, and #60 (or, at least, reimplementation might be a useful time to address those issues).