Skip to content

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.

This is an example for an MkClassPage with the default layout:


created: source_filename: /home/runner/work/mknodes/mknodes/mknodes/pages/mkclasspage/init.py source_function: MkClassPage.init source_line_no: 46 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
      94854582908560["mkcode.MkCode"]
      94854582919984["mkcontainer.MkContainer"]
      94854582916880["mknode.MkNode"]
      94854582838576["node.Node"]
      140544995341632["builtins.object"]
      94854582919984 --> 94854582908560
      94854582916880 --> 94854582919984
      94854582838576 --> 94854582916880
      140544995341632 --> 94854582838576

    🛈 DocStrings

    Bases: MkContainer

    Class representing a Code block.

    fence_boundary property

    fence_boundary: str
    

    Return fence boundary, based on nesting level. Default is ```.

    fence_title property

    fence_title: str
    

    Title in first line.

    text property

    text: str
    

    Text content.

    __init__

    __init__(
        content: str | mk.MkNode | list = "",
        *,
        language: str = "python",
        title: str = "",
        linenums: int | None = None,
        highlight_lines: list[int] | None = None,
        fence_level: int | None = None,
        **kwargs: Any
    )
    

    Constructor.

    Parameters:

    Name Type Description Default
    content str | MkNode | list

    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

    {}

    for_file classmethod

    for_file(
        path: str | os.PathLike,
        *,
        linenums: bool = True,
        highlight_caller: bool = True,
        title: str | None = None,
        language: str | None = None,
        **kwargs: Any
    )
    

    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 str | PathLike

    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: 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
    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

    {}

    Show source on GitHub

    And this is an alternate tabbed layout:


    created: source_filename: /home/runner/work/mknodes/mknodes/mknodes/pages/mkclasspage/init.py source_function: MkClassPage.init source_line_no: 46 inclusion_level: false title: MkCode


    Bases: MkContainer

    Class representing a Code block.

    fence_boundary property

    fence_boundary: str
    

    Return fence boundary, based on nesting level. Default is ```.

    fence_title property

    fence_title: str
    

    Title in first line.

    text property

    text: str
    

    Text content.

    __init__

    __init__(
        content: str | mk.MkNode | list = "",
        *,
        language: str = "python",
        title: str = "",
        linenums: int | None = None,
        highlight_lines: list[int] | None = None,
        fence_level: int | None = None,
        **kwargs: Any
    )
    

    Constructor.

    Parameters:

    Name Type Description Default
    content str | MkNode | list

    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

    {}

    for_file classmethod

    for_file(
        path: str | os.PathLike,
        *,
        linenums: bool = True,
        highlight_caller: bool = True,
        title: str | None = None,
        language: str | None = None,
        **kwargs: Any
    )
    

    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 str | PathLike

    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: 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
    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
        94854582908560["mkcode.MkCode"]
        94854582919984["mkcontainer.MkContainer"]
        94854582916880["mknode.MkNode"]
        94854582838576["node.Node"]
        140544995341632["builtins.object"]
        94854582919984 --> 94854582908560
        94854582916880 --> 94854582919984
        94854582838576 --> 94854582916880
        140544995341632 --> 94854582838576

      Show source on GitHub

      Page info
      Code for this page
      mknodes.manual.page_section._
      @nav.route.page("MkClassPage")
      def _(page: mk.MkPage):
          variables = dict(example_class=mk.MkCode)
          page += mk.MkTemplate("pages/mkclasspage.jinja", variables=variables)
      
      Resources
      Resources(css=[],
                markdown_extensions={'attr_list': {},
                                     'md_in_html': {},
                                     'pymdownx.emoji': {'emoji_generator': <function to_svg at 0x7fd32a7ad800>,
                                                        'emoji_index': <function twemoji at 0x7fd32a7ad6c0>},
                                     'pymdownx.magiclink': {'repo': 'mknodes',
                                                            'repo_url_shorthand': True,
                                                            'user': 'phil65'},
                                     'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
                                                                                 'format': <function fence_code_format at 0x7fd3291289a0>,
                                                                                 'name': 'mermaid'}]},
                                     'tables': {}},
                plugins=[Plugin('mkdocstrings')],
                js=[],
                assets=[],
                packages=[])
      
      Metadata
      created:
        source_filename: /home/runner/work/mknodes/mknodes/mknodes/manual/page_section.py
        source_function: null
        source_line_no: 15
      template: SUMMARY.html
      title: MkClassPage