diff options
author | Jonas Bushart <jonas@bushart.org> | 2019-01-20 18:07:20 +0100 |
---|---|---|
committer | Jonas Bushart <jonas@bushart.org> | 2019-08-26 00:36:03 +0200 |
commit | 917e480a673d1ab03218702d0e9e726131e48799 (patch) | |
tree | 560f4308b71c7addc3bdbc85c024482df2d638e2 /src/row.rs | |
parent | 1e06ea72ccf03cd2129d104360e1e07679190a07 (diff) |
Implement HTML output for Table and TableSlice
* Add a HTML escaper to the utils class.
* Expand TableSlice, Row, and Cell with HTML printing functions.
These are implemented from scratch as they share almost nothing with
the line based printing used for text, as HTML directly supports
multiline cells.
* Add tests to Cell and Table which test the new functionality.
Diffstat (limited to 'src/row.rs')
-rw-r--r-- | src/row.rs | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -205,6 +205,21 @@ impl Row { -> Result<usize, Error> { self.__print(out, format, col_width, Cell::print_term) } + + /// Print the row in HTML format to `out`. + /// + /// If the row is has fewer columns than `col_num`, the row is padded with empty cells. + pub fn print_html<T: Write + ?Sized>(&self, out: &mut T, col_num: usize) -> Result<(), Error> { + let mut printed_columns = 0; + for cell in self.iter() { + printed_columns += cell.print_html(out)?; + } + // Pad with empty cells, if target width is not reached + for _ in 0..col_num - printed_columns { + Cell::default().print_html(out)?; + } + Ok(()) + } } impl Default for Row { |