Ensure word/_rels/document.xml.rels has comment relationships.
(self)
| 1201 | editor.append_to(root, person_xml) |
| 1202 | |
| 1203 | def _ensure_comment_relationships(self): |
| 1204 | """Ensure word/_rels/document.xml.rels has comment relationships.""" |
| 1205 | editor = self["word/_rels/document.xml.rels"] |
| 1206 | |
| 1207 | if self._has_relationship(editor, "comments.xml"): |
| 1208 | return |
| 1209 | |
| 1210 | root = editor.dom.documentElement |
| 1211 | root_tag = root.tagName # type: ignore |
| 1212 | prefix = root_tag.split(":")[0] + ":" if ":" in root_tag else "" |
| 1213 | next_rid_num = int(editor.get_next_rid()[3:]) |
| 1214 | |
| 1215 | # Add relationship elements |
| 1216 | rels = [ |
| 1217 | ( |
| 1218 | next_rid_num, |
| 1219 | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", |
| 1220 | "comments.xml", |
| 1221 | ), |
| 1222 | ( |
| 1223 | next_rid_num + 1, |
| 1224 | "http://schemas.microsoft.com/office/2011/relationships/commentsExtended", |
| 1225 | "commentsExtended.xml", |
| 1226 | ), |
| 1227 | ( |
| 1228 | next_rid_num + 2, |
| 1229 | "http://schemas.microsoft.com/office/2016/09/relationships/commentsIds", |
| 1230 | "commentsIds.xml", |
| 1231 | ), |
| 1232 | ( |
| 1233 | next_rid_num + 3, |
| 1234 | "http://schemas.microsoft.com/office/2018/08/relationships/commentsExtensible", |
| 1235 | "commentsExtensible.xml", |
| 1236 | ), |
| 1237 | ] |
| 1238 | |
| 1239 | for rel_id, rel_type, target in rels: |
| 1240 | rel_xml = f'<{prefix}Relationship Id="rId{rel_id}" Type="{rel_type}" Target="{target}"/>' |
| 1241 | editor.append_to(root, rel_xml) |
| 1242 | |
| 1243 | def _ensure_comment_content_types(self): |
| 1244 | """Ensure [Content_Types].xml has comment content types.""" |
no test coverage detected