Repository navigation
fix(odf): keep ODT comments out of the body text - #4436
PeterStaar-IBM merged 3 commits into
Conversation
An ODT comment (office:annotation) sits inline in the paragraph, heading, list item or table cell it annotates. Every text path read its creator, date and body as inline text, so the comment was spliced into the document text and no comment reached the NOTES layer. Remove the annotations from the parsed body before the walk. Use the plain Element.delete(), because odfdo Annotation.delete() searches the whole body for the matching office:annotation-end once per comment. An office:annotation-end marker holds no text, so it stays in the body. Add each comment to a COMMENT_SECTION group in the NOTES layer, in the '[author: Name (initials), time: date]: text' form of the DOCX backend. A reply (loext:parent-name) joins the group of the comment it answers, also when the reply comes before that comment. As in the XLSX backend, each comment comes before its replies. The walk drops text deleted in a tracked change, so a comment on that text is detached but not added to a group, the same as on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Yash Raj Pandey <yashpn62@gmail.com>
|
✅ DCO Check Passed Thanks @devYRPauli, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Each comment thread was a COMMENT_SECTION group at the document root, so a reader could not tell which item a comment annotates. _detach_annotations() now keys each thread by the paragraph or heading that holds its first comment. The walk passes the threads down and adds them where it makes the item for that paragraph: a heading, a paragraph, a list item, a table for a plain cell, and a footnote. A paragraph in a rich table cell is a paragraph. The thread group is a child of the item in the NOTES layer, and the item gets a FineRef to the group in its comments, as in the DOCX backend. An InlineGroup has no comments field, so a paragraph with several runs gets only the child group. A thread whose paragraph makes no item goes to the root, so no comment is lost. The key is the lxml element under the odfdo wrapper, because odfdo builds a new wrapper on every access. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Yash Raj Pandey <yashpn62@gmail.com>
The walk skips a text box, so its paragraph makes no item. The thread of a comment in that paragraph goes to the root after the walk. No test reached that path before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Yash Raj Pandey <yashpn62@gmail.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@PeterStaar-IBM The changes requested in your review are addressed in d3212ae and 9f3d88b, and the original review threads are now outdated. When you have a chance, could you please take another look? |
dolfim-ibm
left a comment
There was a problem hiding this comment.
Peter's points are addressed: each thread is now a COMMENT_SECTION group in the NOTES layer under the annotated item, with the FineRef back-link as in DOCX. The branch merges cleanly with current main (after the recent ODF chart/page_range changes), and the ODF suite passes on the merge.
Two non-blocking follow-ups:
- a comment in a paragraph holding only an image lands at the document root instead of under the
PictureItem, because_add_odf_paragraphreturns early; - ODP slide comments (
officeooo:annotation) are still out of scope, worth a separate issue.
lgtm
|
Agreed on both follow-ups.
|
An ODT comment (
office:annotation) sits inline in the element it annotates. Every text path inOdtDocumentBackendreads the author, date and text of the comment as inline text. The comment is spliced into the paragraph, heading, list item or table cell, and no comment reaches theNOTESlayer.The script in the issue, on
mainand on this branch:main## BudgetAnn Reviewer2024-01-15T10:00:00ARRename this heading## BudgetThe total is Ann Reviewer2024-01-15T10:00:00ARSource?42 EUR.The total is 42 EUR.- First itemAnn Reviewer2024-01-15T10:00:00ARToo vague- First itemValCell remark Ann Reviewer 2024-01-15 10:00:00ValThe fix:
_detach_annotations()removes everyoffice:annotationfrom the parsed body before the walk. It records the paragraph or heading that holds each comment. The tail text stays in place. One change at the parse step covers every text path.office:annotation-endmarker holds no text, so it stays in the body and adds nothing to the output.Annotation.delete(). That method searches the whole body for the matchingoffice:annotation-end, once per comment.main.COMMENT_SECTIONgroupcomment-<n>in theNOTESlayer. The text uses the DOCX form[author: Name (initials), time: date]: text. The time isdc:dateas written, as in the PPTX backend.FineRefto the group initem.comments, as in the DOCX backend. This covers a heading, a paragraph, a list item, a footnote and a paragraph in a rich table cell.InlineGroup.InlineGrouphas nocommentsfield, so it gets the child group but noFineRef.loext:parent-name. It joins the group of the comment it answers, also when the reply comes before that comment. As in the XLSX backend, each comment comes before its replies. Replies to the same comment keep document order. Aloext:parent-namecycle still gives one group, and no comment is dropped.officeooo:annotationindraw:page).Tests:
test_odt_annotation_becomes_comment_not_body_textbuilds the ODT in code, sotests/datadoes not change. It checks the markdown, the footnote text, the comment groups and theirNOTESlayer. It checks the parent of each of the 13 comment groups and theFineRefon each text item and table.loext:parent-namecycle and two comments with nooffice:name. It also has a comment inside a footnote and a comment on deleted tracked-change text, which is not emitted. One reply writes its initials inloext:sender-initials.main, the new test fails withThe total is Ann Reviewer2024-01-15T10:00:00ARSource?Bo Writer2024-01-15T10:00:00BWAdded below.42 EUR this year.769ee38f, the new test also fails. That backend puts all 13 comment groups under the document root, with noFineRef.tests/test_backend_opendocument.py: 48 passed onmainat38b6fa0a, 49 passed on a local merge of this branch into thatmain. The ground truth of the ODT, ODS and ODP samples does not change.prekhooks pass on both files.tyreports 39 warnings onopendocument_backend.py, and 37 onmain. The 2 new warnings are onFineRef(cref=...).tyreports the same 2 warnings on the same call inmsword_backend.py.Issue resolved by this Pull Request:
Resolves #4435
Checklist: