MCPcopy Index your code
hub / github.com/python-openxml/python-docx / add_comment

Method add_comment

src/docx/oxml/comments.py:32–61  ·  view source on GitHub ↗

Return newly added `w:comment` child of this `w:comments`. The returned `w:comment` element is the minimum valid value, having a `w:id` value unique within the existing comments and the required `w:author` attribute present but set to the empty string. It's content is limite

(self)

Source from the content-addressed store, hash-verified

30 comment = ZeroOrMore("w:comment")
31
32 def add_comment(self) -> CT_Comment:
33 """Return newly added `w:comment` child of this `w:comments`.
34
35 The returned `w:comment` element is the minimum valid value, having a `w:id` value unique
36 within the existing comments and the required `w:author` attribute present but set to the
37 empty string. It's content is limited to a single run containing the necessary annotation
38 reference but no text. Content is added by adding runs to this first paragraph and by
39 adding additional paragraphs as needed.
40 """
41 next_id = self._next_available_comment_id()
42 comment = cast(
43 CT_Comment,
44 parse_xml(
45 f'<w:comment {nsdecls("w")} w:id="{next_id}" w:author="">'
46 f" <w:p>"
47 f" <w:pPr>"
48 f' <w:pStyle w:val="CommentText"/>'
49 f" </w:pPr>"
50 f" <w:r>"
51 f" <w:rPr>"
52 f' <w:rStyle w:val="CommentReference"/>'
53 f" </w:rPr>"
54 f" <w:annotationRef/>"
55 f" </w:r>"
56 f" </w:p>"
57 f"</w:comment>"
58 ),
59 )
60 self.append(comment)
61 return comment
62
63 def get_comment_by_id(self, comment_id: int) -> CT_Comment | None:
64 """Return the `w:comment` element identified by `comment_id`, or |None| if not found."""

Callers

nothing calls this directly

Calls 4

parse_xmlFunction · 0.90
nsdeclsFunction · 0.90
appendMethod · 0.80

Tested by

no test coverage detected