File: __init__.py

package info (click to toggle)
python-mkdocs 1.6.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,812 kB
  • sloc: python: 14,346; javascript: 10,535; perl: 143; sh: 57; makefile: 30; xml: 11
file content (36 lines) | stat: -rw-r--r-- 945 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import annotations

import abc
from typing import TYPE_CHECKING, Iterable

if TYPE_CHECKING:
    from mkdocs.structure.nav import Section


class StructureItem(metaclass=abc.ABCMeta):
    """An item in MkDocs structure - see concrete subclasses Section, Page or Link."""

    @abc.abstractmethod
    def __init__(self):
        ...

    parent: Section | None = None
    """The immediate parent of the item in the site navigation. `None` if it's at the top level."""

    @property
    def is_top_level(self) -> bool:
        return self.parent is None

    title: str | None
    is_section: bool = False
    is_page: bool = False
    is_link: bool = False

    @property
    def ancestors(self) -> Iterable[StructureItem]:
        if self.parent is None:
            return []
        return [self.parent, *self.parent.ancestors]

    def _indent_print(self, depth: int = 0) -> str:
        return ('    ' * depth) + repr(self)