Add a single comment to comments.xml.
(
self, comment_id, para_id, text, author, initials, timestamp
)
| 1066 | # ==================== Private: XML File Creation ==================== |
| 1067 | |
| 1068 | def _add_to_comments_xml( |
| 1069 | self, comment_id, para_id, text, author, initials, timestamp |
| 1070 | ): |
| 1071 | """Add a single comment to comments.xml.""" |
| 1072 | if not self.comments_path.exists(): |
| 1073 | shutil.copy(TEMPLATE_DIR / "comments.xml", self.comments_path) |
| 1074 | |
| 1075 | editor = self["word/comments.xml"] |
| 1076 | root = editor.get_node(tag="w:comments") |
| 1077 | |
| 1078 | escaped_text = ( |
| 1079 | text.replace("&", "&").replace("<", "<").replace(">", ">") |
| 1080 | ) |
| 1081 | # Note: w:rsidR, w:rsidRDefault, w:rsidP on w:p, w:rsidR on w:r, |
| 1082 | # and w:author, w:date, w:initials on w:comment are automatically added by DocxXMLEditor |
| 1083 | comment_xml = f'''<w:comment w:id="{comment_id}"> |
| 1084 | <w:p w14:paraId="{para_id}" w14:textId="77777777"> |
| 1085 | <w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:annotationRef/></w:r> |
| 1086 | <w:r><w:rPr><w:color w:val="000000"/><w:sz w:val="20"/><w:szCs w:val="20"/></w:rPr><w:t>{escaped_text}</w:t></w:r> |
| 1087 | </w:p> |
| 1088 | </w:comment>''' |
| 1089 | editor.append_to(root, comment_xml) |
| 1090 | |
| 1091 | def _add_to_comments_extended_xml(self, para_id, parent_para_id): |
| 1092 | """Add a single comment to commentsExtended.xml.""" |
no test coverage detected