File tree Expand file tree Collapse file tree 4 files changed +19
-2
lines changed
Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ Feature: Get comment properties
1414 Then comment.author is the author of the comment
1515
1616
17- @wip
1817 Scenario : Comment.initials
1918 Given a Comment object
2019 Then comment.initials is the initials of the comment author
Original file line number Diff line number Diff line change @@ -62,3 +62,12 @@ def author(self) -> str:
6262 def comment_id (self ) -> int :
6363 """The unique identifier of this comment."""
6464 return self ._comment_elm .id
65+
66+ @property
67+ def initials (self ) -> str | None :
68+ """Read/write. The recorded initials of the comment author.
69+
70+ This attribute is optional in the XML, returns |None| if not set. Assigning |None| removes
71+ any existing initials from the XML.
72+ """
73+ return self ._comment_elm .initials
Original file line number Diff line number Diff line change 33from __future__ import annotations
44
55from docx .oxml .simpletypes import ST_DecimalNumber , ST_String
6- from docx .oxml .xmlchemy import BaseOxmlElement , RequiredAttribute , ZeroOrMore
6+ from docx .oxml .xmlchemy import BaseOxmlElement , OptionalAttribute , RequiredAttribute , ZeroOrMore
77
88
99class CT_Comments (BaseOxmlElement ):
@@ -36,3 +36,6 @@ class CT_Comment(BaseOxmlElement):
3636
3737 id : int = RequiredAttribute ("w:id" , ST_DecimalNumber ) # pyright: ignore[reportAssignmentType]
3838 author : str = RequiredAttribute ("w:author" , ST_String ) # pyright: ignore[reportAssignmentType]
39+ initials : str | None = OptionalAttribute ( # pyright: ignore[reportAssignmentType]
40+ "w:initials" , ST_String
41+ )
Original file line number Diff line number Diff line change @@ -107,6 +107,12 @@ def it_knows_its_author(self, comments_part_: Mock):
107107
108108 assert comment .author == "Steve Canny"
109109
110+ def it_knows_the_initials_of_its_author (self , comments_part_ : Mock ):
111+ comment_elm = cast (CT_Comment , element ("w:comment{w:id=42,w:initials=SJC}" ))
112+ comment = Comment (comment_elm , comments_part_ )
113+
114+ assert comment .initials == "SJC"
115+
110116 # -- fixtures --------------------------------------------------------------------------------
111117
112118 @pytest .fixture
You can’t perform that action at this time.
0 commit comments