jedib0t / go-pretty

Table-writer and more in golang!
MIT License
2.82k stars 113 forks source link

Automerge does not work in HTML rendered by table #298

Closed naveenbharadwaj-nc closed 6 months ago

naveenbharadwaj-nc commented 6 months ago

Describe the bug The automerge used on certain columns of a table is not applied on HTML rendering.

To Reproduce Create table and apply automerge to some column. Render HTML for it.

Expected behavior Automerge should be applied in HTML view also.

Screenshots image Above is the table rendered on console. As you can see, the first column is auto-merged. And below is the HTML code generated.

<tr>
    <td align="right">21</td>
    <td class="fg-green">CustomResources TestSuite</td>
    <td class="fg-green">Check Service Monitors</td>
    <td class="fg-green">Pass</td>
  </tr>
  <tr>
    <td align="right">22</td>
    <td class="fg-green">CustomResources TestSuite</td>
    <td class="fg-green">Check Pod Monitors</td>
    <td class="fg-green">Pass</td>
  </tr>
  <tr>
    <td align="right">23</td>
    <td class="fg-green">CustomResources TestSuite</td>
    <td class="fg-green">Check Probes</td>
    <td class="fg-green">Pass</td>
  </tr>
  <tr>
    <td align="right">24</td>
    <td class="fg-green">CustomResources TestSuite</td>
    <td class="fg-green">Check Service Monitors</td>
    <td class="fg-green">Pass</td>

Software (please complete the following information):

Additional context image I want to use table.RenderHTML() to write the content to a HTML file. When I render this file in browser, no styles are applied (see above screenshot). Obviously its because CSS classes such as fg-green, fg-red etc are not available. Can you please provide a correct example how to get this working correctly?

jedib0t commented 6 months ago

Hello @naveenbharadwaj-nc --- as noted in comments @ https://github.com/jedib0t/go-pretty/blob/main/table/config.go#L25-L34 ... auto-merge is not supported in CSV/HTML/MarkDown modes. I may implement this as a functionality that works in any mode in the future, but for now it is not. Sorry!

naveenbharadwaj-nc commented 6 months ago

I think it should be added in documentation rather than being as a comment in code. Could you please help with another question about CSS?

jedib0t commented 6 months ago

You should be attaching a style sheet to your HTML on how you'd want the browser to render those classes.

For example:

.fg-green {
    color: Chartreuse;
}
.fg-red {
    color: DarkRed;
}
.fg-blue {
    color: #0000cc;
}

You'd want to nest it under a selector or another class to make sure this is not globally applied - if that is a constraint.

naveenbharadwaj-nc commented 6 months ago

Thank you.