-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define a base class for all navigation item classes
- Loading branch information
Showing
4 changed files
with
59 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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=0): | ||
return (' ' * depth) + repr(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters