MCPcopy Create free account
hub / github.com/SpaceZephyr/myskill / _add_to_comments_xml

Method _add_to_comments_xml

docx/scripts/document.py:1068–1089  ·  view source on GitHub ↗

Add a single comment to comments.xml.

(
        self, comment_id, para_id, text, author, initials, timestamp
    )

Source from the content-addressed store, hash-verified

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("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
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''&#x27;<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>''&#x27;
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."""

Callers 2

add_commentMethod · 0.95
reply_to_commentMethod · 0.95

Calls 2

get_nodeMethod · 0.80
append_toMethod · 0.45

Tested by

no test coverage detected