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 | 1x 1x 1x 22x 22x 22x 22x 22x 22x | import { getSelectedParagraphs } from 'roosterjs-content-model-dom'; import { splitSelectedParagraphByBr } from '../../modelApi/block/splitSelectedParagraphByBr'; import type { IEditor, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types'; /** * Invoke a callback to format the selected paragraph using Content Model * @param editor The editor object * @param apiName Name of API this calling this function. This is mostly for logging. * @param setStyleCallback The callback to format the paragraph. It will be called with current selected table. If no table is selected, it will not be called. */ export function formatParagraphWithContentModel( editor: IEditor, apiName: string, setStyleCallback: (paragraph: ShallowMutableContentModelParagraph) => void ) { editor.formatContentModel( (model, context) => { splitSelectedParagraphByBr(model); const paragraphs = getSelectedParagraphs(model, true /*mutate*/); paragraphs.forEach(setStyleCallback); context.newPendingFormat = 'preserve'; return paragraphs.length > 0; }, { apiName, } ); } |