Support colspans and rowspans in HTML tables#6644
Conversation
|
The current method to build a grid table is simple, hacky, and not very efficient. A better method would be to use a zipper, and building the grid diagonally from top left to bottom right. |
|
Can you explain the problem that is being solved with this GridTable module? Isn't the current pandoc-types representation of a Table pretty much isomorphic to HTML table syntax? Shouldn't it be trivial to render it to HTML by just walking the tree? I am obviously missing something! |
|
The issue is that we need a way to map cells to their column in order to
apply the proper text alignment. Unlike before, it's not enough to look
at each row individually, but we need to know the actual table layout.
Let's say we have a table
<table>
<tr>
<td rowspan=2>spanning</td>
<td>one</td>
</tr>
<tr>
<td>two</td>
</tr>
</table>
with
[(AlignLeft, ColWidthDefault), (AlignCenter, ColWidthDefault)] :: [ColSpec]
We won't know in which column the cell in row two should be placed, and
which alignment to apply to the cell, unless we look at all previous
rows. That's what I'm using GridTable for.
|
|
I see; I guess I was thinking, wrongly, that the alignments could be specified in the colgroup at the top. |
|
I thought the same and am still confused as to why the |
|
I suppose it might be nice to have the The issue there, I think, is that some of the writers (LaTeX in particular) might want to know if the cell's alignment is consistent with the column alignments so that they don't output unnecessary cell alignment overrides. So the |
|
Though |
I was hoping that as well.... so should we change the AST again, or...? |
|
Just as a general comment on the request, the A similar choice, but stylistically different, would be to stick a few helper functions somewhere that look something like renderTableHead
:: Monad m
=> ([Alignment] -> Cell -> m a) -- ^ render a cell given alignments of spanned columns
-> (Int -> Attr -> [a] -> m b) -- ^ render a row given the row number and rendered cells
-> (Attr -> [b] -> m c) -- ^ render the entire head
-> [ColSpec] -> TableHead -> m cthe idea being that the function also takes care of the table layout work like the construction of the All of this information can be recorded directly in the Otherwise, if you'd like, I can write a |
That'd be great! I've written a less naïve toGridTable function in the meantime, but I'd much prefer a central function build with your expertise. |
faf8d06 to
b6b7497
Compare
|
I wrote an alternate |
b6b7497 to
b814414
Compare
|
I rebased to the current master, but now the new "planets" test table is missing a column. I suspect that there be an issue with the table annotator. @despresc, can you help? |
|
Found the problem, misunderstanding on my part. |
b814414 to
f9ae5db
Compare
|
I think this is ready to be merged now. |
|
I assume there are still some new table features in #6312 that are not yet addressed by this PR? |
|
Still missing:
I'll add a note to the issue. |
Add support for cells spanning multiple columns or rows.
See: #6314