Reference
Reference related classes for “text:reference-…” tags.
Classes:
| Name | Description |
|---|---|
Reference |
A reference to a content marked by a reference mark, “text:reference- |
ReferenceMark |
A point reference, “text:reference-mark”. |
ReferenceMarkEnd |
End of a range reference, “text:reference-mark-end”. |
ReferenceMarkStart |
Start of a range reference, “text:reference-mark-start”. |
ReferenceMixin |
Mixin class for classes containing References. |
Functions:
| Name | Description |
|---|---|
remove_all_reference_marks |
Remove all reference mark tags from an element. |
remove_reference_mark |
Remove a specific reference mark from an element by name or position. |
strip_references |
Remove all |
Reference
Bases: Element
A reference to a content marked by a reference mark, “text:reference- ref”.”.
The odf_reference element (“text:reference-ref”) represents a field that references a “text:reference-mark-start” or “text:reference-mark” element. Its text:reference-format attribute specifies what is displayed from the referenced element. Default is ‘page’ Actual content is not updated except for the ‘text’ format by the update() method.
Creation of references can be tricky, consider using this method: odfdo.paragraph.insert_reference()
Values for text:reference-format : The defined values for the text:reference-format attribute supported by all reference fields are: - ‘chapter’: displays the number of the chapter in which the referenced item appears. - ‘direction’: displays whether the referenced item is above or below the reference field. - ‘page’: displays the number of the page on which the referenced item appears. - ‘text’: displays the text of the referenced item. Additional defined values for the text:reference-format attribute supported by references to sequence fields are: - ‘caption’: displays the caption in which the sequence is used. - ‘category-and-value’: displays the name and value of the sequence. - ‘value’: displays the value of the sequence.
References to bookmarks and other references support additional values,
which display the list label of the referenced item. If the referenced
item is contained in a list or a numbered paragraph, the list label is
the formatted number of the paragraph which contains the referenced
item. If the referenced item is not contained in a list or numbered
paragraph, the list label is empty, and the referenced field therefore
displays nothing. If the referenced bookmark or reference contains more
than one paragraph, the list label of the paragraph at which the
bookmark or reference starts is taken.
Additional defined values for the text:reference-format attribute
supported by all references to bookmark's or other reference fields
are:
- 'number': displays the list label of the referenced item. [...]
- 'number-all-superior': displays the list label of the referenced
item and adds the contents of all list labels of superior levels
in front of it. [...]
- 'number-no-superior': displays the contents of the list label of
the referenced item.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a Reference element ( |
update |
Update the content of the reference text field. |
Attributes:
| Name | Type | Description |
|---|---|---|
FORMAT_ALLOWED |
|
|
name |
|
|
ref_format |
str | None
|
Get the |
Source code in odfdo/reference.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 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 | |
FORMAT_ALLOWED
class-attribute
instance-attribute
FORMAT_ALLOWED = (
"chapter",
"direction",
"page",
"text",
"caption",
"category-and-value",
"value",
"number",
"number-all-superior",
"number-no-superior",
)
_properties
class-attribute
instance-attribute
_properties = (PropDef('name', 'text:ref-name'),)
_tag
class-attribute
instance-attribute
_tag = 'text:reference-ref'
name
instance-attribute
name = name
ref_format
property
writable
ref_format: str | None
Get the text:reference-format of the reference.
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The reference format string. |
__init__
__init__(
name: str = "", ref_format: str = "", **kwargs: Any
) -> None
Initialize a Reference element (text:reference-ref).
A Reference represents a field that refers to a ReferenceMark
or ReferenceMarkStart. An existing reference mark with the provided
name is expected.
Consider using the odfdo.paragraph.insert_reference() method for easier creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the reference mark to refer to. |
''
|
ref_format
|
str
|
The format of the reference field, which determines what is displayed (e.g., “page”, “chapter”, “text”). Defaults to “page”. |
''
|
**kwargs
|
Any
|
Additional keyword arguments for the parent |
{}
|
Source code in odfdo/reference.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
update
update() -> None
Update the content of the reference text field.
Currently only ‘text’ format is implemented. Other values, for example the ‘page’ text field, may need to be refreshed through a visual ODF parser.
Source code in odfdo/reference.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
ReferenceMark
Bases: Element
A point reference, “text:reference-mark”.
A point reference marks a position in text and is represented by a single “text:reference-mark” element.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a ReferenceMark element. |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
|
Source code in odfdo/reference.py
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 | |
_properties
class-attribute
instance-attribute
_properties = (PropDef('name', 'text:name'),)
_tag
class-attribute
instance-attribute
_tag = 'text:reference-mark'
name
instance-attribute
name = name
__init__
__init__(name: str = '', **kwargs: Any) -> None
Initialize a ReferenceMark element.
A point reference marks a position in text and is represented by
a single text:reference-mark element.
Consider using the odfdo.paragraph.set_reference_mark() method
for easier creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the reference mark. |
''
|
**kwargs
|
Any
|
Additional keyword arguments for the parent |
{}
|
Source code in odfdo/reference.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
ReferenceMarkEnd
Bases: Element
End of a range reference, “text:reference-mark-end”.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a ReferenceMarkEnd element. |
referenced_text |
Return the text between reference-mark-start and reference-mark- |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
|
Source code in odfdo/reference.py
391 392 393 394 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 | |
_properties
class-attribute
instance-attribute
_properties = (PropDef('name', 'text:name'),)
_tag
class-attribute
instance-attribute
_tag = 'text:reference-mark-end'
name
instance-attribute
name = name
__init__
__init__(name: str = '', **kwargs: Any) -> None
Initialize a ReferenceMarkEnd element.
Represents the end of a range reference. It’s recommended to use the
helper methods odfdo.paragraph.set_reference_mark() or
odfdo.paragraph.set_reference_mark_end() for creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the reference mark this element ends. |
''
|
**kwargs
|
Any
|
Additional keyword arguments for the parent |
{}
|
Source code in odfdo/reference.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
referenced_text
referenced_text() -> str
Return the text between reference-mark-start and reference-mark- end.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The referenced text. |
Source code in odfdo/reference.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
ReferenceMarkStart
Bases: Element
Start of a range reference, “text:reference-mark-start”.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a ReferenceMarkStart element. |
delete |
Delete the element from the XML tree. |
get_referenced |
Get the content between the start and end tags of the reference mark. |
referenced_text |
Return the text between reference-mark-start and reference-mark- |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
|
Source code in odfdo/reference.py
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 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
_properties
class-attribute
instance-attribute
_properties = (PropDef('name', 'text:name'),)
_tag
class-attribute
instance-attribute
_tag = 'text:reference-mark-start'
name
instance-attribute
name = name
__init__
__init__(name: str = '', **kwargs: Any) -> None
Initialize a ReferenceMarkStart element.
Represents the start of a range reference. It’s recommended to use the
helper method odfdo.paragraph.set_reference_mark() for creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the reference mark this element starts. |
''
|
**kwargs
|
Any
|
Additional keyword arguments for the parent |
{}
|
Source code in odfdo/reference.py
438 439 440 441 442 443 444 445 446 447 448 449 450 | |
delete
delete(
child: Element | None = None, keep_tail: bool = True
) -> None
Delete the element from the XML tree.
If child is provided, it deletes a child element. If no child is
given, “self” is deleted, along with its corresponding ReferenceMarkEnd
tag if it exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
child
|
Element | None
|
The child element to delete. If |
None
|
keep_tail
|
bool
|
If True, the |
True
|
Source code in odfdo/reference.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
get_referenced
get_referenced(
no_header: bool = False,
clean: bool = True,
as_xml: bool = False,
as_list: bool = False,
) -> Element | list | str | None
Get the content between the start and end tags of the reference mark.
This method can return the content in various formats (as a single Element,
a list of Elements, or an XML string).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
no_header
|
bool
|
If True, converts |
False
|
clean
|
bool
|
If True, removes unwanted tags like tracked changes marks. |
True
|
as_xml
|
bool
|
If True, returns the content as a serialized XML string. |
False
|
as_list
|
bool
|
If True, returns the content as a list of |
False
|
Returns:
| Type | Description |
|---|---|
Element | list | str | None
|
Element | list | str | None: The referenced content in the specified format. |
Source code in odfdo/reference.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
referenced_text
referenced_text() -> str
Return the text between reference-mark-start and reference-mark- end.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The referenced text. |
Source code in odfdo/reference.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
ReferenceMixin
Bases: Element
Mixin class for classes containing References.
Used by the following classes: “text:a”, “text:h”, “text:meta”, “text:meta-field”, “text:p”, “text:ruby-base”, “text:span”. And with “office:text” for compatibility with previous versions.
Methods:
| Name | Description |
|---|---|
get_reference_mark |
Get a specific reference mark by name or position. |
get_reference_mark_end |
Get a specific reference mark end tag ( |
get_reference_mark_ends |
Get all reference mark end tags ( |
get_reference_mark_single |
Get a specific single-point reference mark ( |
get_reference_mark_start |
Get a specific reference mark start tag ( |
get_reference_mark_starts |
Get all reference mark start tags ( |
get_reference_marks |
Get all reference marks. |
get_reference_marks_single |
Get all single-point reference marks ( |
get_references |
Get all reference fields ( |
Source code in odfdo/reference.py
36 37 38 39 40 41 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 175 176 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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
get_reference_mark
get_reference_mark(
position: int = 0, name: str | None = None
) -> ReferenceMark | ReferenceMarkStart | None
Get a specific reference mark by name or position.
This can be either a single-point mark (text:reference-mark) or the
start of a ranged mark (text:reference-mark-start).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
int
|
The index of the mark to retrieve if |
0
|
name
|
str | None
|
The name of the reference mark. |
None
|
Returns:
| Type | Description |
|---|---|
ReferenceMark | ReferenceMarkStart | None
|
ReferenceMark | ReferenceMarkStart | None: The found reference mark element,
or |
Source code in odfdo/reference.py
175 176 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 205 206 207 208 209 | |
get_reference_mark_end
get_reference_mark_end(
position: int = 0, name: str | None = None
) -> ReferenceMarkEnd | None
Get a specific reference mark end tag (text:reference-mark-end).
It is recommended to use get_reference_mark() for a more comprehensive search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
int
|
The index of the mark to retrieve. Defaults to 0. |
0
|
name
|
str | None
|
The name of the reference mark. |
None
|
Returns:
| Type | Description |
|---|---|
ReferenceMarkEnd | None
|
ReferenceMarkEnd | None: The |
Source code in odfdo/reference.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
get_reference_mark_ends
get_reference_mark_ends() -> list[ReferenceMarkEnd]
Get all reference mark end tags (text:reference-mark-end).
It is recommended to use get_reference_marks() for a more comprehensive search.
Returns:
| Type | Description |
|---|---|
list[ReferenceMarkEnd]
|
list[ReferenceMarkEnd]: A list of |
Source code in odfdo/reference.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
get_reference_mark_single
get_reference_mark_single(
position: int = 0, name: str | None = None
) -> ReferenceMark | None
Get a specific single-point reference mark (text:reference-mark).
It is recommended to use get_reference_mark() for a more comprehensive search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
int
|
The index of the mark to retrieve. Defaults to 0. |
0
|
name
|
str | None
|
The name of the reference mark. |
None
|
Returns:
| Type | Description |
|---|---|
ReferenceMark | None
|
ReferenceMark | None: The |
Source code in odfdo/reference.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
get_reference_mark_start
get_reference_mark_start(
position: int = 0, name: str | None = None
) -> ReferenceMarkStart | None
Get a specific reference mark start tag (text:reference-mark-start).
It is recommended to use get_reference_mark() for a more comprehensive search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
int
|
The index of the mark to retrieve. Defaults to 0. |
0
|
name
|
str | None
|
The name of the reference mark. |
None
|
Returns:
| Type | Description |
|---|---|
ReferenceMarkStart | None
|
ReferenceMarkStart | None: The |
Source code in odfdo/reference.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
get_reference_mark_starts
get_reference_mark_starts() -> list[ReferenceMarkStart]
Get all reference mark start tags (text:reference-mark-start).
It is recommended to use get_reference_marks() for a more comprehensive search.
Returns:
| Type | Description |
|---|---|
list[ReferenceMarkStart]
|
list[ReferenceMarkStart]: A list of |
Source code in odfdo/reference.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
get_reference_marks
get_reference_marks() -> list[
ReferenceMark | ReferenceMarkStart
]
Get all reference marks.
This includes both single-point marks (text:reference-mark) and the
start of ranged marks (text:reference-mark-start).
Returns:
| Type | Description |
|---|---|
list[ReferenceMark | ReferenceMarkStart]
|
list[ReferenceMark | ReferenceMarkStart]: A list of |
Source code in odfdo/reference.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
get_reference_marks_single
get_reference_marks_single() -> list[ReferenceMark]
Get all single-point reference marks (text:reference-mark).
It is recommended to use get_reference_marks() for a more comprehensive search.
Returns:
| Type | Description |
|---|---|
list[ReferenceMark]
|
A list of |
Source code in odfdo/reference.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
get_references
get_references(name: str | None = None) -> list[Reference]
Get all reference fields (text:reference-ref).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
If provided, filter references by their |
None
|
Returns:
| Type | Description |
|---|---|
list[Reference]
|
list[Reference]: A list of |
Source code in odfdo/reference.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
remove_all_reference_marks
remove_all_reference_marks(
element: Element,
) -> Element | list
Remove all reference mark tags from an element.
This includes text:reference-mark, text:reference-mark-start, and
text:reference-mark-end. The inner content of the tags is preserved.
Note: Using the .delete() method on a reference mark directly will
also delete its inner content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Element
|
The element from which to remove reference marks. |
required |
Returns:
| Type | Description |
|---|---|
Element | list
|
Element | list: The element with reference marks removed, or a list of elements if the top-level element itself is stripped. |
Source code in odfdo/reference.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | |
remove_reference_mark
remove_reference_mark(
element: Element,
position: int = 0,
name: str | None = None,
) -> None
Remove a specific reference mark from an element by name or position.
This removes text:reference-mark, text:reference-mark-start, and
text:reference-mark-end tags, while keeping their inner content.
Note: Using the .delete() method on a reference mark directly will
also delete its inner content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Element
|
The element from which to remove the reference mark. |
required |
position
|
int
|
The index of the mark to remove if |
0
|
name
|
str | None
|
The name of the reference mark to remove. |
None
|
Source code in odfdo/reference.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
strip_references
strip_references(element: Element) -> Element | list
Remove all text:reference-ref tags from an element.
This function keeps the inner content of the stripped tags.
Note: Using the .delete() method on a reference mark directly will
also delete its inner content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Element
|
The element from which to strip reference tags. |
required |
Returns:
| Type | Description |
|---|---|
Element | list
|
Element | list: The element with reference tags removed, or a list of elements if the top-level element itself is stripped. |
Source code in odfdo/reference.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |