docx_parser_converter.docx_to_html.converters.numbering_converter module

class docx_parser_converter.docx_to_html.converters.numbering_converter.NumberingConverter[source]

Bases: object

A converter class for handling numbered paragraphs in DOCX documents.

static convert_numbering(paragraph: Paragraph, numbering_schema: NumberingSchema) str[source]

Converts the numbering for a given paragraph to its HTML representation.

Parameters:
  • paragraph (Paragraph) – The paragraph containing the numbering to convert.

  • numbering_schema – The schema containing numbering definitions.

Returns:

The HTML representation of the numbering.

Return type:

str

Example

Given a paragraph with numbering, the output HTML string might look like:

<span style="font-family:Times New Roman;">1.</span><span style="padding-left:7.2pt;"></span>
<span style="font-family:Times New Roman;">I.</span><span style="padding-left:7.2pt;"></span>
static format_number(counter: int, numFmt: str) str[source]

Formats the counter according to the specified numbering format.

Parameters:
  • counter (int) – The current counter value.

  • numFmt (str) – The numbering format (e.g., “decimal”, “lowerRoman”).

Returns:

The formatted number.

Return type:

str

Example

The following converts a counter value to different formats:

NumberingConverter.format_number(1, "decimal")  # "1"
NumberingConverter.format_number(1, "lowerRoman")  # "i"
NumberingConverter.format_number(1, "upperRoman")  # "I"
NumberingConverter.format_number(1, "lowerLetter")  # "a"
NumberingConverter.format_number(1, "upperLetter")  # "A"
NumberingConverter.format_number(1, "bullet")  # "•"
static get_numbering_level(numbering_schema, numId: int, ilvl: int) NumberingLevel[source]

Retrieves the numbering level from the numbering schema.

Parameters:
  • numbering_schema – The schema containing numbering definitions.

  • numId (int) – The numbering ID.

  • ilvl (int) – The numbering level.

Returns:

The retrieved numbering level.

Return type:

NumberingLevel

Raises:

ValueError – If the numbering level is not found.

Example

The numbering level might be represented in the schema as:

<w:num w:numId="1">
    <w:abstractNumId w:val="0"/>
</w:num>
<w:abstractNum w:abstractNumId="0">
    <w:lvl w:ilvl="0">
        <w:start w:val="1"/>
        <w:numFmt w:val="decimal"/>
        <w:lvlText w:val="%1."/>
        <w:lvlJc w:val="left"/>
        <w:pPr>
            <w:ind w:left="720" w:hanging="360"/>
        </w:pPr>
        <w:rPr>
            <w:rFonts w:ascii="Times New Roman"/>
        </w:rPr>
    </w:lvl>
</w:abstractNum>
static reset_counters()[source]
static to_lower_letter(num: int) str[source]

Converts a number to its lowercase letter representation.

Parameters:

num (int) – The number to convert.

Returns:

The lowercase letter representation.

Return type:

str

Example

The following converts a number to a lowercase letter:

NumberingConverter.to_lower_letter(1)  # "a"
static to_roman(num: int) str[source]

Converts a number to its Roman numeral representation.

Parameters:

num (int) – The number to convert.

Returns:

The Roman numeral representation.

Return type:

str

Example

The following converts a number to Roman numeral:

NumberingConverter.to_roman(1)  # "I"
static to_upper_letter(num: int) str[source]

Converts a number to its uppercase letter representation.

Parameters:

num (int) – The number to convert.

Returns:

The uppercase letter representation.

Return type:

str

Example

The following converts a number to an uppercase letter:

NumberingConverter.to_upper_letter(1)  # "A"