Debian Codegraph @

mkdocs/structure/__init__.py

raw
1 from __future__ import annotations
2
3 import abc
4 from typing import TYPE_CHECKING, Iterable
5
6 if TYPE_CHECKING:
7 from mkdocs.structure.nav import Section
8
9
10 class StructureItem(metaclass=abc.ABCMeta):
11 """An item in MkDocs structure - see concrete subclasses Section, Page or Link."""
12
13 @abc.abstractmethod
14 def __init__(self):
15 ...
16
17 parent: Section | None = None
18 """The immediate parent of the item in the site navigation. `None` if it's at the top level."""
19
20 @property
21 def is_top_level(self) -> bool:
22 return self.parent is None
23
24 title: str | None
25 is_section: bool = False
26 is_page: bool = False
27 is_link: bool = False
28
29 @property
30 def ancestors(self) -> Iterable[StructureItem]:
31 if self.parent is None:
32 return []
33 return [self.parent, *self.parent.ancestors]
34
35 def _indent_print(self, depth: int = 0) -> str:
36 return (' ' * depth) + repr(self)