CALS Builder¶
This module can construct a CALS table from
an instance of type Table.
Specifications and examples:
- The CALS DTD is available online in the OASIS web site: CALS Table Model Document Type Definition.
- An example of CALS table is available in Wikipedia: CALS Table Model
-
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.BaseBuilderCALS table builder.
-
build_cell(row_elem, cell)¶ Build the CALS
<entry>element.CALS attributes:
@colsepis 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@colsepvalue.@rowsepis 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@rowsepvalue.@valignis built from the “vertical-align” style. Values can be “top”, “middle”, “bottom” (note: “baseline” is not supported). Default value is “bottom”.@alignis 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/@nameendare set when the cell is spanned horizontally.@morerowsis set when the cell is spanned vertically.@bgcoloris 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:
@colnumis the column number.@colnameis the column name. Its format is “c{col_pos}”.@colwidthwidth of the column (with its unit). The unit is defined by the width_unit options.@alignhorizontal alignment of table entry content. Possible values are: “left”, “right”, “center”, “justify” (“char” is not supported).@colsepcolumn separators (vertical ruling). Possible values are “0” or “1”.@colseprow separators (horizontal ruling). Possible values are “0” or “1”.
Parameters: - group_elem (ElementType) – Parent element:
<tgroup>. - col (benker.table.ColView) – Columns
Changed in version 0.5.0: The
@colnumand@alignattributes are generated.Changed in version 0.5.1: The
@colsepand@rowsepattributes are generated.
-
build_row(tbody_elem, row)¶ Build the CALS
<row>element.CALS attributes:
@valignis 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:rowstyleattribute (extension).Changed in version 0.5.1: The
@cals:valignattribute is built from the “vertical-align” style.
-
build_table(table)¶ Build the CALS
<table>element.CALS attributes:
@colsepis built from the “x-cell-border-right” style. Default value is “0” (not displayed).@rowsepis built from the “x-cell-border-bottom” style. Default value is “0” (not displayed).@tabstyleis built from the table nature.@orientis built from the “x-sect-orient” style (orientation of the current section). Possible values are “port” (portrait, the default) or “land” (landscape).@pgwideis built from the “x-sect-cols” style (column number of the current section). Default value is “0” (width of the current column).@bgcoloris built from the “background-color” style (HTML color).@widthis built from the “width” style (percentage or width with unit). This attribute in an extension.
Note
@colsep,@rowsepand@tabstyleattributes are generated only if the table_in_tgroup options isFalse.Attention
According to the CALS specification, the default value for
@colsepand@rowsepshould 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
bgcolorattribute (background color).Changed in version 0.5.1: Add support for the
@widthattribute (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’.
- group_elem (ElementType) – Parent element:
-
build_tgroup(table_elem, table)¶ Build the CALS
<tgroup>element.CALS attributes:
@colsis the total number of columns.@colsepis built from the “x-cell-border-right” style. Default value is “0” (not displayed).@rowsepis built from the “x-cell-border-bottom” style. Default value is “0” (not displayed).@tgroupstyleis built from the table nature.
Note
@colsep,@rowsepand@tgroupstyleattributes are generated only if the table_in_tgroup options isTrue.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)¶