All files / roosterjs-content-model-dom/lib/formatHandlers/table legacyTableBorderFormatHandler.ts

100% Statements 16/16
100% Branches 12/12
100% Functions 2/2
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40            1x   359x 359x 359x   359x 4x     359x 4x     359x 4x         105x 3x     105x 3x     105x 3x        
import type { FormatHandler } from '../FormatHandler';
import type { LegacyTableBorderFormat } from 'roosterjs-content-model-types';
 
/**
 * @internal
 */
export const legacyTableBorderFormatHandler: FormatHandler<LegacyTableBorderFormat> = {
    parse: (format, element) => {
        const border = element.getAttribute('border');
        const cellSpacing = element.getAttribute('cellspacing');
        const cellpadding = element.getAttribute('cellpadding');
 
        if (border) {
            format.legacyTableBorder = border;
        }
 
        if (cellSpacing) {
            format.cellSpacing = cellSpacing;
        }
 
        if (cellpadding) {
            format.cellPadding = cellpadding;
        }
    },
 
    apply: (format, element) => {
        if (format.legacyTableBorder) {
            element.setAttribute('border', format.legacyTableBorder);
        }
 
        if (format.cellSpacing) {
            element.setAttribute('cellspacing', format.cellSpacing);
        }
 
        if (format.cellPadding) {
            element.setAttribute('cellpadding', format.cellPadding);
        }
    },
};