Skip to main content

TableBlock

Struct TableBlock 

Source
pub struct TableBlock<'src> { /* private fields */ }
Expand description

A table is a delimited block that arranges content into a grid of rows and columns.

A table is introduced by a table delimiter (|===, or !=== for a nested table) and closed by a matching delimiter. By default cells are separated using prefix-separated value (PSV) syntax: the table’s cell separator — a vertical bar (|) by default — at the start of a line or preceded by whitespace begins a new cell. Cells flow, in document order, into rows whose length is fixed by the number of columns. (The separator defaults to ! inside a nested table and can be overridden with the separator attribute; see below.)

The number of columns is determined either by the cols attribute or, implicitly, by the number of cells found in the first non-empty line after the opening delimiter.

§Data formats

In addition to the default PSV format, a table can be populated from delimiter-separated data with the format attribute: csv (comma-separated values), tsv (tab-separated values), or dsv (delimited values, colon-separated by default). The ,=== and :=== shorthand delimiters select the CSV and DSV formats respectively without an explicit format attribute. In a data format the separator is placed between values (not in front of each cell) and a cell carries no formatting spec; cell formatting is instead applied per column with the cols attribute. See DataFormat for the parsing rules.

Column specifier style operators (the a, d, e, h, l, m, and s operators) are supported, along with proportional width and the horizontal and vertical alignment operators. Per-cell horizontal and vertical alignment operators are supported and override the column’s alignment, and a per-cell style operator (in the last position of the cell specifier) is supported and overrides the column’s style. The per-cell span (+) operator is supported: a cell can span multiple columns (<n>+), multiple rows (.<n>+), or a block of both (<n>.<n>+). The per-cell duplication (*) operator is supported: a cell with a duplication factor (<n>*) clones its content and properties into <n> consecutive cells.

Table sizing is supported: the width attribute sets a fixed table width, the autowidth option (is_autowidth) sizes the table and its columns to their content, and an individual column can be made autowidth with the ~ width value.

Table borders are supported: the frame attribute controls the border around the table and the grid attribute controls the borders between cells. Each falls back to a document-level default (table-frame / table-grid) and then to all.

Zebra striping is supported via the stripes attribute, which falls back to the table-stripes document attribute and then to none.

Nested tables are supported: an AsciiDoc cell may contain its own table. The cell separator defaults to the vertical bar (|) but switches to the exclamation mark (!) inside an AsciiDoc cell, so a nested table is opened with !=== and separates its cells with !. The separator attribute overrides the default separator with an explicit character at any level.

Implementations§

Source§

impl<'src> TableBlock<'src>

Source

pub fn caption(&self) -> Option<&str>

Returns the caption assigned to this table, if any.

A titled table is captioned with a label that a processor prepends to the title. By default the label combines the table-caption attribute and an automatically incremented number (e.g. "Table 1. "). An explicit caption attribute on the table overrides this with a verbatim label and no number; an explicitly empty caption (e.g. [caption=]) removes the label entirely. The caption is absent when the table has no title, when table-caption has been unset and no explicit caption is given, or when an empty caption was supplied.

Source

pub fn number(&self) -> Option<usize>

Returns the number assigned to this table, if any.

A titled table for which the table-caption attribute is set is numbered with an automatically incremented, document-wide table counter (the same number that appears in its caption, e.g. the 1 in "Table 1. "). The number is absent when the table is not captioned, or when its caption comes from an explicit (unnumbered) caption attribute.

Source

pub fn columns(&self) -> &[TableColumn]

Returns the columns of this table.

Source

pub fn data_format(&self) -> DataFormat

Returns the DataFormat used to populate this table.

The format comes from the format attribute on the table (psv, csv, tsv, or dsv) or from a shorthand delimiter (,=== selects CSV, :=== selects DSV). When neither is present the format defaults to DataFormat::Psv.

Source

pub fn width(&self) -> Option<usize>

Returns the fixed width of this table, as a percentage of the content area, when the width attribute is set.

The width attribute is an integer percentage from 1 to 100; the trailing % sign is optional ([width=75%] and [width=75] are equivalent). A value outside that range, or one that is not an integer, is ignored and reported as None. When the attribute is absent the table spans the width of the content area and this returns None.

Source

pub fn is_autowidth(&self) -> bool

Returns true if this table carries the autowidth option.

An autowidth table is sized to fit its content rather than spanning the width of the content area, and each of its columns is likewise autowidth.

Source

pub fn frame(&self) -> Frame

Returns the Frame that controls the border drawn around this table.

The frame comes from the frame attribute on the table, which accepts all, ends, sides, or none. When the attribute is absent the value is taken from the table-frame document attribute, and when that too is absent it defaults to Frame::All.

Source

pub fn grid(&self) -> Grid

Returns the Grid that controls the borders drawn between this table’s cells.

The grid comes from the grid attribute on the table, which accepts all, rows, cols, or none. When the attribute is absent the value is taken from the table-grid document attribute, and when that too is absent it defaults to Grid::All.

Source

pub fn stripes(&self) -> Stripes

Returns the Stripes that control which rows of this table are shaded to create a zebra-striping effect.

The stripes come from the stripes attribute on the table, which accepts none, even, odd, all, or hover. When the attribute is absent the value is taken from the table-stripes document attribute, and when that too is absent it defaults to Stripes::None.

As a shorthand, a stripes-<value> role on the table (e.g. [.stripes-even]) applies the same CSS class directly without setting the stripes attribute. That shorthand does not affect this value (which remains Stripes::None); the role is instead reported among the table’s roles.

Source

pub fn header_row(&self) -> Option<&TableRow<'src>>

Returns the header row of this table, if one was declared.

Source

pub fn body_rows(&self) -> &[TableRow<'src>]

Returns the body rows of this table.

Source

pub fn footer_row(&self) -> Option<&TableRow<'src>>

Returns the footer row of this table, if one was declared.

Trait Implementations§

Source§

impl<'src> Clone for TableBlock<'src>

Source§

fn clone(&self) -> TableBlock<'src>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'src> Debug for TableBlock<'src>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'src> Eq for TableBlock<'src>

Source§

impl<'src> HasSpan<'src> for TableBlock<'src>

Source§

fn span(&self) -> Span<'src>

Return a Span describing the syntactic element’s location within the source string/file.
Source§

impl<'src> IsBlock<'src> for TableBlock<'src>

Source§

fn content_model(&self) -> ContentModel

Returns the ContentModel for this block.
Source§

fn raw_context(&self) -> CowStr<'src>

Returns the raw (uninterpreted) context for this block. Read more
Source§

fn title_source(&'src self) -> Option<Span<'src>>

Returns the source text for the title for this block, if present.
Source§

fn title(&self) -> Option<&str>

Returns the rendered title for this block, if present.
Source§

fn caption(&self) -> Option<&str>

Returns the caption prefix for this block, if it has one. Read more
Source§

fn number(&self) -> Option<usize>

Returns the automatically assigned number for this block, if it has one. Read more
Source§

fn anchor(&'src self) -> Option<Span<'src>>

Returns the anchor for this block, if present.
Source§

fn anchor_reftext(&'src self) -> Option<Span<'src>>

Returns the reference text for this block’s anchor, if present.
Source§

fn attrlist(&'src self) -> Option<&'src Attrlist<'src>>

Returns the attribute list for this block, if present.
Source§

fn rendered_content(&'src self) -> Option<&'src str>

Returns the rendered content for this block, if any. Read more
Source§

fn resolved_context(&'src self) -> CowStr<'src>

Returns the resolved context for this block. Read more
Source§

fn declared_style(&'src self) -> Option<&'src str>

Returns the declared (uninterpreted) style for this block. Read more
Source§

fn nested_blocks(&'src self) -> Iter<'src, Block<'src>>

Returns an iterator over the nested blocks contained within this block. Read more
Source§

fn nested_blocks_mut(&mut self) -> &mut [Block<'src>]

Returns a mutable slice of the nested blocks contained within this block. Read more
Source§

fn content_mut(&mut self) -> Option<&mut Content<'src>>

Returns a mutable reference to this block’s own resolvable content — its body, section title, or description-list term — if any. Read more
Source§

fn id(&'src self) -> Option<&'src str>

Returns the ID for this block, if present. Read more
Source§

fn roles(&'src self) -> Vec<&'src str>

Returns any role attributes that were found. Read more
Source§

fn options(&'src self) -> Vec<&'src str>

Returns any option attributes that were found. Read more
Source§

fn has_option<N: AsRef<str>>(&'src self, name: N) -> bool

Returns true if this block has the named option. Read more
Source§

fn substitution_group(&'src self) -> SubstitutionGroup

Returns the default substitution group that is applied unless you customize the substitutions for a particular element.
Source§

impl<'src> PartialEq for TableBlock<'src>

Source§

fn eq(&self, other: &TableBlock<'src>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'src> StructuralPartialEq for TableBlock<'src>

Auto Trait Implementations§

§

impl<'src> Freeze for TableBlock<'src>

§

impl<'src> RefUnwindSafe for TableBlock<'src>

§

impl<'src> Send for TableBlock<'src>

§

impl<'src> Sync for TableBlock<'src>

§

impl<'src> Unpin for TableBlock<'src>

§

impl<'src> UnsafeUnpin for TableBlock<'src>

§

impl<'src> UnwindSafe for TableBlock<'src>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.