Skip to content
Document Authoring DA  API Docs v1.10.0
npmGitHub

Replacement

Replacement:

{
formatting?: Partial<Formatting>;
}

Specifies replacement content for text operations, including both text and formatting.

Replacement is used with replace operations to specify what should replace the matched content.

When used in ReplaceTextSignature operations, if text is omitted, the original matched text is preserved and only formatting is modified.

Replace formatting only (preserve text):

// Highlight all occurrences of "important" without changing text
paragraph.replaceText(/important/gi, {
formatting: { highlight: "#ffff00", bold: true }
});

Dynamic replacement based on match (using with ReplaceFn):

// Convert numbers to currency format with styling
paragraph.replaceText(/\$?(\d+(\.\d{2})?)/g, (match) => {
const amount = parseFloat(match.replace('$', ''));
return {
text: `$${amount.toFixed(2)}`,
formatting: {
color: amount > 100 ? "#ff0000" : "#00ff00",
bold: amount > 100
}
};
});

optional text: string

The replacement text content.

When specified, replaces the matched text with this string. When omitted, the original matched text is preserved (useful for formatting-only changes).


optional formatting: Partial<Formatting>

Formatting to apply to the replacement text.

Specifies formatting properties to apply.