]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/todo/support_multi-row_table_headers.mdwn
07198fd5cb4d438076844e9bb88af60db8e206d1
[git.ikiwiki.info.git] / doc / todo / support_multi-row_table_headers.mdwn
1 [[!template id=gitbranch branch=jon/table_headerblock author="[[Jon]]"]]
2 It would be great if it were possible to support multi-row table headers in the [[plugins/table]] plugin, so you could do e.g.
4         \[[!table header="""
5         Name | Platform ||
6         | Windows | Mac | Linux
7         """ data="""
8         ikiwiki | ‧ | ✓ | ✓
9         """]]
11 -- [[Jon]]
13 [[!tag wishlist patch]]
15 > This seems like weird overloading of the header parameter - it's
16 > table data, except when it isn't.
18 > > My first cut (now rebased out of existence I think) introduced a
19 > > new "headerblock" parameter, but trying to clearly document the
20 > > interaction of data/headerblock/header parameters was too awkward. -- [[Jon]]
22 > Perhaps
23 > something like this would be easier to use in practice?
24 > (and also more featureful :-) )
25 >
26 >     \[[!table header="2 rows 1 column" data="""
27 >     Name | Platform ||
28 >     | Windows | Mac | Linux
29 >     ikiwiki | no | yes | yes
30 >     Starcraft | yes | yes | via Wine
31 >     """]]
33 > > Thanks for your prompt feedback!
34 > > 
35 > > This would probably be good, yes, and having mixed row/column headers is
36 > > definitely a nice-to-have. I don't relish the prospect of writing the parser
37 > > but I see you've made a stab already...
38 > > 
39 > > One thing you'd lose, but it's debatable whether this is valuable, would be
40 > > to have the header defined in the directive, and the remaining table data
41 > > declared in an external CSV. -- [[Jon]]
43 > intended to be rendered like
44 >
45 > <table>
46 > <tr><th>Name</th><th colspan=2>Platform</th>
47 > <tr><th></th><th>Windows</th><th>Mac</th><th>Linux</th></tr>
48 > <tr><th>ikiwiki</th><td>no</td><td>yes</td><td>yes</td></tr>
49 > <tr><th>Starcraft</th><td>yes</td><td>yes</td><td>via Wine</td></tr>
50 > </table>
51 >
52 > (Deliberately switching to plain-text to make it more obvious
53 > what's a `<th>` and what's `<td>`.)
54 >
55 > Vague pseudocode for parsing `headers`
56 > (possibly even valid Perl, I'm not sure):
57 >
58 >     my ($header_rows, $header_cols);
59 >     while ($header =~ s/(\d*)\W*(\w+)//) {
60 >         my $n = ($1 or 0);
61 >         my $what = $2;
62 >         if ($what =~ m/rows?/) {
63 >             $header_rows = $n;
64 >         }
65 >         elif ($what =~ m/col(?:umn)?s?/) {
66 >             $header_cols = $n;
67 >         }
68 >     }
69 >
70 > and it would even be fairly easy to extend to support
71 > `(first|last|)\W*(\d*)\W*(\w+)` later, e.g.
72 > `header="1 row, first 2 cols, last column"`.
73 >
74 > --[[smcv]]
76 > > To be clear I think your suggestion is a good one, but my hack has
77 > > addressed my immediate need so it's the one I'm deploying at $ork for the
78 > > time being. I'm unlikely to have time to implement this solution in the
79 > > near future. -- [[Jon]]
81 ----
83 I'd quite like to revisit this if that's ok. I'm still carrying a fork of
84 table.pm locally to add this feature as I find it so useful. The main objection
85 you made back in 2014 seems to be overloading the header= parameter, and I agree
86 that this is not ideal. So I'm happy to resubmit this with an alternative parameter
87 name for the new purpose. But I balked at the idea of implementing something like 
88 an NLP processor to define the header range. And I must stress how useful it is in
89 practise to separate out the header definition from the data: quite often I don't
90 want headers in my CSV files at all, for example, so I can perform rudimentary analysis
91 on them with command line tools without having to factor in a header line (how many
92 records?  = `wc -l`; sorting on fields simply with `sort -k` etc.). Having them
93 separate means I can have machine-generated or manipulated CSV files of data and then
94 use ikiwiki to mark them up for human reading, but change or regenerate the data quickly
95 and easily underneath.
97 I'd appreciate your take on the above suggestions [[smcv]] before I roll my sleeves up.
98 Thanks! — [[Jon]] (2018-09-24)
100 > I continue to think that the `header` parameter shouldn't be sometimes a
101 > description of which parts of the table are header, and sometimes the header
102 > data itself; so if you want an inline header, it should indeed have a
103 > distinct name.
105 > If you can think of a good name for the new parameter, and can document it
106 > reasonably clearly, then I would be OK with having a separate parameter that
107 > is the externally-provided header. I don't know what the right name for that
108 > parameter would be: `headercontent` or `headerblock` is unwieldy but I can't
109 > think of anything better.
111 > It would maybe simplify things to make it mutually exclusive with `header`,
112 > but then you wouldn't be able to express things like "the first column of my
113 > CSV is a header, the first row is just an ordinary row, and please add
114 > this literal header row to the top".
116 > It might help to write the documentation and/or tests first, and then
117 > implement it afterwards, when you have an "API" you're happy with.
119 > Corner cases:
121 > How would it work if you want to add a literal header column on the left
122 > rather than adding a literal header row on the top? If you add both, what
123 > happens at the top left corner?
125 > Is it necessary to be able to add header columns on the right (for RTL
126 > languages?), or header rows (footer rows, I suppose) on the bottom?
128 > --[[smcv]]