Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 80 additions & 107 deletions packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts

Large diffs are not rendered by default.

45 changes: 30 additions & 15 deletions packages/layout-engine/pm-adapter/src/converters/paragraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,34 @@ const applyInlineRunProperties = (
return { ...run, ...runAttrs };
};

/**
* Extracts the default font family and size from paragraph properties.
* Used for creating default runs in empty paragraphs.
* @param converterContext - Converter context with document styles
* @param paragraphProperties - Resolved paragraph properties
* @returns Object with defaultFont and defaultSize
*/
function extractDefaultFontProperties(
converterContext: ConverterContext,
paragraphProperties: ParagraphProperties,
): { defaultFont: string; defaultSize: number } {
const defaultRunAttrs = computeRunAttrs(
resolveRunProperties(
converterContext,
paragraphProperties.runProperties,
paragraphProperties,
converterContext.tableInfo,
false,
false,
),
converterContext,
);
return {
defaultFont: defaultRunAttrs.fontFamily!,
defaultSize: defaultRunAttrs.fontSize!,
};
}

/**
* Converts a paragraph PM node to an array of FlowBlocks.
*
Expand All @@ -509,9 +537,6 @@ const applyInlineRunProperties = (
* @param para - Paragraph PM node to convert
* @param nextBlockId - Block ID generator
* @param positions - Position map for PM node tracking
* @param defaultFont - Default font family
* @param defaultSize - Default font size
* @param styleContext - Style resolution context
* @param trackedChanges - Optional tracked changes configuration
* @param bookmarks - Optional bookmark position map
* @param hyperlinkConfig - Hyperlink configuration
Expand All @@ -525,9 +550,6 @@ export function paragraphToFlowBlocks({
para,
nextBlockId,
positions,
defaultFont,
defaultSize,
styleContext,
trackedChangesConfig,
bookmarks,
hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG,
Expand All @@ -551,6 +573,7 @@ export function paragraphToFlowBlocks({
: undefined;
const hasSectPr = Boolean(rawParagraphProps?.sectPr);
const isSectPrMarker = hasSectPr || paraAttrs.pageBreakSource === 'sectPr';
const { defaultFont, defaultSize } = extractDefaultFontProperties(converterContext, resolvedParagraphProperties);

if (paragraphAttrs.pageBreakBefore) {
blocks.push({
Expand Down Expand Up @@ -936,6 +959,7 @@ export function paragraphToFlowBlocks({
enableComments,
);
}
applyInlineRunProperties(tokenRun as TextRun, activeRunProperties, converterContext);
console.debug('[token-debug] paragraph-token-run', {
token: (tokenRun as TextRun).token,
fontFamily: (tokenRun as TextRun).fontFamily,
Expand Down Expand Up @@ -1102,9 +1126,6 @@ export function paragraphToFlowBlocks({
node,
nextBlockId,
positions,
defaultFont,
defaultSize,
styleContext,
trackedChangesConfig,
bookmarks,
hyperlinkConfig,
Expand Down Expand Up @@ -1248,9 +1269,6 @@ export function handleParagraphNode(node: PMNode, context: NodeHandlerContext):
recordBlockKind,
nextBlockId,
positions,
defaultFont,
defaultSize,
styleContext,
trackedChangesConfig,
bookmarks,
hyperlinkConfig,
Expand Down Expand Up @@ -1283,9 +1301,6 @@ export function handleParagraphNode(node: PMNode, context: NodeHandlerContext):
para: node,
nextBlockId,
positions,
defaultFont,
defaultSize,
styleContext,
trackedChangesConfig,
bookmarks,
hyperlinkConfig,
Expand Down
Loading
Loading