All files / roosterjs-content-model-dom/lib/formatHandlers/segment underlineFormatHandler.ts

92.86% Statements 13/14
94.44% Branches 17/18
100% Functions 2/2
92.86% Lines 13/14

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 341x             1x   2896x   2896x 35x 2861x         2027x 1970x     57x   57x 17x 16x   1x          
import { wrapAllChildNodes } from '../../domUtils/moveChildNodes';
import type { FormatHandler } from '../FormatHandler';
import type { UnderlineFormat } from 'roosterjs-content-model-types';
 
/**
 * @internal
 */
export const underlineFormatHandler: FormatHandler<UnderlineFormat> = {
    parse: (format, element, context, defaultStyle) => {
        const textDecoration = element.style.textDecoration || defaultStyle.textDecoration;
 
        if (textDecoration?.indexOf('underline')! >= 0) {
            format.underline = true;
        } else Iif (element.tagName == 'A' && textDecoration == 'none') {
            format.underline = false;
        }
    },
    apply: (format, element, context) => {
        if (typeof format.underline === 'undefined') {
            return;
        }
 
        const blockUnderline = context.implicitFormat.underline;
 
        if (!!blockUnderline != !!format.underline) {
            if (format.underline) {
                wrapAllChildNodes(element, 'u');
            } else {
                element.style.textDecoration = 'none';
            }
        }
    },
};