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(width_unit='mm', table_in_tgroup=False, **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 “valign” 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.
- Parameters
row_elem (etree._Element) – Parent element:
<row>
.cell (benker.cell.Cell) – The cell.
- build_colspec(group_elem, col)¶
Build the CALS
<colspec>
element.CALS attributes:
@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.
Note
The
@colnum
attribute (number of column) is not generated because this value is usually implied, and can be deduce from the@colname
attribute.- Parameters
group_elem (etree._Element) – Parent element:
<tgroup>
.col (benker.table.ColView) – Columns
- build_row(tbody_elem, row)¶
Build the CALS
<row>
element.CALS attributes:
@valign
is built from the “valign” 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 (etree._Element) – Parent element:
<tbody>
, <thead>`, or <tfoot>`.row (benker.table.RowView) – The row.
- 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).
Note
@colsep
,@rowsep
and@tabstyle
attributes are generated only if the table_in_tgroup options isFalse
.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.
- build_tbody(group_elem, row_list, nature_tag)¶
Build the CALS
<tbody>
, <thead>`, or <tfoot>` element.- Parameters
group_elem (etree._Element) – 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 isTrue
.- Parameters
table_elem (etree._Element) – 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
- benker.builders.cals.revision_mark(name, attrs)¶