docx_plus.numbering.read¶
Reading list definitions back out of numbering.xml, including ones Word
or another tool wrote.
Like every reader in the library this never fabricates a part: a document
with no numbering.xml reads as an empty list rather than gaining one as
a side effect of being inspected.
A fresh Document() is not empty
python-docx's bundled template ships nine abstractNum entries and
nine num instances backing the built-in List Bullet and
List Number styles, so an untouched document already reports nine
definitions.
docx_plus.numbering.read ¶
Reading list definitions back out of numbering.xml.
The read side of :mod:docx_plus.numbering.define. It reports what is
actually in the part — including definitions Word or another tool wrote,
and including the nine abstractNum entries python-docx's bundled
template ships in every fresh document.
Like every reader in the library this never fabricates a part: a
document with no numbering.xml reads as an empty list rather than
gaining one as a side effect of being inspected.
This module imports only from docx_plus.core (SPEC §9.1).
ListDefinition
dataclass
¶
ListDefinition(
num_id: int,
abstract_id: int | None,
levels: tuple[ListLevel, ...],
name: str | None = None,
style_link: str | None = None,
num_style_link: str | None = None,
multi_level_type: str | None = None,
start_overrides: tuple[tuple[int, int], ...] = (),
)
A <w:num> instance together with the definition behind it.
Attributes:
| Name | Type | Description |
|---|---|---|
num_id |
int
|
The |
abstract_id |
int | None
|
The |
levels |
tuple[ListLevel, ...]
|
The abstract definition's levels, outermost first. Empty if the reference is dangling. |
name |
str | None
|
The definition's |
style_link |
str | None
|
|
num_style_link |
str | None
|
|
multi_level_type |
str | None
|
|
start_overrides |
tuple[tuple[int, int], ...]
|
|
ListLevel
dataclass
¶
ListLevel(
level: int,
fmt: str | None = None,
text: str | None = None,
start: int | None = None,
indent: int | None = None,
hanging: int | None = None,
justify: str | None = None,
suffix: str | None = None,
restart_after: int | None = None,
font: str | None = None,
)
One outline level of a definition, as found in the document.
The read-side counterpart of
:class:~docx_plus.numbering.LevelDefinition. Every field mirrors an
optional child of <w:lvl>, so None means "the element is
absent" — which Word reads as its own default, not as zero.
Attributes:
| Name | Type | Description |
|---|---|---|
level |
int
|
Zero-based outline depth ( |
fmt |
str | None
|
|
text |
str | None
|
|
start |
int | None
|
|
indent |
int | None
|
Left indent in twips from the level's |
hanging |
int | None
|
Hanging indent in twips from the same. |
justify |
str | None
|
|
suffix |
str | None
|
|
restart_after |
int | None
|
|
font |
str | None
|
|
read_list_definitions ¶
Return every list definition in doc, in numbering.xml order.
Note
A fresh Document() is not empty here. python-docx's
bundled template ships nine abstractNum entries and nine
num instances covering the built-in List Bullet and
List Number styles, so a document you have not touched
already reports nine definitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The python-docx :class: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[ListDefinition]
|
class: |
list[ListDefinition]
|
the document has no |
Example
from docx import Document from docx_plus.numbering import define_bullet_list, read_list_definitions doc = Document() num = define_bullet_list(doc) mine = [d for d in read_list_definitions(doc) if d.num_id == num] mine[0].levels[0].fmt 'bullet'