Skip to content

Mixin Toc

Mixin class for elements that can contain table of content, “text:table-of-content”.

Classes:

Name Description
TocMixin

Mixin class for elements that can contain table of content.

TocMixin

Bases: Element

Mixin class for elements that can contain table of content.

This mixin provides methods to access and manipulate “text:table-of-content”.

Used by the following classes
  • “draw:text-box”
  • “office:text”
  • “style:footer”
  • “style:footer-first”
  • “style:footer-left”
  • “style:header”
  • “style:header-first”
  • “style:header-left”
  • “table:covered-table-cell”
  • “table:table-cell”
  • “text:deletion”
  • “text:index-body”
  • “text:index-title”
  • “text:note-body”
  • “text:section”

Methods:

Name Description
get_toc

Returns a single table of contents that matches the specified criteria.

get_tocs

Returns all tables of contents found within the element’s subtree.

Attributes:

Name Type Description
toc TOC | None

Returns the first table of contents found within the element’s subtree.

tocs list[TOC]

Returns all tables of contents found within the element’s subtree.

Source code in odfdo/mixin_toc.py
33
34
35
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
class TocMixin(Element):
    """Mixin class for elements that can contain table of content.

    This mixin provides methods to access and manipulate
    "text:table-of-content".

    Used by the following classes:
        - "draw:text-box"
        - "office:text"
        - "style:footer"
        - "style:footer-first"
        - "style:footer-left"
        - "style:header"
        - "style:header-first"
        - "style:header-left"
        - "table:covered-table-cell"
        - "table:table-cell"
        - "text:deletion"
        - "text:index-body"
        - "text:index-title"
        - "text:note-body"
        - "text:section"
    """

    def get_tocs(self) -> list[TOC]:
        """Returns all tables of contents found within the element's subtree.

        Returns:
            list[TOC]: A list of TOC instances.
        """
        return self.get_elements("text:table-of-content")  # type: ignore[return-value]

    @property
    def tocs(self) -> list[TOC]:
        """Returns all tables of contents found within the element's subtree.

        Returns:
            list[TOC]: A list of TOC instances.
        """
        return self.get_elements("text:table-of-content")  # type: ignore[return-value]

    def get_toc(
        self,
        position: int = 0,
        content: str | None = None,
    ) -> TOC | None:
        """Returns a single table of contents that matches the specified criteria.

        Args:
            position: The 0-based index of the matching table of contents to return.
            content: A regex pattern to match against the TOC's content.

        Returns:
            TOC | None: A TOC instance, or None if no TOC matches the criteria.
        """
        return self._filtered_element(
            "text:table-of-content", position, content=content
        )  # type: ignore[return-value]

    @property
    def toc(self) -> TOC | None:
        """Returns the first table of contents found within the element's subtree.

        Returns:
            The first TOC instance, or None if not found.
        """
        return self.get_toc()

toc property

toc: TOC | None

Returns the first table of contents found within the element’s subtree.

Returns:

Type Description
TOC | None

The first TOC instance, or None if not found.

tocs property

tocs: list[TOC]

Returns all tables of contents found within the element’s subtree.

Returns:

Type Description
list[TOC]

list[TOC]: A list of TOC instances.

get_toc

get_toc(
    position: int = 0, content: str | None = None
) -> TOC | None

Returns a single table of contents that matches the specified criteria.

Parameters:

Name Type Description Default
position int

The 0-based index of the matching table of contents to return.

0
content str | None

A regex pattern to match against the TOC’s content.

None

Returns:

Type Description
TOC | None

TOC | None: A TOC instance, or None if no TOC matches the criteria.

Source code in odfdo/mixin_toc.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def get_toc(
    self,
    position: int = 0,
    content: str | None = None,
) -> TOC | None:
    """Returns a single table of contents that matches the specified criteria.

    Args:
        position: The 0-based index of the matching table of contents to return.
        content: A regex pattern to match against the TOC's content.

    Returns:
        TOC | None: A TOC instance, or None if no TOC matches the criteria.
    """
    return self._filtered_element(
        "text:table-of-content", position, content=content
    )  # type: ignore[return-value]

get_tocs

get_tocs() -> list[TOC]

Returns all tables of contents found within the element’s subtree.

Returns:

Type Description
list[TOC]

list[TOC]: A list of TOC instances.

Source code in odfdo/mixin_toc.py
57
58
59
60
61
62
63
def get_tocs(self) -> list[TOC]:
    """Returns all tables of contents found within the element's subtree.

    Returns:
        list[TOC]: A list of TOC instances.
    """
    return self.get_elements("text:table-of-content")  # type: ignore[return-value]