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.
class MkClassPage(mktemplatepage.MkTemplatePage)
Page showing information about a class.
This is an example for an MkClassPage with the default layout:
MkCode¶
Sub classes¶
Name |
Children |
Inherits |
|---|---|---|
MkDiagram |
||
MkTreeView |
Base classes¶
Name |
Children |
Inherits |
|---|---|---|
MkContainer |
⋔ 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¶
class MkCode(mkcontainer.MkContainer)
Class representing a Code block.
fence_boundary¶
fence_boundary: str
Return fence boundary, based on nesting level. Default is ```.
fence_title¶
fence_title: str
Title in first line.
__init__¶
def __init__(content: str | mk.MkNode | list[mk.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 to show inside code box |
‘’ |
|
|
language for syntax highlighting |
‘python’ |
|
|
Code block title |
‘’ |
|
|
If set, use as start linenumber |
None |
|
|
Optionally highlight lines |
None |
|
|
Determines amount of ticks used for fence. |
None |
|
|
Keyword arguments passed to parent |
{} |
fence_for¶
def fence_for(text: str) -> str
Return the fence for given code: longer than any fence inside the code.
for_file¶
def 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 to the code file (also supports fsspec-protocol URLs) |
|
|
|
Whether to show line numbers |
True |
|
|
Whether we want to try to highlight the line which called |
True |
|
|
title to use for the code box. If None is set, filename will be used. |
None |
|
|
Syntax highlighting language. If None, try to infer from extension. |
None |
|
|
Keyword arguments passed to MkCode ctor |
{} |
for_object¶
def for_object(obj: datatypes.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 |
|---|---|---|---|
|
|
Python object to show code from |
|
|
|
Whether to dedent the code |
True |
|
|
if True, Function / Class signatures are stripped from the code |
False |
|
|
Title to use for code block. If None, it will use the object path. |
None |
|
|
Whether to show line numbers |
True |
|
|
Whether we want to try to highlight the line which called |
True |
|
|
Keyword arguments passed to MkCode ctor |
{} |
get_content¶
def get_content() -> resources.NodeContent
Single-pass: get code block markdown and resources.
get_text¶
def get_text() -> str
Text content.
And this is an alternate tabbed layout:
MkCode¶
class MkCode(mkcontainer.MkContainer)
Class representing a Code block.
fence_boundary: str
Return fence boundary, based on nesting level. Default is ```.
fence_title: str
Title in first line.
def __init__(content: str | mk.MkNode | list[mk.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 to show inside code box |
‘’ |
|
|
language for syntax highlighting |
‘python’ |
|
|
Code block title |
‘’ |
|
|
If set, use as start linenumber |
None |
|
|
Optionally highlight lines |
None |
|
|
Determines amount of ticks used for fence. |
None |
|
|
Keyword arguments passed to parent |
{} |
def fence_for(text: str) -> str
Return the fence for given code: longer than any fence inside the code.
def 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 to the code file (also supports fsspec-protocol URLs) |
|
|
|
Whether to show line numbers |
True |
|
|
Whether we want to try to highlight the line which called |
True |
|
|
title to use for the code box. If None is set, filename will be used. |
None |
|
|
Syntax highlighting language. If None, try to infer from extension. |
None |
|
|
Keyword arguments passed to MkCode ctor |
{} |
def for_object(obj: datatypes.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 |
|---|---|---|---|
|
|
Python object to show code from |
|
|
|
Whether to dedent the code |
True |
|
|
if True, Function / Class signatures are stripped from the code |
False |
|
|
Title to use for code block. If None, it will use the object path. |
None |
|
|
Whether to show line numbers |
True |
|
|
Whether we want to try to highlight the line which called |
True |
|
|
Keyword arguments passed to MkCode ctor |
{} |
def get_content() -> resources.NodeContent
Single-pass: get code block markdown and resources.
def get_text() -> str
Text content.
Name |
Children |
Inherits |
|---|---|---|
MkDiagram |
||
MkTreeView |
Name |
Children |
Inherits |
|---|---|---|
MkContainer |
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
Page info
Code for this page
15@nav.route.page("MkClassPage")
16def _(page: mk.MkPage) -> None:
17 variables = dict(example_class=mk.MkCode)
18 page += mk.MkTemplate("pages/mkclasspage.jinja", variables=variables)
Resources
Resources(css=[],
markdown_extensions={'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
'format': <function fence_code_format at 0x7ff77e88b060>,
'name': 'mermaid'}]},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/page_section.py
source_function: _
source_line_no: 15
title: MkClassPage