docx_plus.comments.read¶
Inverse of add_comment: walks comments.xml and pairs each
<w:comment> with the body-side range it anchors. Each result carries
the comment body text, the anchored document text, the paragraph index
where the comment is attached, and parsed metadata (author, initials,
timestamp). Orphaned comments (no matching body range) appear with
anchored_text="" and paragraph_index=-1.
Each result also carries its position in the thread graph — parent_id
and resolved. For the nested view, see
docx_plus.comments.threads.
docx_plus.comments.read ¶
Read every anchored comment from a document.
Inverse of :func:docx_plus.comments.add_comment: walks the comments
part and pairs each <w:comment> with the body-side range it anchors,
extracting the comment text and the document text the comment is
attached to, plus its position in the thread graph.
For the nested view — roots with their replies grouped — see
:func:docx_plus.comments.read_threads.
This module imports only from docx_plus.core and the siblings
docx_plus.comments._extended / docx_plus.comments._ids
(SPEC §9.1).
AnchoredComment
dataclass
¶
AnchoredComment(
comment_id: int,
author: str,
initials: str | None,
timestamp: datetime | None,
text: str,
anchored_text: str,
paragraph_index: int,
parent_id: int | None = None,
resolved: bool = False,
durable_id: str | None = None,
)
A comment paired with the document text it anchors to.
Attributes:
| Name | Type | Description |
|---|---|---|
comment_id |
int
|
The |
author |
str
|
The |
initials |
str | None
|
The |
timestamp |
datetime | None
|
The |
text |
str
|
The comment body text. Multiple text runs are concatenated. |
anchored_text |
str
|
The document text between the comment's
|
paragraph_index |
int
|
Zero-based index (within
|
parent_id |
int | None
|
|
resolved |
bool
|
Whether the comment's thread is marked resolved
( |
durable_id |
str | None
|
The |
read_comments ¶
Return every comment in doc paired with the text it anchors to.
A comment with no matching body range still appears in the result
with anchored_text="" and paragraph_index=-1 — this is the
"orphaned" state that python-docx's add_comment produces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The python-docx :class: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[AnchoredComment]
|
class: |
list[AnchoredComment]
|
|
|
list[AnchoredComment]
|
comments part at all. |