Opened 18 years ago
Closed 14 years ago
#3347 closed enhancement (fixed)
Generate <th> for table header
Reported by: | Owned by: | Christian Boos | |
---|---|---|---|
Priority: | normal | Milestone: | 0.12 |
Component: | wiki system | Version: | |
Severity: | minor | Keywords: | table header text-align |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
The first row of a table created with WikiFormatting should be a <th>
element instead of a <tr>
Attachments (4)
Change History (27)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
I agree that table headers should be a separate syntax rather than automatic for the first row. However, maybe we should just encourage the use of reStructuredText for more powerful table layouts like this example.
comment:3 by , 18 years ago
Keywords: | table added |
---|---|
Milestone: | → 1.0 |
Severity: | normal → minor |
Simple tables could eventually support a simple way to specify to use of a <th> instead of a <td>. This could be something like, with the = ... =
reminiscent of the heading syntax.
||= column title =||= column title =|| ||= row title =|| data ||
More complex tables would anyway be supported by #1424.
comment:4 by , 17 years ago
Version: | devel |
---|
Restructured text is nice, but I think its table syntax sucks. The biggest problem is that when you are updating a table and one of the cells in a row becomes wider than the others you now have to go through the rest of the table and add more —- characters to make all of the cells be equal width. This is not too bad for small tables, but if you have large tables, something like 50 rows, it becomes very tedious.
th tag support would be great. Currently in my organization people typically use bold text in headers, but it would be nice to be able to color the background a different color with CSS. I like the syntax proposed by cboos.
by , 16 years ago
Attachment: | 3347_TableHeaders.diff added |
---|
Diff file for table headers against 0.11.1
comment:5 by , 16 years ago
I'm attaching a patch that will generate <th> and </th> tags for headers. The syntax is to use triple pipes for headers, i.e.
||| ||| 1 ||| 2 ||| 3 || ||| A || X || || X || ||| B || || X || || ||| C || X || X || ||
will render as the second table
Changes:
- Added the <table_header> token in parser.py for
|||
- Updated formatter.py to translate <table_header>s to HTML
- Added these methods
- _table_header_formatter
- open_table_cell_or_header
- _table_header_formatter and _table_cell_formatter are much simpler using this helper
- close_table_cell_or_header
- open_table_cell_or_header starts by calling this before opening anything new
- was able to simplify close_table_row by using it
- Initializing in_table_header in the reset method
- Added these methods
- Added CSS for th tags
- Applying td's borders and padding to ths
- Inverting body colours on ths
Manual Testing:
- Ran tracd, added the following wiki
Headers on top ||| Trac ||| Headers || || Trac || Rocks! || Headers on top and side ||| ||| 1 ||| 2 ||| 3 || ||| A || X || || X || ||| B || || X || || ||| C || X || X || ||
- Inspected generated HTML
Headers on top </p> <blockquote> <table class="wiki"> <tr></th><th> Trac <th> Headers </th></tr><tr></td><td> Trac <td> Rocks! </td></tr></table> </blockquote> <p> Headers on top and side </p> <blockquote> <table class="wiki"> <tr></th></th></th><th> <th> 1 <th> 2 <th> 3 </th></tr><tr></th></td></td><th> A <td> X <td> <td> X </td></tr><tr></th></td></td><th> B <td> <td> X <td> </td></tr><tr></th></td></td><th> C <td> X <td> X <td> </td></tr></table>
by , 16 years ago
Attachment: | 3347_TableHeaders_NicerFormat.diff added |
---|
Patch for Trac ticket #3347 using cboos' suggested syntax
comment:6 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I'm attaching 3347_TableHeaders_NicerFormat.diff against 0.11.1 that will generate <th> and </th> tags for headers, using the syntax suggested by cboos. The previous patch was functional, but cboos' syntax is nicer than triple pipes.
Changes:
- Added the <table_header> token in parser.py
- Updated <table_cell> token to still open and close plain cells
- Updated formatter.py to translate <table_header>s to HTML
- Added these methods
- _table_header_formatter
- open_table_cell_or_header
- _table_header_formatter and _table_cell_formatter are much simpler using this helper
- close_table_cell_or_header
- open_table_cell_or_header starts by calling this before opening anything new
- was able to simplify close_table_row by using it
- Initializing in_table_header in the reset method
- Added these methods
- Added CSS for <th/> tags
- Applying <td/> borders and padding to <th/>s
- Inverting body colours on <th/>s
Manual Testing:
- Ran tracd, added the following wiki (cboos' example)
cboos' example ||= column title =||= column title =|| ||= row title =|| data ||
- Inspected generated HTML
cboos' example </p> <blockquote> <table class="wiki"> <tr><th> column title </th><th> column title </th></tr><tr><th> row title </th><td> data </td></tr></table>
comment:7 by , 16 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Thanks for the patch, I'll put it on my todo list. However, please do not close tickets before they are applied in SVN.
comment:8 by , 16 years ago
Milestone: | 1.0 → 0.12 |
---|---|
Owner: | changed from | to
Status: | reopened → new |
Tentatively rescheduling for 0.12, as the changes are local to the wiki engine and should not disturb other 0.12 features.
follow-ups: 10 11 comment:9 by , 16 years ago
I have reworked the patch a bit, and made it play well with the colspan patch.
comment:10 by , 16 years ago
Owner: | changed from | to
---|
Replying to cboos:
I have reworked the patch a bit, and made it play well with the colspan patch.
I'll leave this ticket to you, then.
comment:11 by , 15 years ago
Replying to cboos:
I have reworked the patch a bit, and made it play well with the colspan patch.
I would have some time this week to integrate this. Do you want to post your patches (this one and the colspan one) and I take care of applying and testing?
comment:12 by , 15 years ago
As those patches sit at the bottom of my "TracWikiPlus" patch queue, I think it's simpler if I just commit those changes. I just finished to refresh them. You can then tell me if you think something needs to be reworked.
comment:13 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:14 by , 15 years ago
comment:15 by , 15 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Is it intentional that the text in <th>
cells is centered? While it looks good for header rows, it doesn't look as good on header columns:
First column | Second column | |
---|---|---|
A row | Some text in the table | Some more text in the table |
A very long row | More text | Less text |
Another row | Blah | More |
Do you mind if I set text-align: left
on <th>
? For comparison, we also left-align header rows in the custom query tables.
follow-up: 18 comment:16 by , 15 years ago
I have an upcoming patch for specifying cell alignment. The idea is to have something like:
||left aligned || || right aligned|| || default || || default || (i.e. either left aligned for <td>, centered for <th>) || default || ||justified text||
Same rules for the ||= ... =||
cells. Would that work for you?
Or do we need smarter defaults, left aligned th for the first column, centered for the others? Always defaulting to left aligned for <th> wouldn't be that nice.
follow-up: 19 comment:18 by , 15 years ago
Replying to cboos:
I have an upcoming patch for specifying cell alignment.
Sounds good! What happens if I don't leave any space on the left and the right? Default alignment?
||no space||
Would that work for you?
Sure, it's much better than what I asked for.
Or do we need smarter defaults, left aligned th for the first column, centered for the others?
No, that makes the rules too complicated, and the code probably as well. If I can choose the alignment myself, I don't need too smart defaults.
by , 15 years ago
Attachment: | align-in-cells-r9004.patch added |
---|
WikiFormatting: align content in cells according to which border the content sticks to.
follow-up: 20 comment:19 by , 15 years ago
Replying to rblank:
Sounds good! What happens if I don't leave any space on the left and the right? Default alignment?
I made that "justify".
follow-up: 21 comment:20 by , 15 years ago
Replying to cboos:
I made that "justify".
Sounds logical. This will probably cause a few surprises for people who currently pack their tables (I do). Is "justified" text in a table really useful?
comment:21 by , 15 years ago
Keywords: | header text-align added |
---|---|
Resolution: | → fixed |
Status: | reopened → closed |
Replying to rblank:
Replying to cboos:
I made that "justify".
Is "justified" text in a table really useful?
Not really and it makes the generated HTML "heavier" for no real benefit. That was a "ballon d'essai" as I wasn't fully convinced myself ;-)
Also, we don't have a way to force center align in non-header cells, so in case center align is really wanted, the only way is to use a header cell.
Simplified patch committed as r9005.
The quirk of using a not 100% robust lookahead mechanism for getting the next ||
separator will go away as soon as we have the WikiDOM (#4431).
follow-up: 23 comment:22 by , 14 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Actually it's generating <th> but inside <tbody><tr>. Should be inside <thead><tr> I think. That could help for example to use jquery plugins like tablesorter.
comment:23 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Replying to Nacho Larrateguy:
Actually it's generating <th> but inside <tbody><tr>. Should be inside <thead><tr> I think.
No, you can have at most one <thead>
per <table>
, but several <tbody>
.
-1: there is no reason for forcing the first row (or the first column) to be a table header. Such a configuration is probably the most common case, but it is not a universal case.
Support for tables is poor, IMHO <th> should only be used when a special tag is inserted in the wiki syntax.