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.
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.
This module imports only from docx_plus.core (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,
)
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
|
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. |