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
23 changes: 20 additions & 3 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions lib/properties/src/paragraph-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export type ParagraphProperties = {
*/
change?: null | (ChangeInformation & Omit<ParagraphProperties, 'change'>);
pageBreakBefore?: null | boolean;
/**
* Suppress space above/below when the adjacent paragraph uses the same style.
*/
contextualSpacing?: null | boolean;
/**
* Used for formatting of the `rPr` elements at the top level of a paragraph.
* This is text property changes applied to the whole parent paragraph.
Expand Down Expand Up @@ -175,7 +179,8 @@ export function paragraphPropertiesFromNode(
"date": @${QNS.w}date/string(),
"_node": ./${QNS.w}pPr
},
"pageBreakBefore": docxml:ct-on-off(./${QNS.w}pageBreakBefore),
"pageBreakBefore": docxml:ct-on-off(./${QNS.w}pageBreakBefore),
"contextualSpacing": docxml:ct-on-off(./${QNS.w}contextualSpacing),
"tabs": ./${QNS.w}tabs/array {${QNS.w}tab/map {
"type": @${QNS.w}val/string(),
"leader": @${QNS.w}leader/string(),
Expand Down Expand Up @@ -294,8 +299,12 @@ export async function paragraphPropertiesToNode(
$rpr,
$sectpr,

if (exists($pageBreakBefore)) then element ${QNS.w}pageBreakBefore {
attribute ${QNS.w}val { $pageBreakBefore }
if (exists($pageBreakBefore)) then element ${QNS.w}pageBreakBefore {
attribute ${QNS.w}val { $pageBreakBefore }
} else (),

if (exists($contextualSpacing)) then element ${QNS.w}contextualSpacing {
attribute ${QNS.w}val { $contextualSpacing }
} else (),

if (exists($change)) then element ${QNS.w}pPrChange {
Expand Down Expand Up @@ -359,6 +368,7 @@ export async function paragraphPropertiesToNode(
: null,
listItem: data.listItem || null,
pageBreakBefore: data.pageBreakBefore || null,
contextualSpacing: data.contextualSpacing || null,
change: data.change
? {
id: data.change.id,
Expand Down
16 changes: 16 additions & 0 deletions lib/properties/test/paragraph-properties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,20 @@ describe('Paragraph formatting', () => {
}
);
});

describe('contextualSpacing', () => {
test(
`<w:pPr ${ALL_NAMESPACE_DECLARATIONS}>
<w:contextualSpacing w:val="true" />
</w:pPr>`,
{ contextualSpacing: true }
);

test(
`<w:pPr ${ALL_NAMESPACE_DECLARATIONS}>
<w:contextualSpacing w:val="false" />
</w:pPr>`,
{ contextualSpacing: false }
);
});
});