Xj0dZddlmZddlZddlmZmZmZddl m Z ddl m Z ddl mZmZmZddlmZmZmZmZer dd lmZdd lmZGd d eZGd deZy)z4Custom element classes related to document comments.) annotationsN) TYPE_CHECKINGCallablecast)nsdecls) parse_xml) ST_DateTimeST_DecimalNumber ST_String)BaseOxmlElementOptionalAttributeRequiredAttribute ZeroOrMore)CT_Tbl)CT_PcDeZdZUdZded<edZd dZd dZd dZ y) CT_Commentsa`w:comments` element, the root element for the comments part. Simply contains a collection of `w:comment` elements, each representing a single comment. Each contained comment is identified by a unique `w:id` attribute, used to reference the comment from the document text. The offset of the comment in this collection is arbitrary; it is essentially a _set_ implemented as a list. zlist[CT_Comment] comment_lstz w:commentc |j}tttdt dd|d}|j ||S)aReturn newly added `w:comment` child of this `w:comments`. The returned `w:comment` element is the minimum valid value, having a `w:id` value unique within the existing comments and the required `w:author` attribute present but set to the empty string. It's content is limited to a single run containing the necessary annotation reference but no text. Content is added by adding runs to this first paragraph and by adding additional paragraphs as needed. z )_next_available_comment_idr CT_Commentrrappend)selfnext_idcomments f/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/oxml/comments.py add_commentzCT_Comments.add_comment sU113  gcl^77) <    $ Gc>|jd|d}|r|dSdS)zRReturn the `w:comment` element identified by `comment_id`, or |None| if not found.z(./w:comment[@w:id='z'])[1]rNxpath)r comment_id comment_elmss rget_comment_by_idzCT_Comments.get_comment_by_id?s+zz$8 F"KL ".|A8D8rc|jdDcgc] }t|}}t|ddz}|dkr|Stt |D]\}}||k7s |cSt |Scc}w)anThe next available comment id. According to the schema, this can be any positive integer, as big as you like, and the default mechanism is to use `max() + 1`. However, if that yields a value larger than will fit in a 32-bit signed integer, we take a more deliberate approach to use the first ununsed integer starting from 0. z./w:comment/@w:id)defaulti)r"intmax enumeratesortedlen)rxused_idsrexpectedactuals rrz&CT_Comments._next_available_comment_idDs%)JJ/B$CDqCFDDh+a/ i N!*&*: ; Hf6! 8}EsA/N)returnr)r#r*r3zCT_Comment | None)r3r*) __name__ __module__ __qualname____doc____annotations__rrrr%rrrrrs("!%G>9 rrceZdZUdZedeZded<edeZ ded<e deZ d ed <e d e Z d ed <eddZeddZded<ded<ded<ded<eddZy)raQ`w:comment` element, representing a single comment. A comment is a so-called "story" and can contain paragraphs and tables much like a table-cell. While probably most often used for a single sentence or phrase, a comment can contain rich content, including multiple rich-text paragraphs, hyperlinks, images, and tables. zw:idr*idzw:authorstrauthorz w:initialsz str | Noneinitialszw:datezdt.datetime | Nonedatezw:pr9) successorszw:tblzCallable[[], CT_P]add_pz list[CT_P]p_lstz list[CT_Tbl]tbl_lstzCallable[[CT_Tbl], CT_Tbl] _insert_tblc$|jdS)z8Generate all `w:p` and `w:tbl` elements in this comment.z./w:p | ./w:tblr!)rs rinner_content_elementsz!CT_Comment.inner_content_elementsyszz+,,rN)r3zlist[CT_P | CT_Tbl])r4r5r6r7rr r;r8r r=r r>r r?rptblpropertyrFr9rrrr[s (89B9#J :FC:,iHj 1+ D  5R(A W ,C   ++ --rr)r7 __future__rdatetimedttypingrrr docx.oxml.nsrdocx.oxml.parserrdocx.oxml.simpletypesr r r docx.oxml.xmlchemyr r rrdocx.oxml.tablerdocx.oxml.text.paragraphrrrr9rrrTsJ:"00 &JJ``&-F/FR!-!-r