MkClassPage
An MkClassPage is an MkPage subclass used to display information about a specific class. It uses a Jinja template to display the class-related information. By default, the Docstrings, tables for sub and parent classes as well as an inheritance graph are shown. The template can be adjusted manually in case a different layout is preferred.
Bases: MkTemplatePage
Page showing information about a class.
obj_path
property
¶
Dotted path used for the mkdocstrings ::: directive.
The path of the defining module (or module_path if given). If griffe can only
resolve the class via another module (e.g. classes of collections.abc, which
are defined in _collections_abc), that path is used.
path
property
writable
¶
Return the last part of the page path.
An explicitly set path is used as-is (case preserved, ClassName.md),
otherwise the slugified title.
__init__
¶
__init__(
klass: type,
*,
title: str | None = None,
module_path: tuple[str, ...] | str | None = None,
template_path: str | None = None,
**kwargs: Any
) -> None
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
klass
|
type
|
class to show info for |
required |
title
|
str | None
|
Optional title override. Defaults to class name |
None
|
module_path
|
tuple[str, ...] | str | None
|
If given, overrides module returned by class.module This can be useful if you want to link to an aliased class (for example a class imported to init.py) |
None
|
template_path
|
str | None
|
Name of the template to load |
None
|
kwargs
|
Any
|
keyword arguments passed to base class |
{}
|
This is an example for an MkClassPage with the default layout:
created: source_filename: /home/runner/work/mknodes/mknodes/docs/pages/mkclasspage.jinja source_function: root source_line_no: 27 inclusion_level: false title: MkCode
Sub classes¶
| Name | Children | Inherits |
|---|---|---|
| MkDiagram mknodes.basenodes.mkdiagram Class representing a mermaid diagram. |
||
| MkTreeView mknodes.templatenodes.mktreeview Node to display tree structures. |
Base classes¶
| Name | Children | Inherits |
|---|---|---|
| MkContainer mknodes.basenodes.mkcontainer A node containing other MkNodes. |
⋔ Inheritance diagram¶
graph TD
1761293797["mkcode.MkCode"]
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
835538629 --> 1761293797
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
🛈 DocStrings¶
Bases: MkContainer
Class representing a Code block.
fence_boundary
property
¶
Return fence boundary, based on nesting level. Default is ```.
__init__
¶
__init__(
content: str | MkNode | list[MkNode] = "",
*,
language: str = "python",
title: str = "",
linenums: int | None = None,
highlight_lines: list[int] | None = None,
fence_level: int | None = None,
**kwargs: Any
) -> None
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str | MkNode | list[MkNode]
|
Content to show inside code box |
''
|
language
|
str
|
language for syntax highlighting |
'python'
|
title
|
str
|
Code block title |
''
|
linenums
|
int | None
|
If set, use as start linenumber |
None
|
highlight_lines
|
list[int] | None
|
Optionally highlight lines |
None
|
fence_level
|
int | None
|
Determines amount of ticks used for fence. If None, auto-determine based on nesting depth. |
None
|
kwargs
|
Any
|
Keyword arguments passed to parent |
{}
|
fence_for
¶
Return the fence for given code: longer than any fence inside the code.
for_file
classmethod
¶
for_file(
path: JoinablePathLike,
*,
linenums: bool = True,
highlight_caller: bool = True,
title: str | None = None,
language: str | None = None,
**kwargs: Any
) -> Self
Create a MkCode node based on a code file.
Line numbers will be shown by default. If highlight_caller is True,
it will try to detect whether the calling method is inside the code block are
creating and if yes, it will highlight that line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
JoinablePathLike
|
Path to the code file (also supports fsspec-protocol URLs) |
required |
linenums
|
bool
|
Whether to show line numbers |
True
|
highlight_caller
|
bool
|
Whether we want to try to highlight the line which called this method. |
True
|
title
|
str | None
|
title to use for the code box. If None is set, filename will be used. |
None
|
language
|
str | None
|
Syntax highlighting language. If None, try to infer from extension. |
None
|
kwargs
|
Any
|
Keyword arguments passed to MkCode ctor |
{}
|
for_object
classmethod
¶
for_object(
obj: HasCodeType,
*,
dedent: bool = True,
extract_body: bool = False,
title: str | None = None,
linenums: bool = True,
highlight_caller: bool = True,
**kwargs: Any
) -> Self
Create a MkCode node based on a python object.
Fetches code by using the inspect module. Line numbers will be shown by default. If highlight_caller is True, it will try to detect whether the calling method is inside the code block are displaying and if yes, it will highlight that line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
HasCodeType
|
Python object to show code from |
required |
dedent
|
bool
|
Whether to dedent the code |
True
|
extract_body
|
bool
|
if True, Function / Class signatures are stripped from the code |
False
|
title
|
str | None
|
Title to use for code block. If None, it will use the object path. |
None
|
linenums
|
bool
|
Whether to show line numbers |
True
|
highlight_caller
|
bool
|
Whether we want to try to highlight the line which called this method. |
True
|
kwargs
|
Any
|
Keyword arguments passed to MkCode ctor |
{}
|
And this is an alternate tabbed layout:
created: source_filename: /home/runner/work/mknodes/mknodes/docs/pages/mkclasspage.jinja source_function: root source_line_no: 29 inclusion_level: false title: MkCode
Bases: MkContainer
Class representing a Code block.
fence_boundary
property
¶
Return fence boundary, based on nesting level. Default is ```.
__init__
¶
__init__(
content: str | MkNode | list[MkNode] = "",
*,
language: str = "python",
title: str = "",
linenums: int | None = None,
highlight_lines: list[int] | None = None,
fence_level: int | None = None,
**kwargs: Any
) -> None
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str | MkNode | list[MkNode]
|
Content to show inside code box |
''
|
language
|
str
|
language for syntax highlighting |
'python'
|
title
|
str
|
Code block title |
''
|
linenums
|
int | None
|
If set, use as start linenumber |
None
|
highlight_lines
|
list[int] | None
|
Optionally highlight lines |
None
|
fence_level
|
int | None
|
Determines amount of ticks used for fence. If None, auto-determine based on nesting depth. |
None
|
kwargs
|
Any
|
Keyword arguments passed to parent |
{}
|
fence_for
¶
Return the fence for given code: longer than any fence inside the code.
for_file
classmethod
¶
for_file(
path: JoinablePathLike,
*,
linenums: bool = True,
highlight_caller: bool = True,
title: str | None = None,
language: str | None = None,
**kwargs: Any
) -> Self
Create a MkCode node based on a code file.
Line numbers will be shown by default. If highlight_caller is True,
it will try to detect whether the calling method is inside the code block are
creating and if yes, it will highlight that line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
JoinablePathLike
|
Path to the code file (also supports fsspec-protocol URLs) |
required |
linenums
|
bool
|
Whether to show line numbers |
True
|
highlight_caller
|
bool
|
Whether we want to try to highlight the line which called this method. |
True
|
title
|
str | None
|
title to use for the code box. If None is set, filename will be used. |
None
|
language
|
str | None
|
Syntax highlighting language. If None, try to infer from extension. |
None
|
kwargs
|
Any
|
Keyword arguments passed to MkCode ctor |
{}
|
for_object
classmethod
¶
for_object(
obj: HasCodeType,
*,
dedent: bool = True,
extract_body: bool = False,
title: str | None = None,
linenums: bool = True,
highlight_caller: bool = True,
**kwargs: Any
) -> Self
Create a MkCode node based on a python object.
Fetches code by using the inspect module. Line numbers will be shown by default. If highlight_caller is True, it will try to detect whether the calling method is inside the code block are displaying and if yes, it will highlight that line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
HasCodeType
|
Python object to show code from |
required |
dedent
|
bool
|
Whether to dedent the code |
True
|
extract_body
|
bool
|
if True, Function / Class signatures are stripped from the code |
False
|
title
|
str | None
|
Title to use for code block. If None, it will use the object path. |
None
|
linenums
|
bool
|
Whether to show line numbers |
True
|
highlight_caller
|
bool
|
Whether we want to try to highlight the line which called this method. |
True
|
kwargs
|
Any
|
Keyword arguments passed to MkCode ctor |
{}
|
| Name | Children | Inherits |
|---|---|---|
| MkDiagram mknodes.basenodes.mkdiagram Class representing a mermaid diagram. |
||
| MkTreeView mknodes.templatenodes.mktreeview Node to display tree structures. |
| Name | Children | Inherits |
|---|---|---|
| MkContainer mknodes.basenodes.mkcontainer A node containing other MkNodes. |
graph TD
1761293797["mkcode.MkCode"]
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
835538629 --> 1761293797
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199