Annotation
Annotation class for “office:annotation” tag.
Classes:
| Name | Description |
|---|---|
Annotation |
An annotation (private note), “office:annotation”. |
AnnotationEnd |
End of annotation marker, “office:annotation-end”. |
AnnotationMixin |
Mixin class for classes containing Annotations. |
Functions:
| Name | Description |
|---|---|
get_unique_office_name |
Provide an autogenerated unique “office:name” for the document. |
Annotation
Bases: MDTail, ListMixin, LinkMixin, Element, DcCreatorMixin, DcDateMixin
An annotation (private note), “office:annotation”.
This element contains the content of a comment or annotation, along with metadata such as the creator and date.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The unique name of the annotation. |
note_id |
str
|
The ID of the note. |
creator |
str
|
The creator of the annotation. |
date |
datetime
|
The date of the annotation. |
note_body |
str or Element
|
The body content of the annotation. |
Methods:
| Name | Description |
|---|---|
__init__ |
Create an Annotation element. |
__str__ |
|
check_validity |
Checks the validity of the Annotation. |
delete |
Delete the element from the XML tree. |
get_annotated |
Returns the annotated content from an annotation. |
Source code in odfdo/annotation.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
_properties
class-attribute
instance-attribute
_properties = (
PropDef("name", "office:name"),
PropDef("note_id", "text:id"),
)
_tag
class-attribute
instance-attribute
_tag = 'office:annotation'
creator
instance-attribute
creator = creator
date
instance-attribute
date = date
dc_creator
property
writable
dc_creator: str | None
Alias for self.creator property.
dc_date
property
writable
dc_date: datetime | None
Alias for self.date property.
end
property
end: AnnotationEnd | None
Return the corresponding annotation-end tag or None.
name
instance-attribute
name = name
note_body
property
writable
note_body: str
start
property
start: Annotation
Return self.
__init__
__init__(
text_or_element: Element | str | None = None,
creator: str | None = None,
date: datetime | None = None,
name: str | None = None,
parent: Element | None = None,
**kwargs: Any,
) -> None
Create an Annotation element.
An annotation is a private note, represented by “office:annotation”. This element is credited to a creator and contains text content, optionally dated (current date by default).
If ‘name’ is not provided and a ‘parent’ is given, the name will be autogenerated to be unique within the document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_or_element
|
Element | str | None
|
The content of the annotation, which can be a string or another ODF element. |
None
|
creator
|
str | None
|
The name of the person who created the annotation. |
None
|
date
|
datetime | None
|
The date and time when the annotation was created. Defaults to the current time if not provided. |
None
|
name
|
str | None
|
A unique name for the annotation. If not provided, a unique name is generated. |
None
|
parent
|
Element | None
|
The parent element to which this annotation will be associated for name generation. |
None
|
Source code in odfdo/annotation.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
__str__
__str__() -> str
Source code in odfdo/annotation.py
388 389 | |
check_validity
check_validity() -> None
Checks the validity of the Annotation.
Source code in odfdo/annotation.py
379 380 381 382 383 384 385 386 | |
delete
delete(
child: Element | None = None, keep_tail: bool = True
) -> None
Delete the element from the XML tree.
If a child element is provided, it is deleted. If no child is given, the annotation itself and its corresponding “annotation-end” tag (if it exists) are deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
child
|
Element | None
|
The child element to delete. If None, the annotation itself is deleted. Defaults to None. |
None
|
keep_tail
|
bool
|
This argument is not used in this context but is kept for compatibility. Defaults to True. |
True
|
Source code in odfdo/annotation.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
get_annotated
get_annotated(
as_text: bool = False,
no_header: bool = True,
clean: bool = True,
) -> Element | list | str | None
Returns the annotated content from an annotation.
If no content exists (e.g., single position annotation or if the annotation-end tag is not found), it returns an empty list or an empty string if ‘as_text’ is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
as_text
|
bool
|
If True, returns the text content as a string. Defaults to False. |
False
|
no_header
|
bool
|
If True, converts ‘text:h’ elements to ‘text:p’. Defaults to True. |
True
|
clean
|
bool
|
If True, suppresses unwanted tags such as deletion marks. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
Element | list | str | None
|
Element | list | str | None: The content of the annotation, which |
Element | list | str | None
|
can be a single element, a list of elements, a string, or None if |
Element | list | str | None
|
the end tag is missing. |
Source code in odfdo/annotation.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
AnnotationEnd
Bases: MDTail, Element
End of annotation marker, “office:annotation-end”.
The “office:annotation-end” element is used to define the end of a text range that is being annotated, especially when the content spans across element boundaries. It must be preceded by an “office:annotation” element with the same ‘office:name’ attribute.
If an “office:annotation-end” element does not have a matching preceding “office:annotation” element, it is ignored.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the annotation this element is closing. This name must match the ‘office:name’ of a preceding “office:annotation” element. |
Methods:
| Name | Description |
|---|---|
__init__ |
Create an AnnotationEnd element. |
Source code in odfdo/annotation.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
_properties
class-attribute
instance-attribute
_properties = (PropDef('name', 'office:name'),)
_tag
class-attribute
instance-attribute
_tag = 'office:annotation-end'
end
property
end: AnnotationEnd
Return self.
name
instance-attribute
name = name
start
property
start: Annotation | None
Return the corresponding annotation starting tag or None.
__init__
__init__(
annotation: Annotation | None = None,
name: str | None = None,
**kwargs: Any,
) -> None
Create an AnnotationEnd element.
This element marks the end of an annotation. It must be associated with an existing “office:annotation” element, either by passing the annotation object directly or by providing a matching name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotation
|
Annotation | None
|
The “office:annotation” element that this “annotation-end” is closing. If provided, the ‘name’ attribute will be taken from this annotation. |
None
|
name
|
str | None
|
The name of the annotation to close. This is required if ‘annotation’ is not provided. |
None
|
Source code in odfdo/annotation.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
AnnotationMixin
Bases: Element
Mixin class for classes containing Annotations.
Used by the following classes
- “table:covered-table-cell”
- “table:table-cell”
- “text:a”
- “text:h”
- “text:meta”
- “text:meta-field”
- “text:p”
- “text:ruby-base”
- “text:span”
and “office:text”, “office:spreadsheet” for compatibility with previous versions.
Methods:
| Name | Description |
|---|---|
get_annotation |
Return the annotation that matches the criteria. |
get_annotation_end |
Return the annotation end that matches the criteria. |
get_annotation_ends |
Return all the annotation ends. |
get_annotations |
Return all the annotations that match the criteria. |
Source code in odfdo/annotation.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
get_annotation
get_annotation(
position: int = 0,
creator: str | None = None,
start_date: datetime | None = None,
end_date: datetime | None = None,
content: str | None = None,
name: str | None = None,
) -> Annotation | None
Return the annotation that matches the criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
int
|
The position of the annotation to return. |
0
|
creator
|
str | None
|
The creator of the annotation. |
None
|
start_date
|
datetime | None
|
The start date for filtering. |
None
|
end_date
|
datetime | None
|
The end date for filtering. |
None
|
content
|
str | None
|
A regex to match in the content. |
None
|
name
|
str | None
|
The name of the annotation. |
None
|
Returns:
| Type | Description |
|---|---|
Annotation | None
|
Annotation or None: The matching Annotation element, or None if not found. |
Source code in odfdo/annotation.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
get_annotation_end
get_annotation_end(
position: int = 0, name: str | None = None
) -> AnnotationEnd | None
Return the annotation end that matches the criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
int
|
The position of the annotation end to return. |
0
|
name
|
str | None
|
The name of the annotation end. |
None
|
Returns:
| Type | Description |
|---|---|
AnnotationEnd | None
|
AnnotationEnd or None: The matching AnnotationEnd element, or None if not found. |
Source code in odfdo/annotation.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
get_annotation_ends
get_annotation_ends() -> list[AnnotationEnd]
Return all the annotation ends.
Returns:
| Type | Description |
|---|---|
list[AnnotationEnd]
|
list[AnnotationEnd]: A list of AnnotationEnd elements. |
Source code in odfdo/annotation.py
141 142 143 144 145 146 147 148 149 150 151 152 | |
get_annotations
get_annotations(
creator: str | None = None,
start_date: datetime | None = None,
end_date: datetime | None = None,
content: str | None = None,
) -> list[Annotation]
Return all the annotations that match the criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
creator
|
str | None
|
The creator of the annotation. |
None
|
start_date
|
datetime | None
|
The start date for filtering. |
None
|
end_date
|
datetime | None
|
The end date for filtering. |
None
|
content
|
str | None
|
A regex to match in the content. |
None
|
Returns:
| Type | Description |
|---|---|
list[Annotation]
|
list[Annotation]: A list of matching Annotation elements. |
Source code in odfdo/annotation.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
get_unique_office_name
get_unique_office_name(
element: Element | None = None,
) -> str
Provide an autogenerated unique “office:name” for the document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Element | None
|
The element to which the annotation is related. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A unique name. |
Source code in odfdo/annotation.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |