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 43 44 45 46 | 1x 1x 1x 1x 1x 1x 1x 198x 19x 19x 179x 204x 204x 204x 8x 8x 196x 11x 196x 196x 194x 194x 198x | import { adjustHeading } from '../utils/adjustHeading';
import { applyLink } from './applyLink';
import { applyTextFormatting } from './applyTextFormatting';
import { createBr, createText } from 'roosterjs-content-model-dom';
import { createImageSegment } from '../creators/createImageSegment';
import { splitParagraphSegments } from '../utils/splitParagraphSegments';
import type {
ContentModelParagraph,
ContentModelParagraphDecorator,
} 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 textSegments = splitParagraphSegments(text);
for (const segment of textSegments) {
const formattedSegment = createText(segment.text);
if (segment.type === 'image') {
const image = createImageSegment(segment.text, segment.url);
paragraph.segments.push(image);
} else {
if (segment.type === 'link') {
applyLink(formattedSegment, segment.text, segment.url);
}
const segmentWithAdjustedHeading = adjustHeading(formattedSegment, decorator);
if (segmentWithAdjustedHeading) {
const formattedSegments = applyTextFormatting(formattedSegment);
paragraph.segments.push(...formattedSegments);
}
}
}
}
return paragraph;
}
|