Mixin Paragraph
Mixin class for Paragraph methods.
Classes:
| Name | Description |
|---|---|
ParaMixin |
Mixin for Paragraph methods. |
_re_only_spaces
module-attribute
_re_only_spaces = compile('^ +$')
_re_spaces_split
module-attribute
_re_spaces_split = compile('( +)')
_re_splitter
module-attribute
_re_splitter = compile('(\\n|\\t)')
_re_sub_splitter
module-attribute
_re_sub_splitter = compile('[ \\t\\n]+')
ParaMixin
Bases: ReferenceMixin, BookmarkMixin, AnnotationMixin
Mixin for Paragraph methods.
Methods:
| Name | Description |
|---|---|
append |
Append a string or an element to the paragraph. |
append_plain_text |
Append plain text to the paragraph, converting special characters to ODF tags. |
insert_annotation |
Insert an annotation into the paragraph. |
insert_annotation_end |
Insert an annotation end tag for an existing annotation. |
insert_note |
Insert a note (footnote or endnote) into the paragraph. |
insert_reference |
Create and insert a reference to a content marked by a reference |
insert_variable |
Insert a variable element into the paragraph. |
remove_link |
Remove specific |
remove_links |
Remove all |
remove_span |
Remove specific |
remove_spans |
Remove all |
set_bookmark |
Insert a bookmark ( |
set_link |
Create a hyperlink from text content within the paragraph. |
set_reference_mark |
Insert a reference mark ( |
set_reference_mark_end |
Insert or move a |
set_span |
Apply a text style to content within the paragraph using a |
Source code in odfdo/mixin_paragraph.py
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 390 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 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 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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 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 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 | |
_expand_spaces
_expand_spaces(added_string: str) -> list[Element | str]
Expand spaces within the element’s content.
This function processes text and <text:s> (space) elements,
merging consecutive text nodes and converting <text:s> into strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
added_string
|
str
|
A string to append at the end of the expansion. |
required |
Returns:
| Type | Description |
|---|---|
list[Element | str]
|
list[Element | str]: A list of elements and strings with spaces expanded. |
Source code in odfdo/mixin_paragraph.py
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 | |
_merge_spaces
_merge_spaces(
content: list[Element | str],
) -> list[Element | str]
Merge multiple consecutive spaces into <text:s> elements where appropriate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
list[Element | str]
|
A list of elements and strings to process. |
required |
Returns:
| Type | Description |
|---|---|
list[Element | str]
|
list[Element | str]: A new list with consecutive spaces merged into |
Source code in odfdo/mixin_paragraph.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
_replace_tabs_lb
_replace_tabs_lb(
content: list[Element | str],
) -> list[Element | str]
Replace tab and line break characters within a list of content with ODF elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
list[Element | str]
|
A list of elements and strings to process. |
required |
Returns:
| Type | Description |
|---|---|
list[Element | str]
|
list[Element | str]: A new list with tabs and line breaks replaced by |
Source code in odfdo/mixin_paragraph.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
_sub_merge_spaces
staticmethod
_sub_merge_spaces(text: str) -> list[Element | str]
Internal helper to merge spaces within a string into Spacer elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The string to process. |
required |
Returns:
| Type | Description |
|---|---|
list[Element | str]
|
list[Element | str]: A list of elements and strings, with spaces
converted into |
Source code in odfdo/mixin_paragraph.py
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 | |
_sub_replace_tabs_lb
staticmethod
_sub_replace_tabs_lb(text: str) -> list[Element | str]
Internal helper to replace tab and line break characters in a string with ODF elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The string to process. |
required |
Returns:
| Type | Description |
|---|---|
list[Element | str]
|
list[Element | str]: A list of elements and strings, with tab and
line break characters replaced by |
Source code in odfdo/mixin_paragraph.py
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 | |
_unformatted
staticmethod
_unformatted(text: str | bytes | None) -> str
Remove extra whitespace and newlines, replacing them with single spaces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | bytes | None
|
The input text. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The unformatted text. |
Source code in odfdo/mixin_paragraph.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
append
append(
str_or_element: str | bytes | Element,
formatted: bool = True,
) -> None
Append a string or an element to the paragraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str_or_element
|
str | bytes | Element
|
The content to append. |
required |
formatted
|
bool
|
If True (default), special characters like newlines, tabs, and multiple spaces in strings are converted to their ODF tag equivalents. If False, the string content is inserted unformatted (only extra whitespace is removed). |
True
|
Source code in odfdo/mixin_paragraph.py
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 | |
append_plain_text
append_plain_text(text: str | bytes | None = '') -> None
Append plain text to the paragraph, converting special characters to ODF tags.
This method processes the input text, replacing carriage returns, tabs,
and multiple spaces with their corresponding ODF tags (<text:line-break>,
<text:tab>, <text:s>). Existing content of the paragraph is cleared.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | bytes | None
|
The plain text to append. |
''
|
Source code in odfdo/mixin_paragraph.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
insert_annotation
insert_annotation(
annotation_element: Annotation | None = None,
before: str | None = None,
after: str | Element | None = None,
position: int | tuple = 0,
content: str | Element | None = None,
body: str | None = None,
creator: str | None = None,
date: datetime | None = None,
) -> Annotation
Insert an annotation into the paragraph.
The insertion point can be defined by a regular expression (before, after, content)
or by positional arguments (position).
- If
contentis provided, the annotation will cover the entire content matching the regex. Ifcontentis anElement, the annotation will cover its full inner content. In this case,AnnotationStartandAnnotationEndtags are automatically inserted. - Otherwise, the annotation is positioned either
beforeoraftera regex match, or at a specificposition.
If before, after, or content are regular expressions that return multiple matches,
the position argument can be used to select which match to use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotation_element
|
Annotation | None
|
An optional pre-existing |
None
|
before
|
str | None
|
A regular expression. The annotation is inserted before text matching this regex. |
None
|
after
|
str | Element | None
|
A regular expression or an |
None
|
position
|
int | tuple
|
An integer for character offset, or a 2-tuple |
0
|
content
|
str | Element | None
|
A regular expression or an |
None
|
body
|
str | None
|
The content of the annotation. |
None
|
creator
|
str | None
|
The creator of the annotation. |
None
|
date
|
datetime | None
|
The creation date of the annotation. Defaults to current date if None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Annotation |
Annotation
|
The inserted annotation element. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid combination of arguments is provided. |
Source code in odfdo/mixin_paragraph.py
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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
insert_annotation_end
insert_annotation_end(
annotation_element: Annotation,
before: str | None = None,
after: str | None = None,
position: int = 0,
) -> AnnotationEnd
Insert an annotation end tag for an existing annotation.
If an end tag for the given annotation_element already exists, it is
replaced. The end tag is positioned based on a regex match (before or after)
or a numerical position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotation_element
|
Annotation
|
The |
required |
before
|
str | None
|
A regular expression. The end tag is inserted before text matching this regex. |
None
|
after
|
str | None
|
A regular expression. The end tag is inserted after text matching this regex. |
None
|
position
|
int
|
An integer character offset for insertion. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
AnnotationEnd |
AnnotationEnd
|
The inserted |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If |
Source code in odfdo/mixin_paragraph.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
insert_note
insert_note(
note_element: Note | None = None,
after: str | Element | None = None,
note_class: str = "footnote",
note_id: str | None = None,
citation: str | None = None,
body: str | None = None,
) -> None
Insert a note (footnote or endnote) into the paragraph.
A new Note element can be created using the provided parameters,
or an existing Note element can be inserted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note_element
|
Note | None
|
An existing |
None
|
after
|
str | Element | None
|
A regular expression (str) or an
|
None
|
note_class
|
str
|
The class of the note (“footnote” or “endnote”). |
'footnote'
|
note_id
|
str | None
|
A unique ID for the note. |
None
|
citation
|
str | None
|
The citation text for the note. |
None
|
body
|
str | None
|
The content of the note body. |
None
|
Source code in odfdo/mixin_paragraph.py
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 | |
insert_reference
insert_reference(
name: str,
ref_format: str = "",
before: str | None = None,
after: str | Element | None = None,
position: int = 0,
display: str | None = None,
) -> None
Create and insert a reference to a content marked by a reference mark. The 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 automatically updated except for the ‘text’ format.
name is mandatory and should represent an existing reference mark of the document.
ref_format is the argument for format reference (default is ‘page’).
The reference is inserted the position defined by the regex (before / after), or by positional argument (position). If ‘display’ is provided, it will be used as the text value for the reference.
If after is an ODF Element, the reference is inserted as first child of this element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the reference mark. |
required |
ref_format
|
str
|
The format for the reference, one of ‘chapter’, ‘direction’, ‘page’, ‘text’, ‘caption’, ‘category-and-value’, ‘value’, ‘number’, ‘number-all-superior’, ‘number-no-superior’. |
''
|
before
|
str | None
|
A regular expression before which to insert the reference. |
None
|
after
|
str | Element | None
|
A regular expression or an ODF element after which to insert the reference. |
None
|
position
|
int
|
The insertion position. |
0
|
display
|
str | None
|
The text value for the reference, if provided. |
None
|
Source code in odfdo/mixin_paragraph.py
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 | |
insert_variable
insert_variable(
variable_element: Element, after: str | None
) -> None
Insert a variable element into the paragraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_element
|
Element
|
The variable element to insert. |
required |
after
|
str | None
|
A regular expression after which to insert the variable. |
required |
Source code in odfdo/mixin_paragraph.py
792 793 794 795 796 797 798 799 | |
remove_link
remove_link(links: Link | list[Link]) -> Element
Remove specific text:a (hyperlink) elements from a copy of the paragraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
links
|
Link | list[Link]
|
The |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Element |
Element
|
A new |
Source code in odfdo/mixin_paragraph.py
900 901 902 903 904 905 906 907 908 909 910 | |
remove_links
remove_links() -> Element
Remove all text:a (hyperlink) elements from a copy of the paragraph.
Returns:
| Name | Type | Description |
|---|---|---|
Element |
Element
|
A new |
Source code in odfdo/mixin_paragraph.py
890 891 892 893 894 895 896 897 898 | |
remove_span
remove_span(spans: Element | list[Element]) -> Element
Remove specific text:span elements from a copy of the paragraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spans
|
Element | list[Element]
|
The |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Element |
Element
|
A new |
Source code in odfdo/mixin_paragraph.py
850 851 852 853 854 855 856 857 858 859 860 | |
remove_spans
remove_spans(keep_heading: bool = True) -> Element
Remove all text:span elements from a copy of the paragraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keep_heading
|
bool
|
If True, |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Element |
Element
|
A new |
Source code in odfdo/mixin_paragraph.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | |
set_bookmark
set_bookmark(
name: str,
before: str | None = None,
after: str | None = None,
position: int | tuple = 0,
role: str | None = None,
content: str | None = None,
) -> Element | tuple[Element, Element]
Insert a bookmark (Bookmark, BookmarkStart, or BookmarkEnd) into the paragraph.
The insertion point can be defined by a regular expression (before, after, content)
or by positional arguments (position).
- If
contentis provided, a pair ofBookmarkStartandBookmarkEndtags are automatically inserted to span the content. - If
positionis a 2-tuple(start, end),BookmarkStartandBookmarkEndtags are inserted at the specified offsets. - Otherwise, a single
Bookmark(ifroleis None),BookmarkStart(ifrole="start"), orBookmarkEnd(ifrole="end") is inserted based onbefore,after, orposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the bookmark. |
required |
before
|
str | None
|
A regular expression. The bookmark is inserted before text matching this regex. |
None
|
after
|
str | None
|
A regular expression. The bookmark is inserted after text matching this regex. |
None
|
position
|
int | tuple
|
An integer for a character offset, or a 2-tuple |
0
|
role
|
str | None
|
Specifies the type of bookmark to insert: “start”, “end”, or None for a regular bookmark. |
None
|
content
|
str | None
|
A regular expression. If provided, the bookmark spans the matching content. |
None
|
Returns:
| Type | Description |
|---|---|
Element | tuple[Element, Element]
|
Element | tuple[Element, Element]: The created bookmark element(s).
Returns a tuple |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid combination of arguments is provided. |
Source code in odfdo/mixin_paragraph.py
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 | |
set_link
set_link(
url: str,
regex: str | None = None,
offset: int | None = None,
length: int = 0,
**kwargs: Any,
) -> list[Link]
Create a hyperlink from text content within the paragraph.
The text content can be identified either by a regular expression (regex)
or by an offset and length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL that the hyperlink points to. |
required |
regex
|
str | None
|
A regular expression to match the text content. |
None
|
offset
|
int | None
|
The starting character offset in the paragraph’s text content. |
None
|
length
|
int
|
The length of the text content to convert into a link,
starting from |
0
|
Returns:
| Type | Description |
|---|---|
list[Link]
|
list[Link]: A list of generated |
Source code in odfdo/mixin_paragraph.py
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
set_reference_mark
set_reference_mark(
name: str,
before: str | None = None,
after: str | None = None,
position: int = 0,
content: str | Element | None = None,
) -> Element
Insert a reference mark (ReferenceMark, ReferenceMarkStart, or ReferenceMarkEnd) into the paragraph.
The insertion point can be defined by a regular expression (before, after, content)
or by positional arguments (position).
- If
contentis provided (regex orElement), a pair ofReferenceMarkStartandReferenceMarkEndtags are inserted to cover the specified content. - Otherwise, a single
ReferenceMarktag is positioned eitherbeforeoraftera regex match, or at a specificposition.
The name is mandatory and should be unique within the document for the reference mark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the reference mark. |
required |
before
|
str | None
|
A regular expression. The mark is inserted before text matching this regex. |
None
|
after
|
str | None
|
A regular expression. The mark is inserted after text matching this regex. |
None
|
position
|
int
|
An integer for character offset, or a 2-tuple |
0
|
content
|
str | Element | None
|
A regular expression or an |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Element |
Element
|
The created |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid combination of arguments is provided. |
Source code in odfdo/mixin_paragraph.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | |
set_reference_mark_end
set_reference_mark_end(
reference_mark: Element,
before: str | None = None,
after: str | None = None,
position: int = 0,
) -> ReferenceMarkEnd
Insert or move a ReferenceMarkEnd for an existing reference mark.
If an end tag for the given reference_mark already exists, it is
replaced. The end tag is positioned based on a regex match (before or after)
or a numerical position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_mark
|
Element
|
The |
required |
before
|
str | None
|
A regular expression. The end tag is inserted before text matching this regex. |
None
|
after
|
str | None
|
A regular expression. The end tag is inserted after text matching this regex. |
None
|
position
|
int
|
An integer character offset for insertion. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
ReferenceMarkEnd |
ReferenceMarkEnd
|
The inserted |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in odfdo/mixin_paragraph.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | |
set_span
set_span(
style: str,
regex: str | None = None,
offset: int | None = None,
length: int = 0,
**kwargs: Any,
) -> list[Span]
Apply a text style to content within the paragraph using a text:span element.
The target content can be specified either by a regular expression (regex)
or by an offset and length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style
|
str
|
The name of the text style to apply. |
required |
regex
|
str | None
|
A regular expression to match the text content. |
None
|
offset
|
int | None
|
The starting character offset in the paragraph’s text content. |
None
|
length
|
int
|
The length of the text content to apply the style to,
starting from |
0
|
Returns:
| Type | Description |
|---|---|
list[Span]
|
list[Span]: A list of generated |
Source code in odfdo/mixin_paragraph.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
_by_offset_wrapper
_by_offset_wrapper(
method: Callable,
element: Element,
offset: int,
*args: Any,
**kwargs: Any,
) -> list[Span | Link]
Helper for inserting elements by character offset.
This function wraps a method that creates a new element (like Span or Link)
and inserts it into the XML tree at a specific character offset within
the text content of the element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Callable
|
The function that creates the new element. |
required |
element
|
Element
|
The parent element whose text content is being modified. |
required |
offset
|
int
|
The character offset at which to perform the insertion. |
required |
*args
|
Any
|
Positional arguments to pass to the wrapped method. |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the wrapped method, including ‘length’ for the matched string length. |
{}
|
Returns:
| Type | Description |
|---|---|
list[Span | Link]
|
list[Span | Link]: A list of the newly created elements. |
Source code in odfdo/mixin_paragraph.py
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 | |
_by_regex_offset
_by_regex_offset(method: Callable) -> Callable
Decorator to enable element insertion by regex or offset.
This decorator wraps a method that creates a new element. The wrapped method
will then accept either a regex pattern or an offset and length to
specify where the new element should be inserted within the text content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Callable
|
The function that creates the new element. It will
receive |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
The decorated wrapper function. |
Source code in odfdo/mixin_paragraph.py
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 225 226 227 | |
_by_regex_wrapper
_by_regex_wrapper(
method: Callable,
element: Element,
regex: str,
*args: Any,
**kwargs: Any,
) -> list[Span | Link]
Helper for inserting elements by regular expression match.
This function wraps a method that creates a new element (like Span or Link)
and inserts it into the XML tree at positions matching a given regular
expression within the text content of the element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
Callable
|
The function that creates the new element. |
required |
element
|
Element
|
The parent element whose text content is being modified. |
required |
regex
|
str
|
The regular expression pattern to match. |
required |
*args
|
Any
|
Positional arguments to pass to the wrapped method. |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the wrapped method. |
{}
|
Returns:
| Type | Description |
|---|---|
list[Span | Link]
|
list[Span | Link]: A list of the newly created elements. |
Source code in odfdo/mixin_paragraph.py
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 | |