"""Table-only options shared by the style editor, CSS and Word exporter.""" TABLE_OPTIONS = { 'table_border_mode': '--mdhelper-table-borders', 'table_banded_rows': '--mdhelper-table-banded-rows', 'table_stripe_color': '--mdhelper-table-stripe-color', 'table_repeat_header': '--mdhelper-table-repeat-header', 'table_allow_row_split': '--mdhelper-table-allow-row-split', } TABLE_BOOL_FIELDS = ('table_banded_rows', 'table_repeat_header', 'table_allow_row_split') TABLE_ONLY_FIELDS = {'border_color', 'border_width', 'border_style', 'cell_padding', *TABLE_OPTIONS} HEADER_COLOR = '#f1f5f9' STRIPE_COLOR = '#f8fafc' BORDER_COLOR = '#d5dbe5' VERTICAL_BORDER_COLOR = '#e8ecf2' def table_helper_css(rule): """Companion rules for options that affect descendants of the table.""" parts = [] selector = '.reader table[data-mdh-table]' mode = rule.get('table_border_mode') if mode in ('horizontal', 'none'): declarations = 'border-style: none;' if mode == 'none' else 'border-left-style: none; border-right-style: none;' parts.append(f'{selector}, {selector} th, {selector} td {{ {declarations} }}') if rule.get('table_banded_rows'): color = rule.get('table_stripe_color', 'var(--reader-table-stripe, #f8fafc)') # Low specificity lets explicit cell backgrounds remain authoritative. parts.append(f':where(.reader table) tbody tr:where(:nth-child(even)) td {{ background-color: {color}; }}') if 'table_repeat_header' in rule: display = 'table-header-group' if rule['table_repeat_header'] else 'table-row-group' parts.append(f'{selector} thead {{ display: {display}; }}') if 'table_allow_row_split' in rule: value = 'auto' if rule['table_allow_row_split'] else 'avoid' parts.append(f'{selector} tr {{ break-inside: {value}; }}') return '\n'.join(parts)