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

Paragraph

Paragraph:

Represents a paragraph block-level element within a document.

Paragraph is one of the primary block-level elements in a document (along with Table). It contains content like text, images, line breaks, and other elements.

Paragraphs are obtained from:

To work with paragraph content, use asTextView to get a TextView interface that provides methods for reading and manipulating the text and inline elements.

Iterate through all paragraphs in a section:

const blockLevels = section.content().blocklevels();
for (const bl of blockLevels) {
if (bl.type === 'paragraph') {
const textView = bl.asTextView();
const text = textView.getPlainText();
console.log('Paragraph text:', text);
}
}

Add and populate a new paragraph:

const container = section.content();
const newPara = container.addParagraph();
// Set text content
const textView = newPara.asTextView();
textView.setText('This is a new paragraph.');
// Apply formatting
textView.setFormatting({ bold: true, fontSize: 14 });

type: "paragraph"

Type discriminator for block-level elements.

Always has the value 'paragraph'. Use this property to narrow the block-level element type and access paragraph-specific methods.


replaceText: ReplaceTextSignature

Replaces all occurrences of a pattern with new content.

Convenience method equivalent to calling TextView.replaceText on the result of asTextView. Searches for all matches of the pattern within this paragraph and replaces them with the specified content.

See ReplaceTextSignature for detailed parameter and usage information.

if (blockLevel.type === 'paragraph') {
// Replace all "TODO" with "DONE"
const count = blockLevel.replaceText(/TODO/g, 'DONE');
console.log(`Replaced ${count} occurrences`);
}
if (blockLevel.type === 'paragraph') {
// Replace with formatting
blockLevel.replaceText(/ERROR/gi, {
text: 'ERROR',
formatting: { color: '#ff0000', bold: true }
});
}

asTextView(): TextView

Gets a TextView interface for reading and manipulating the paragraph’s content.

TextView

A TextView that provides access to the paragraph’s inline elements

Returns a TextView interface that exposes methods for working with the paragraph’s text and inline elements. Use this to:

if (blockLevel.type === 'paragraph') {
const textView = blockLevel.asTextView();
const text = textView.getPlainText();
console.log('Paragraph content:', text);
}