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 41 42 | 1x 1x 1x 1x 206x 19x 19x 187x 187x 187x 250x 250x 186x 186x 186x 2x 248x 206x | import { adjustHeading } from '../utils/adjustHeading';
import { createBr } from 'roosterjs-content-model-dom';
import { parseInlineSegments } from '../utils/parseInlineSegments';
import type {
ContentModelParagraph,
ContentModelParagraphDecorator,
ContentModelSegment,
} from 'roosterjs-content-model-types';
/**
* @internal
*/
export function applySegmentFormatting(
text: string,
paragraph: ContentModelParagraph,
decorator?: ContentModelParagraphDecorator
): ContentModelParagraph | undefined {
if (text.length === 0) {
const br = createBr();
paragraph.segments.push(br);
} else {
const segments: ContentModelSegment[] = [];
parseInlineSegments(text, segments);
// Apply heading adjustment to the first text-bearing segment, if any.
let headingAdjusted = false;
for (const segment of segments) {
if (!headingAdjusted && segment.segmentType === 'Text') {
const adjusted = adjustHeading(segment, decorator);
headingAdjusted = true;
if (!adjusted) {
continue;
}
}
paragraph.segments.push(segment);
}
}
return paragraph;
}
|