Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

NameChildrenInherits
MkDiagram
mknodes.basenodes.mkdiagram
Class representing a mermaid diagram.
MkTreeView
mknodes.templatenodes.mktreeview
Node to display tree structures.

    Base classes

    NameChildrenInherits
    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

    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:

    NameTypeDescriptionDefault
    contentstr | mk.MkNode | list[mk.MkNode]Content to show inside code boxβ€˜β€™
    languagestrlanguage for syntax highlightingβ€˜python’
    titlestrCode block titleβ€˜β€™
    linenumsint | NoneIf set, use as start linenumberNone
    highlight_lineslist[int] | NoneOptionally highlight linesNone
    fence_levelint | NoneDetermines amount of ticks used for fence.
    If None, auto-determine based on nesting depth.
    None
    kwargsAnyKeyword 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:

    NameTypeDescriptionDefault
    pathJoinablePathLikePath to the code file (also supports fsspec-protocol URLs)
    linenumsboolWhether to show line numbersTrue
    highlight_callerboolWhether we want to try to highlight the line which called
    this method.
    True
    titlestr | Nonetitle to use for the code box. If None is set, filename will be used.None
    languagestr | NoneSyntax highlighting language. If None, try to infer from extension.None
    kwargsAnyKeyword 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:

    NameTypeDescriptionDefault
    objdatatypes.HasCodeTypePython object to show code from
    dedentboolWhether to dedent the codeTrue
    extract_bodyboolif True, Function / Class signatures are stripped from the codeFalse
    titlestr | NoneTitle to use for code block. If None, it will use the object path.None
    linenumsboolWhether to show line numbersTrue
    highlight_callerboolWhether we want to try to highlight the line which called
    this method.
    True
    kwargsAnyKeyword 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.

    github Show source on GitHub

    And this is an alternate tabbed layout:

    MkCode

    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:

    NameTypeDescriptionDefault
    contentstr | mk.MkNode | list[mk.MkNode]Content to show inside code boxβ€˜β€™
    languagestrlanguage for syntax highlightingβ€˜python’
    titlestrCode block titleβ€˜β€™
    linenumsint | NoneIf set, use as start linenumberNone
    highlight_lineslist[int] | NoneOptionally highlight linesNone
    fence_levelint | NoneDetermines amount of ticks used for fence.
    If None, auto-determine based on nesting depth.
    None
    kwargsAnyKeyword 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:

    NameTypeDescriptionDefault
    pathJoinablePathLikePath to the code file (also supports fsspec-protocol URLs)
    linenumsboolWhether to show line numbersTrue
    highlight_callerboolWhether we want to try to highlight the line which called
    this method.
    True
    titlestr | Nonetitle to use for the code box. If None is set, filename will be used.None
    languagestr | NoneSyntax highlighting language. If None, try to infer from extension.None
    kwargsAnyKeyword 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:

    NameTypeDescriptionDefault
    objdatatypes.HasCodeTypePython object to show code from
    dedentboolWhether to dedent the codeTrue
    extract_bodyboolif True, Function / Class signatures are stripped from the codeFalse
    titlestr | NoneTitle to use for code block. If None, it will use the object path.None
    linenumsboolWhether to show line numbersTrue
    highlight_callerboolWhether we want to try to highlight the line which called
    this method.
    True
    kwargsAnyKeyword 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.

    Sub classes
    NameChildrenInherits
    MkDiagram
    mknodes.basenodes.mkdiagram
    Class representing a mermaid diagram.
    MkTreeView
    mknodes.templatenodes.mktreeview
    Node to display tree structures.
      Base classes
      NameChildrenInherits
      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
      

      github Show source on GitHub

      Page info
      Code for this page

      mknodes.manual.page_section._

      @nav.route.page("MkClassPage")
      def _(page: mk.MkPage) -> None:
          variables = dict(example_class=mk.MkCode)
          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 0x7d707a397060>,
                                                                                 '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