pub struct Table {
pub columns: Vec<TableColumn>,
pub header_rows: u32,
pub rows: Vec<Vec<TableCell>>,
pub caption: Option<Vec<Inline>>,
pub extra: Extra,
}Expand description
A table: { "type": "table", "columns": …, "rows": … } in book.json
(the block’s JSON is flat; Block::Table(Table)).
Fields§
§columns: Vec<TableColumn>One entry per column: how its text is aligned. Its length is the table’s width.
header_rows: u32The first header_rows rows are headers (0: none). They repeat on
every page in print and are <thead> in the EPUB.
rows: Vec<Vec<TableCell>>Row by row, only the cells that START in the row: a cell that a rowspan above covers is not listed again.
caption: Option<Vec<Inline>>Shown above the table.
extra: ExtraFields written by newer builds, kept on round-trip.
Implementations§
Source§impl Table
impl Table
Sourcepub fn new(
columns: Vec<TableColumn>,
header_rows: u32,
rows: Vec<Vec<TableCell>>,
) -> Self
pub fn new( columns: Vec<TableColumn>, header_rows: u32, rows: Vec<Vec<TableCell>>, ) -> Self
A table, normalized (see Table::normalized): what the importers
build. columns may be empty, then the width is the widest row’s.
Sourcepub fn with_caption(self, caption: Vec<Inline>) -> Self
pub fn with_caption(self, caption: Vec<Inline>) -> Self
The same table with a caption shown above it.
Sourcepub fn layout(&self) -> TableLayout<'_>
pub fn layout(&self) -> TableLayout<'_>
The grid this table means, by the seven rules below. Total: no stored table panics or loses a cell’s text.
- The width is
columns.len()(or the widest row, seeSelf::width). - A span of 0 is 1; a
colspanis cut at the width and at a position a rowspan above covers. - Cells are placed row by row, each at the first position at or after the end of the previous one that no rowspan above covers. A cell that does not fit has its text appended, after a line break, to the last cell placed in its row.
- A
rowspanis cut at the last row and at the header boundary (a cell that starts in a header row covers header rows only). A rectangle cannot meet a position already taken: placement goes row by row, so positions below a cell are free until a later row takes them, and that row avoids the covered ones. - A position nothing covers and no cell was placed on becomes an empty cell.
- A row whose every position is covered by rowspans from above cuts those spans to end above it, and is then placed like any row (its listed cells take the freed positions, the rest become empty). The ADR drops the text of such a row’s listed cells; this keeps it, since the rule only exists so that no row is without a cell.
header_rowsis cut to the number of rows.
Sourcepub fn normalized(&self) -> Table
pub fn normalized(&self) -> Table
The layout written back as a stored table, in the form importers and
Table::new make: one column entry per position, only the cells that
start in each row, spans cut, gaps filled with empty cells,
header_rows cut. Its layout is this table’s, cell for cell (the
source of a cell made up now points at its stored place).