[Haskell-cafe] Is Text.XHtml.Table usable?
Anton van Straaten
anton at appsolutions.com
Sun Mar 29 21:03:23 EDT 2009
Thomas Hartman wrote:
> I was playing with Text.XHtml.Table but couldn't use it to output tables.
> ( cell . toHtml $ " a " ) `beside` (cell . toHtml $ " b " )
>> a b </tr
> already seems wrong -- should be two cells, right? And the result
> doesn't get embedded in a table tag?
'cell' is not a TD element, it's an abstraction used to manage cells and
deal with arbitrary numbers of rows and columns. You won't normally use
'cell' directly, but it gets used when laying out a table.
Here's a simple two-cell table:
table << (td << " a ") `beside` (td << " b ")
Note that 'beside' has an infix version, <->. 'above' also has an infix
version, </>. So here's a 2x2 table:
table << (td << "a" <-> td << "b"
</> td << "c" <-> td << "d")
(I haven't included the HTML output, but it works.)
To see what 'cell' does, we can create a table with cell widths and
heights other than 1. In GHCi:
let twoDown = (td << "a" </> td << "b")
let threeAcross = (td << "d" <-> td << "e" <-> td << "f")
let threeDown = (td << "g" </> td << "h" </> td << "i")
let oneTopTwoBottom = (td << "j" </> td << "k" <-> td << "l")
table << (twoDown <-> threeAcross <-> threeDown <-> oneTopTwoBottom)
The 'cell' function doesn't get called explicitly above, but it gets
used internally. Try it, the results are fairly self-explanatory.
More information about the Haskell-Cafe