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

.printhtml() method doesnt insert table headers (titles) correctly #159

Open
belakm opened this issue Nov 9, 2023 · 2 comments
Open

.printhtml() method doesnt insert table headers (titles) correctly #159

belakm opened this issue Nov 9, 2023 · 2 comments

Comments

@belakm
Copy link

belakm commented Nov 9, 2023

Description

When using .printhtml() method on a table, it doesnt work correctly for titles.
It inserts <td> elements into <th> elements, treating <th> as <tr> and <td> as <th>.

Current solution around this is to treat table headers as just a row as those seem to get printed just fine.

Example snippet:

let mut out = File::create("table.html").unwrap();
let mut table = table!(["Value 1", "Value 2"], ["Value three", "Value four"]);
table.set_titles(row!["Title 1", "Title 2"]);
table.print_html(&mut out);

it renders the below table as such in HTML:

<table>
  <th>
    <td style="text-align: left;">Title 1</td>
    <td style="text-align: left;">Title 2</td>
  </th>
  <!-- ... data rows -->
</table>

The correct way for table headers would be:

<table>
  <tr>
    <th style="text-align: left;">Title 1</th>
    <th style="text-align: left;">Title 2</th>
  </tr>
  <tr>
  <!-- ... data rows -->
</table>

Chrome based browsers try their best to render this and they somehow get it, but it is skewed because of the empty <th> element:

image

@michaelsippel
Copy link

Hi there,
thanks for this nice and simple crate!

Since I ran into the exact same issue as described by @belakm and this thread remained unanswered, I decided to quickly put together a fix. PR #161

@pinkforest
Copy link
Collaborator

Hey thanks for the fix and very nicely detailed issue - I left a comment in your PR just honing the API a bit :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants