Documentation
¶
Overview ¶
Command tablecsv extracts every table in a document as CSV, expanding colspan and rowspan so every row has the same number of fields.
A table is the hardest structure in HTML to read from a stream, for three reasons that have nothing to do with CSV.
Cells and rows are usually written without end tags. <tr><td>a<td>b is two cells, and the second start tag is what ends the first - so a cell's content ends at a token the cell's own end-tag handler will not see. The program keeps the stack of open elements and applies the implied end tags, the same way examples/gip/markdown does.
A table can contain things that are not in it. A parser moves content that cannot be inside a table to just before the table; there is no tree here, so that content is reported inside. Text between <table> and the first <tr> is the common case, and a program that collected "the table's text" would collect it. This one takes cell content from cells, which is the shape that avoids the question.
And a grid is not a list of rows. colspan and rowspan mean a row's cells do not line up with its columns, and a rowspan from an earlier row occupies a column in this one without any cell being written for it. So the program fills a grid rather than appending fields, and carries the outstanding row spans forward.