Edgewall Software
Modify

Opened 18 years ago

Closed 13 years ago

#3347 closed enhancement (fixed)

Generate <th> for table header

Reported by: dserodio@… 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)

3347_TableHeaders.diff (2.7 KB ) - added by nado18@… 16 years ago.
Diff file for table headers against 0.11.1
3347_TableHeaders.gif (8.5 KB ) - added by nado18@… 16 years ago.
Screenshot of table headers
3347_TableHeaders_NicerFormat.diff (3.8 KB ) - added by nado18@… 16 years ago.
Patch for Trac ticket #3347 using cboos' suggested syntax
align-in-cells-r9004.patch (4.1 KB ) - added by Christian Boos 14 years ago.
WikiFormatting: align content in cells according to which border the content sticks to.

Download all attachments as: .zip

Change History (27)

comment:1 by Emmanuel Blot, 18 years ago

-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.

comment:2 by Matthew Good, 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 Christian Boos, 17 years ago

Keywords: table added
Milestone: 1.0
Severity: normalminor

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 kamil@…, 16 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 nado18@…, 16 years ago

Attachment: 3347_TableHeaders.diff added

Diff file for table headers against 0.11.1

by nado18@…, 16 years ago

Attachment: 3347_TableHeaders.gif added

Screenshot of table headers

comment:5 by nado18@…, 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

Screenshot of table headers

Changes:

  1. Added the <table_header> token in parser.py for |||
  2. Updated formatter.py to translate <table_header>s to HTML
    1. 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
    2. Initializing in_table_header in the reset method
  3. Added CSS for th tags
    1. Applying td's borders and padding to ths
    2. Inverting body colours on ths

Manual Testing:

  1. 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 ||    ||
    
  2. 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 nado18@…, 16 years ago

Patch for Trac ticket #3347 using cboos' suggested syntax

comment:6 by nado18@…, 16 years ago

Resolution: fixed
Status: newclosed

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:

  1. Added the <table_header> token in parser.py
    1. Updated <table_cell> token to still open and close plain cells
  2. Updated formatter.py to translate <table_header>s to HTML
    1. 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
    2. Initializing in_table_header in the reset method
  3. Added CSS for <th/> tags
    1. Applying <td/> borders and padding to <th/>s
    2. Inverting body colours on <th/>s

Manual Testing:

  1. Ran tracd, added the following wiki (cboos' example)
    cboos' example
      ||= column title =||= column title =||
      ||= row title    =|| data           ||
    
  2. 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 Remy Blank, 16 years ago

Resolution: fixed
Status: closedreopened

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 Remy Blank, 16 years ago

Milestone: 1.00.12
Owner: changed from Jonas Borgström to Remy Blank
Status: reopenednew

Tentatively rescheduling for 0.12, as the changes are local to the wiki engine and should not disturb other 0.12 features.

comment:9 by Christian Boos, 15 years ago

I have reworked the patch a bit, and made it play well with the colspan patch.

in reply to:  9 comment:10 by Remy Blank, 15 years ago

Owner: changed from Remy Blank to Christian Boos

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.

in reply to:  9 comment:11 by Remy Blank, 14 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 Christian Boos, 14 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 Christian Boos, 14 years ago

Resolution: fixed
Status: newclosed

Support for <th> as described in comment:3 implemented in r8699.

Feedback welcomed on this and previous changesets.

comment:14 by Christian Boos, 14 years ago

[8750] added some additional highlight to header cells, not as flashy as in comment:5, though ;-)

comment:15 by Remy Blank, 14 years ago

Resolution: fixed
Status: closedreopened

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.

comment:16 by Christian Boos, 14 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.

comment:17 by Daniel Serodio <dserodio@…>, 14 years ago

Yeah, I think center-aligned works better for column headers

in reply to:  16 ; comment:18 by Remy Blank, 14 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 Christian Boos, 14 years ago

Attachment: align-in-cells-r9004.patch added

WikiFormatting: align content in cells according to which border the content sticks to.

in reply to:  18 ; comment:19 by Christian Boos, 14 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".

in reply to:  19 ; comment:20 by Remy Blank, 14 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?

in reply to:  20 comment:21 by Christian Boos, 14 years ago

Keywords: header text-align added
Resolution: fixed
Status: reopenedclosed

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).

comment:22 by Nacho Larrateguy, 13 years ago

Resolution: fixed
Status: closedreopened

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.

in reply to:  22 comment:23 by Remy Blank, 13 years ago

Resolution: fixed
Status: reopenedclosed

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>.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.