Paragraph
Paragraph:
{}Represents a paragraph block-level element within a document.
Remarks
Section titled “Remarks”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:
BlockLevelContainer.blocklevels- Get all block-level elementsBlockLevelContainer.addParagraph- Create a new paragraph
To work with paragraph content, use asTextView to get a TextView interface
that provides methods for reading and manipulating the text and inline elements.
Examples
Section titled “Examples”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();
const textView = newPara.asTextView();textView.setText('This is a new paragraph.');
// Apply formattingtextView.setFormatting({ bold: true, fontSize: 14 });Properties
Section titled “Properties”type:
"paragraph"
Type discriminator for block-level elements.
Remarks
Section titled “Remarks”Always has the value 'paragraph'. Use this property to narrow the block-level
element type and access paragraph-specific methods.
replaceText
Section titled “replaceText”replaceText:
ReplaceTextSignature
Replaces all occurrences of a pattern with new content.
Remarks
Section titled “Remarks”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.
Examples
Section titled “Examples”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 } });}Methods
Section titled “Methods”asTextView()
Section titled “asTextView()”asTextView():
TextView
Gets a TextView interface for reading and manipulating the paragraph’s content.
Returns
Section titled “Returns”A TextView that provides access to the paragraph’s inline elements
Remarks
Section titled “Remarks”Returns a TextView interface that exposes methods for working with the
paragraph’s text and inline elements. Use this to:
- Read text content (
TextView.getPlainText) - Search for text (
TextView.searchText) - Modify text (
TextView.setText) - Apply formatting (
TextView.setFormatting) - Access inline elements (
TextView.inlines)
Example
Section titled “Example”if (blockLevel.type === 'paragraph') { const textView = blockLevel.asTextView(); const text = textView.getPlainText(); console.log('Paragraph content:', text);}