Container part for comments added to the document.
| 21 | |
| 22 | |
| 23 | class CommentsPart(StoryPart): |
| 24 | """Container part for comments added to the document.""" |
| 25 | |
| 26 | def __init__( |
| 27 | self, partname: PackURI, content_type: str, element: CT_Comments, package: Package |
| 28 | ): |
| 29 | super().__init__(partname, content_type, element, package) |
| 30 | self._comments = element |
| 31 | |
| 32 | @property |
| 33 | def comments(self) -> Comments: |
| 34 | """A |Comments| proxy object for the `w:comments` root element of this part.""" |
| 35 | return Comments(self._comments, self) |
| 36 | |
| 37 | @classmethod |
| 38 | def default(cls, package: Package) -> Self: |
| 39 | """A newly created comments part, containing a default empty `w:comments` element.""" |
| 40 | partname = PackURI("/word/comments.xml") |
| 41 | content_type = CT.WML_COMMENTS |
| 42 | element = cast("CT_Comments", parse_xml(cls._default_comments_xml())) |
| 43 | return cls(partname, content_type, element, package) |
| 44 | |
| 45 | @classmethod |
| 46 | def _default_comments_xml(cls) -> bytes: |
| 47 | """A byte-string containing XML for a default comments part.""" |
| 48 | path = os.path.join(os.path.split(__file__)[0], "..", "templates", "default-comments.xml") |
| 49 | with open(path, "rb") as f: |
| 50 | xml_bytes = f.read() |
| 51 | return xml_bytes |
no outgoing calls
searching dependent graphs…