docx_parser_converter.docx_parsers.styles.paragraph_properties_parser module

class docx_parser_converter.docx_parsers.styles.paragraph_properties_parser.ParagraphPropertiesParser[source]

Bases: object

Parses the paragraph properties from a DOCX paragraph properties element.

This class extracts and parses various properties related to paragraph formatting, converting them into structured Pydantic models for further processing or conversion to other formats.

convert_to_points(element: Element, attrs: List[str]) float | None[source]

Converts the given attribute values to points.

Parameters:
  • element (ET.Element) – The XML element containing the attributes.

  • attrs (List[str]) – The list of attribute names to convert.

Returns:

The converted value in points, or None if not found.

Return type:

Optional[float]

Example

The following is an example of converting attributes to points:

left_pt = self.convert_to_points(indent_element, ['left', 'start'])
extract_bidi(pPr_element: Element) bool | None[source]

Extracts the bidirectional setting from the given paragraph properties element.

Parameters:

pPr_element (ET.Element) – The paragraph properties element.

Returns:

The bidirectional setting.

Return type:

Optional[bool]

Example

The following is an example of a bidirectional setting in a paragraph properties element:

<w:bidi/>
extract_highlight(pPr_element: Element) str | None[source]

Extracts paragraph highlight/shading color from the properties element.

Prefers an explicit <w:highlight w:val=”…”> if present, otherwise falls back to the fill color defined on <w:shd>.

extract_indentation(pPr_element: Element) IndentationProperties | None[source]

Extracts indentation properties from the given paragraph properties element.

Parameters:

pPr_element (ET.Element) – The paragraph properties element.

Returns:

The extracted indentation properties.

Return type:

Optional[IndentationProperties]

Example

The following is an example of indentation properties in a paragraph properties element:

<w:ind w:left="720" w:right="720" w:firstLine="720"/>
extract_justification(pPr_element: Element) str | None[source]

Extracts the justification value from the given element.

Parameters:

pPr_element (ET.Element) – The element containing the justification.

Returns:

The raw DOCX justification value (e.g., ‘left’, ‘start’, ‘both’) or None.

Return type:

Optional[str]

Example

The following is an example of a justification setting in a paragraph properties element:

<w:jc w:val="both"/>
extract_keep_next(pPr_element: Element) bool | None[source]

Extracts the keep next setting from the given paragraph properties element.

Parameters:

pPr_element (ET.Element) – The paragraph properties element.

Returns:

The keep next setting.

Return type:

Optional[bool]

Example

The following is an example of a keep next setting in a paragraph properties element:

<w:keepNext/>
extract_outline_level(pPr_element: Element) int | None[source]

Extracts the outline level from the given paragraph properties element.

Parameters:

pPr_element (ET.Element) – The paragraph properties element.

Returns:

The extracted outline level.

Return type:

Optional[int]

Example

The following is an example of an outline level in a paragraph properties element:

<w:outlineLvl w:val="1"/>
extract_spacing(pPr_element: Element) SpacingProperties | None[source]

Extracts spacing properties from the given paragraph properties element.

Parameters:

pPr_element (ET.Element) – The paragraph properties element.

Returns:

The extracted spacing properties.

Return type:

Optional[SpacingProperties]

Example

The following is an example of spacing properties in a paragraph properties element:

<w:spacing w:before="240" w:after="240" w:line="360"/>
extract_suppress_auto_hyphens(pPr_element: Element) bool | None[source]

Extracts the suppress auto hyphens setting from the given paragraph properties element.

Parameters:

pPr_element (ET.Element) – The paragraph properties element.

Returns:

The suppress auto hyphens setting.

Return type:

Optional[bool]

Example

The following is an example of a suppress auto hyphens setting in a paragraph properties element:

<w:suppressAutoHyphens/>
extract_suppress_line_numbers(pPr_element: Element) bool | None[source]

Extracts the suppress line numbers setting from the given paragraph properties element.

Parameters:

pPr_element (ET.Element) – The paragraph properties element.

Returns:

The suppress line numbers setting.

Return type:

Optional[bool]

Example

The following is an example of a suppress line numbers setting in a paragraph properties element:

<w:suppressLineNumbers/>
extract_widow_control(pPr_element: Element) bool | None[source]

Extracts the widow control setting from the given paragraph properties element.

Parameters:

pPr_element (ET.Element) – The paragraph properties element.

Returns:

The widow control setting.

Return type:

Optional[bool]

Example

The following is an example of a widow control setting in a paragraph properties element:

<w:widowControl/>
parse(pPr_element: Element) ParagraphStyleProperties[source]

Parses the given paragraph properties element into a ParagraphStyleProperties object.

Parameters:

pPr_element (ET.Element) – The paragraph properties element.

Returns:

The parsed paragraph style properties.

Return type:

ParagraphStyleProperties

Example

The following is an example of a paragraph properties element:

<w:pPr>
    <w:spacing w:before="240" w:after="240" w:line="360"/>
    <w:ind w:left="720" w:right="720" w:firstLine="720"/>
    <w:jc w:val="both"/>
    <w:outlineLvl w:val="1"/>
    <w:widowControl/>
    <w:suppressAutoHyphens/>
    <w:bidi/>
    <w:keepNext/>
    <w:suppressLineNumbers/>
</w:pPr>