docx_parser_converter.docx_to_txt.converters.paragraph_converter module

class docx_parser_converter.docx_to_txt.converters.paragraph_converter.ParagraphConverter[source]

Bases: object

Class to convert paragraphs to plain text.

static add_indentation(text: str, indent_value: float) str[source]

Add indentation to the text based on the indent value in points.

Parameters:
  • text (str) – The text to indent.

  • indent_value (float) – The indentation value in points.

Returns:

The indented text.

Return type:

str

Example

indented_text = ParagraphConverter.add_indentation("This is a test.", 72)
print(indented_text)  # Output: "               This is a test."
static add_spacing(prev_paragraph: Paragraph, curr_paragraph: Paragraph) str[source]

Add spacing between paragraphs based on their spacing properties.

Args:

prev_paragraph (Paragraph): The previous paragraph. curr_paragraph (Paragraph): The current paragraph.

Returns:

str: Newlines to add for spacing.

Example:
spacing = ParagraphConverter.add_spacing(prev_paragraph, curr_paragraph)
print(spacing)  # Output: "

“ (depending on spacing properties)

static convert_paragraph(paragraph: Paragraph, numbering_schema, indent: bool) str[source]

Convert a paragraph to plain text.

Parameters:
  • paragraph (Paragraph) – The paragraph object.

  • numbering_schema – The numbering schema.

  • indent (bool) – Whether to apply indentation.

Returns:

Plain text representation of the paragraph.

Return type:

str

Example

paragraph_text = ParagraphConverter.convert_paragraph(paragraph, numbering_schema, indent=True)
print(paragraph_text)
static convert_paragraph_properties(properties, indent: bool) str[source]

Convert paragraph properties to text format.

Parameters:
  • properties – The paragraph properties.

  • indent (bool) – Whether to apply indentation.

Returns:

Text representation of paragraph properties.

Return type:

str

Example

paragraph_properties_text = ParagraphConverter.convert_paragraph_properties(properties, indent=True)
print(paragraph_properties_text)