MkContainer¶
A node containing other MkNodes.¶
Description
This is the concrete implementation with list-based storage. Can be used directly or as a base class. Nodes added to a container are automatically re-parented.
Example: Regular
Jinja
{{ ["a = 1 + 2" | MkCode, "abc" | MkText] | MkContainer }}
Python
MkContainer()
a = 1 + 2
abc
a = 1 + 2
abc
````python
a = 1 + 2
````
abc
````python
a = 1 + 2
````
abc
<pre><code class="language-python">a = 1 + 2
</code></pre>
<p>abc</p>
<pre><code class="language-python">a = 1 + 2
</code></pre>
<p>abc</p>
MkContainer
├── MkCode(None)
│ ╰── MkText('a = 1 + 2')
├── MkText('abc')
╰── MkContainer()
├── MkCode(None)
│ ╰── MkText('a = 1 + 2')
├── MkText('abc')
Name |
Children |
Inherits |
|---|---|---|
MkBlock |
||
MkAdmonition |
||
MkBlockQuote |
||
MkCode |
||
MkTemplate |
||
MkList |
||
MkBaseTable |
||
MkTab |
||
MkTabContainer |
||
MkCritic |
||
MkAnnotation |
||
MkAnnotations |
||
MkFootNote |
||
MkFootNotes |
||
MkDefinition |
||
MkDefinitionList |
||
MkPage |
||
MkShowcase |
||
MkSpeechBubble |
||
MkTask |
||
MkTaskList |
||
MkTimeline |
||
MkShields |
||
MkMetadataBadges |
Name |
Children |
Inherits |
|---|---|---|
MkContainerBase |
graph TD
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
[metadata]
icon = "mdi:database"
name = "MkContainer"
[examples.regular]
title = "Regular"
jinja = """
{{ ["a = 1 + 2" | MkCode, "abc" | MkText] | MkContainer }}
"""
108class MkContainer(MkContainerBase):
109 """A node containing other MkNodes.
110
111 This is the concrete implementation with list-based storage.
112 Can be used directly or as a base class.
113 Nodes added to a container are automatically re-parented.
114 """
115
116 def __init__(
117 self,
118 content: list[Any] | str | mknode.MkNode | None = None,
119 *,
120 block_separator: str = "\n\n",
121 **kwargs: Any,
122 ) -> None:
123 """Constructor.
124
125 Args:
126 content: Child Nodes of this container
127 block_separator: Separator to put between blocks. Defaults to 2 linebreaks
128 kwargs: Keyword arguments passed to parent
129 """
130 super().__init__(block_separator=block_separator, **kwargs)
131 match content:
132 case None:
133 self._items: list[mknode.MkNode] = []
134 case str():
135 self._items = [self.to_child_node(content)] if content else []
136 case mknode.MkNode():
137 self._items = [self.to_child_node(content)]
138 case list():
139 self._items = [self.to_child_node(i) for i in content]
140 case _:
141 raise TypeError(content)
142
143 def get_items(self) -> list[mknode.MkNode]:
144 """Return the list of contained items."""
145 return self._items
146
147 def set_items(self, items: list[mknode.MkNode]) -> None:
148 """Set the list of contained items."""
149 self._items = items
Page info
Code for this page
93def create_section_for_nodes(
94 nav: mk.MkNav,
95 klasses: Sequence[type[mk.MkNode]],
96) -> mk.MkTable:
97 table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
98 for kls in klasses:
99 tpl = "classpage_custom.jinja"
100 page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
101 nav += page
102 if kls.STATUS:
103 page.metadata.status = kls.STATUS
104 elif kls.JS_FILES:
105 page.metadata.status = "js"
106 elif kls.CSS:
107 page.metadata.status = "css"
108 page.created_by = create_section_for_nodes
109 link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
110 extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
111 table.add_row((link, kls.__doc__, extensions))
112 return table
Resources
Resources(css=[],
markdown_extensions={'admonition': {},
'pymdownx.details': {},
'pymdownx.highlight': {'anchor_linenums': True,
'line_spans': '__span',
'pygments_lang_class': True},
'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
'format': <function fence_code_format at 0x7ff77e88b060>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
source_function: create_section_for_nodes
source_line_no: 93
hide:
- toc
icon: material/database
title: MkContainer