CALS Builder

This module can construct a CALS table from an instance of type Table.

Specifications and examples:

class benker.builders.cals.CalsBuilder(cals_ns=None, cals_prefix=None, width_unit='mm', table_in_tgroup=False, tgroup_sorting=None, **options)

Bases: benker.builders.base_builder.BaseBuilder

CALS table builder.

build_cell(row_elem, cell)

Build the CALS <entry> element.

CALS attributes:

  • @colsep is built from the “border-right” style. Default value is “1” (displayed), so, it is better to always define it. This value is only set if different from the table @colsep value.
  • @rowsep is built from the “border-bottom” style. Default value is “1” (displayed), so, it is better to always define it. This value is only set if different from the table @rowsep value.
  • @valign is built from the “vertical-align” style. Values can be “top”, “middle”, “bottom” (note: “baseline” is not supported). Default value is “bottom”.
  • @align is built from the “align” style. Values can be “left”, “center”, “right”, or “justify”. Default value is “left”. note: paragraphs alignment should be preferred to cells alignment.
  • @namest/@nameend are set when the cell is spanned horizontally.
  • @morerows is set when the cell is spanned vertically.
  • @bgcolor is built from the “background-color” style (HTML color).
Parameters:
  • row_elem (ElementType) – Parent element: <row>.
  • cell (benker.cell.Cell) – The cell.

Changed in version 0.5.0: Add support for bgcolor.

Changed in version 0.5.1: Preserve processing instruction in cell content.

build_colspec(group_elem, col)

Build the CALS <colspec> element.

CALS attributes:

  • @colnum is the column number.
  • @colname is the column name. Its format is “c{col_pos}”.
  • @colwidth width of the column (with its unit). The unit is defined by the width_unit options.
  • @align horizontal alignment of table entry content. Possible values are: “left”, “right”, “center”, “justify” (“char” is not supported).
  • @colsep column separators (vertical ruling). Possible values are “0” or “1”.
  • @colsep row separators (horizontal ruling). Possible values are “0” or “1”.
Parameters:

Changed in version 0.5.0: The @colnum and @align attributes are generated.

Changed in version 0.5.1: The @colsep and @rowsep attributes are generated.

build_row(tbody_elem, row)

Build the CALS <row> element.

CALS attributes:

  • @valign is built from the “vertical-align” style. Values can be “top”, “middle”, “bottom” (note: “baseline” is not supported). Default value is “bottom”.

Note

A row can be marked as inserted if “x-ins” is defined in the row styles. Revision marks are inserted before and after a <row> using a couple of processing-instructions. We use the <?change-start?> PI to mark the start of the inserted row, and the <?change-end?> PI to mark the end.

Parameters:
  • tbody_elem (ElementType) – Parent element: <tbody>, <thead>`, or <tfoot>`.
  • row (benker.table.RowView) – The row.

New in version 0.5.0: Add support for the @cals:rowstyle attribute (extension).

Changed in version 0.5.1: The @cals:valign attribute is built from the “vertical-align” style.

build_table(table)

Build the CALS <table> element.

CALS attributes:

  • @colsep is built from the “x-cell-border-right” style. Default value is “0” (not displayed).
  • @rowsep is built from the “x-cell-border-bottom” style. Default value is “0” (not displayed).
  • @tabstyle is built from the table nature.
  • @orient is built from the “x-sect-orient” style (orientation of the current section). Possible values are “port” (portrait, the default) or “land” (landscape).
  • @pgwide is built from the “x-sect-cols” style (column number of the current section). Default value is “0” (width of the current column).
  • @bgcolor is built from the “background-color” style (HTML color).
  • @width is built from the “width” style (percentage or width with unit). This attribute in an extension.

Note

@colsep, @rowsep and @tabstyle attributes are generated only if the table_in_tgroup options is False.

Attention

According to the CALS specification, the default value for @colsep and @rowsep should be “1”. But, having this value as a default is really problematic for conversions: most of nowadays formats, like Office Open XML and CSS, consider that the default value is “no border” (a.k.a: border: none). So, setting “0” as a default value is a better choice.

Parameters:table (benker.table.Table) – Table
Returns:The newly-created <table> element.

Changed in version 0.5.0: Add support for the bgcolor attribute (background color).

Changed in version 0.5.1: Add support for the @width attribute (table width).

build_tbody(group_elem, row_list, nature_tag)

Build the CALS <tbody>, <thead>`, or <tfoot>` element.

Parameters:
  • group_elem (ElementType) – Parent element: <tgroup>.
  • row_list – List of rows
  • nature_tag – name of the tag: ‘tbody’, ‘thead’ or ‘tfoot’.
build_tgroup(table_elem, table)

Build the CALS <tgroup> element.

CALS attributes:

  • @cols is the total number of columns.
  • @colsep is built from the “x-cell-border-right” style. Default value is “0” (not displayed).
  • @rowsep is built from the “x-cell-border-bottom” style. Default value is “0” (not displayed).
  • @tgroupstyle is built from the table nature.

Note

@colsep, @rowsep and @tgroupstyle attributes are generated only if the table_in_tgroup options is True.

Parameters:
  • table_elem (ElementType) – Parent element: <table>.
  • table (benker.table.Table) – Table
Returns:

The newly-created <tgroup> element.

generate_table_tree(table)

Build the XML table from the Table instance.

Parameters:table (benker.table.Table) – Table
Returns:Table tree
ns_map
setup_table(table)
benker.builders.cals.ElementType

alias of lxml.etree._Element

benker.builders.cals.get_colsep_attr(styles, style='x-cell-border-right')
benker.builders.cals.get_frame_attr(styles)
benker.builders.cals.get_rowsep_attr(styles, style='x-cell-border-bottom')
benker.builders.cals.revision_mark(name, attrs)