docx_parser_converter.docx_parsers.numbering.numbering_parser module

class docx_parser_converter.docx_parsers.numbering.numbering_parser.NumberingParser(source: bytes | str)[source]

Bases: object

Parses the numbering definitions from a DOCX file.

This class extracts and parses the numbering definitions found in the numbering.xml file of a DOCX document, converting them into structured Pydantic models for further processing or conversion to other formats.

extract_fonts(lvl: Element) FontProperties | None[source]

Extracts font properties from a numbering level.

Parameters:

lvl (etree.Element) – The XML element representing the numbering level.

Returns:

The extracted font properties.

Return type:

Optional[FontProperties]

Example

The following is an example of run properties with font settings in a numbering level:

<w:rPr>
    <w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
</w:rPr>
extract_indentation(lvl: Element) IndentationProperties | None[source]

Extracts indentation properties from a numbering level.

Parameters:

lvl (etree.Element) – The XML element representing the numbering level.

Returns:

The extracted indentation properties.

Return type:

Optional[IndentationProperties]

Example

The following is an example of paragraph properties with indentation in a numbering level:

<w:pPr>
    <w:ind w:left="720" w:hanging="360"/>
</w:pPr>
extract_level(numId: int, lvl: Element) NumberingLevel[source]

Extracts a single numbering level.

Parameters:
  • numId (int) – The numbering ID.

  • lvl (etree.Element) – The XML element representing the numbering level.

Returns:

The extracted numbering level.

Return type:

NumberingLevel

Example

The following is an example of a numbering level in a numbering.xml file:

<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:lvl>
extract_levels(abstractNumId: int) List[NumberingLevel][source]

Extracts the levels for a given abstract numbering ID.

Parameters:

abstractNumId (int) – The abstract numbering ID.

Returns:

The list of extracted numbering levels.

Return type:

List[NumberingLevel]

extract_tab(lvl: Element) float | None[source]

Extracts tab stop properties from a numbering level.

Parameters:

lvl (etree.Element) – The XML element representing the numbering level.

Returns:

The tab stop position in points.

Return type:

Optional[float]

Example

The following is an example of paragraph properties with a tab stop in a numbering level:

<w:pPr>
    <w:tabs>
        <w:tab w:val="left" w:pos="720"/>
    </w:tabs>
</w:pPr>
get_numbering_schema() NumberingSchema[source]

Gets the parsed numbering schema.

Returns:

The parsed numbering schema.

Return type:

NumberingSchema

parse() NumberingSchema[source]

Parses the numbering XML into a NumberingSchema.

Returns:

The parsed numbering schema.

Return type:

NumberingSchema

Example

The following is an example of a numbering definition in a numbering.xml file:

<w:numbering>
    <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:lvl>
    </w:abstractNum>
</w:numbering>