Edgewall Software

Ticket #3347 (new enhancement)

Opened 2 years ago

Last modified 9 days ago

Generate <th> for table header

Reported by: dserodio@… Owned by: cboos
Priority: normal Milestone: 0.12
Component: wiki system Version:
Severity: minor Keywords: table
Cc:

Description

The first row of a table created with WikiFormatting should be a <th> element instead of a <tr>

Attachments

3347_TableHeaders.diff (2.7 KB) - added by nado18@… 3 months ago.
Diff file for table headers against 0.11.1
3347_TableHeaders.gif (8.5 KB) - added by nado18@… 3 months ago.
Screenshot of table headers
3347_TableHeaders_NicerFormat.diff (3.8 KB) - added by nado18@… 2 months ago.
Patch for Trac ticket #3347 using cboos' suggested syntax

Change History

  Changed 2 years ago by eblot

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

  Changed 2 years ago by mgood

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.

  Changed 22 months ago by cboos

  • keywords table added
  • severity changed from normal to minor
  • milestone set to 1.0

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.

  Changed 8 months ago by kamil@…

  • version devel deleted

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.

Changed 3 months ago by nado18@…

Diff file for table headers against 0.11.1

Changed 3 months ago by nado18@…

Screenshot of table headers

  Changed 3 months ago by nado18@…

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>
    

Changed 2 months ago by nado18@…

Patch for Trac ticket #3347 using cboos' suggested syntax

  Changed 2 months ago by nado18@…

  • status changed from new to closed
  • resolution set to fixed

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>
    

  Changed 2 months ago by rblank

  • status changed from closed to reopened
  • resolution fixed deleted

Thanks for the patch, I'll put it on my todo list. However, please do not close tickets before they are applied in SVN.

  Changed 2 months ago by rblank

  • owner changed from jonas to rblank
  • status changed from reopened to new
  • milestone changed from 1.0 to 0.12

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

follow-up: ↓ 10   Changed 4 weeks ago by cboos

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

in reply to: ↑ 9   Changed 9 days ago by rblank

  • owner changed from rblank to cboos

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.

Add/Change #3347 (Generate <th> for table header)

Author



Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change from cboos. Next status will be 'new'
The owner will change from cboos to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.