Skip to content

Mixin Link

Mixin class for “text:a” tag.

Classes:

Name Description
LinkMixin

Mixin class for elements that can contain links.

LinkMixin

Bases: Element

Mixin class for elements that can contain links.

Used by the following classes
  • “text:h”
  • “text:meta”
  • “text:meta-field”
  • “text:p”
  • “text:ruby-base”
  • “text:span”

Also used for convenience by “office:text”, “office:spreadsheet”, “office:presentation”, “text:note-body”, “text:note”, “text:section”, “office:annotation”.

Methods:

Name Description
get_link

Returns a single link that matches the specified criteria.

get_links

Returns all links that match the specified criteria.

Source code in odfdo/mixin_link.py
 32
 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
100
101
class LinkMixin(Element):
    """Mixin class for elements that can contain links.

    Used by the following classes:
         - "text:h"
         - "text:meta"
         - "text:meta-field"
         - "text:p"
         - "text:ruby-base"
         - "text:span"

    Also used for convenience by "office:text", "office:spreadsheet",
    "office:presentation", "text:note-body", "text:note", "text:section",
    "office:annotation".
    """

    def get_links(
        self,
        name: str | None = None,
        title: str | None = None,
        url: str | None = None,
        content: str | None = None,
    ) -> list[Link]:
        """Returns all links that match the specified criteria.

        Args:
            name: The name of the link.
            title: The title of the link.
            url: A regex pattern to match against the link's URL.
            content: A regex pattern to match against the link's content.

        Returns:
            list[Link]: A list of Link instances matching the criteria.
        """
        return self._filtered_elements(
            "descendant::text:a",
            office_name=name,
            office_title=title,
            url=url,
            content=content,
        )  # type: ignore [return-value]

    def get_link(
        self,
        position: int = 0,
        name: str | None = None,
        title: str | None = None,
        url: str | None = None,
        content: str | None = None,
    ) -> Link | None:
        """Returns a single link that matches the specified criteria.

        Args:
            position: The 0-based index of the matching link to return.
            name: The name of the link.
            title: The title of the link.
            url: A regex pattern to match against the link's URL.
            content: A regex pattern to match against the link's content.

        Returns:
            Link | None: A Link instance, or None if no link matches the criteria.
        """
        return self._filtered_element(
            "descendant::text:a",
            position,
            office_name=name,
            office_title=title,
            url=url,
            content=content,
        )  # type: ignore [return-value]
get_link(
    position: int = 0,
    name: str | None = None,
    title: str | None = None,
    url: str | None = None,
    content: str | None = None,
) -> Link | None

Returns a single link that matches the specified criteria.

Parameters:

Name Type Description Default
position int

The 0-based index of the matching link to return.

0
name str | None

The name of the link.

None
title str | None

The title of the link.

None
url str | None

A regex pattern to match against the link’s URL.

None
content str | None

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

None

Returns:

Type Description
Link | None

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

Source code in odfdo/mixin_link.py
 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
def get_link(
    self,
    position: int = 0,
    name: str | None = None,
    title: str | None = None,
    url: str | None = None,
    content: str | None = None,
) -> Link | None:
    """Returns a single link that matches the specified criteria.

    Args:
        position: The 0-based index of the matching link to return.
        name: The name of the link.
        title: The title of the link.
        url: A regex pattern to match against the link's URL.
        content: A regex pattern to match against the link's content.

    Returns:
        Link | None: A Link instance, or None if no link matches the criteria.
    """
    return self._filtered_element(
        "descendant::text:a",
        position,
        office_name=name,
        office_title=title,
        url=url,
        content=content,
    )  # type: ignore [return-value]
get_links(
    name: str | None = None,
    title: str | None = None,
    url: str | None = None,
    content: str | None = None,
) -> list[Link]

Returns all links that match the specified criteria.

Parameters:

Name Type Description Default
name str | None

The name of the link.

None
title str | None

The title of the link.

None
url str | None

A regex pattern to match against the link’s URL.

None
content str | None

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

None

Returns:

Type Description
list[Link]

list[Link]: A list of Link instances matching the criteria.

Source code in odfdo/mixin_link.py
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
def get_links(
    self,
    name: str | None = None,
    title: str | None = None,
    url: str | None = None,
    content: str | None = None,
) -> list[Link]:
    """Returns all links that match the specified criteria.

    Args:
        name: The name of the link.
        title: The title of the link.
        url: A regex pattern to match against the link's URL.
        content: A regex pattern to match against the link's content.

    Returns:
        list[Link]: A list of Link instances matching the criteria.
    """
    return self._filtered_elements(
        "descendant::text:a",
        office_name=name,
        office_title=title,
        url=url,
        content=content,
    )  # type: ignore [return-value]