docx
    Preparing search index...

    Class Paragraph

    Represents a paragraph in a WordprocessingML document.

    A paragraph is the primary unit of block-level content in a document and can contain various inline elements such as text runs, images, hyperlinks, and bookmarks.

    Reference: http://officeopenxml.com/WPparagraph.php

    <xsd:complexType name="CT_P">
    <xsd:sequence>
    <xsd:element name="pPr" type="CT_PPr" minOccurs="0"/>
    <xsd:group ref="EG_PContent" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="rsidRPr" type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidR" type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidDel" type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidP" type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidRDefault" type="ST_LongHexNumber"/>
    </xsd:complexType>
    // Simple paragraph with text
    new Paragraph("Hello World");

    // Paragraph with options
    new Paragraph({
    children: [new TextRun("Hello"), new TextRun({ text: "World", bold: true })],
    alignment: AlignmentType.CENTER,
    });

    Hierarchy (View Summary)

    Index
    fileChild: symbol = ...

    Marker property identifying this as a FileChild

    The options the paragraph was made with. A paragraph made from a string has it as its text

    • get Alignment(): Pick<IParagraphOptions, "alignment" | "bidirectional">
      Internal

      The paragraph's alignment and direction, which a table gives the empty paragraphs of the cells it adds below a cell merged down rows (rowSpan), so that the merged cell is aligned as one.

      Returns Pick<IParagraphOptions, "alignment" | "bidirectional">

    • get writtenAs(): readonly BaseXmlComponent[] | undefined
      Internal

      The components written in this one's place, one after another, when it can't be written as a single element, such as a run with another run in its children. Undefined when it is written as itself.

      Returns readonly BaseXmlComponent[] | undefined

    • Internal

      Ends a section at this paragraph by adding the section's properties to the paragraph's properties, as Word does with the last paragraph of each section but the last.

      The body adds them only while it is written and removes them afterwards with removeSectionProperties, so the same paragraph can be used in other documents.

      Parameters

      • sectionProperties: SectionProperties

        The properties of the section the paragraph ends

      Returns void

    • Prepares this component and its children for XML serialization.

      This method is called by the Formatter to convert the component tree into an object structure compatible with the xml library (https://www.npmjs.com/package/xml). It recursively processes all children and handles special cases like attribute-only elements and empty elements.

      The method can be overridden by subclasses to customize XML representation or execute side effects during serialization (e.g., creating relationships).

      Parameters

      • context: IContext

        The serialization context containing document state

      Returns IXmlableObject | undefined

      The XML-serializable object, or undefined to exclude from output

      // Override to add custom serialization logic
      prepForXml(context: IContext): IXmlableObject | undefined {
      // Custom logic here
      return super.prepForXml(context);
      }
    • Makes a new paragraph with the paragraph's options and these, which take the place of its own, such as to indent the paragraphs a parser made. The paragraph itself is left as it is, and the new one has the same children.

      Each option given replaces the paragraph's whole option: to keep the rest of its spacing, give spacing: { ...paragraph.options.spacing, before: 240 }. An option given as undefined is removed.

      Parameters

      Returns Paragraph

      const indented = paragraphs.map((paragraph) => paragraph.with({ indent: { left: 720, right: 720 } }));