MkDetailsBlock¶
Pymdownx-based details box.¶
Example: Regular
Jinja
{{ "Different types." | MkDetailsBlock(typ="warning") }}
Python
MkDetailsBlock(content='Different types.', typ='warning')
Warning
Different types.
:::{dropdown} Warning
:color: warning
Different types.
:::
<details class="sd-dropdown sd-bg-warning">
<summary>Warning</summary>
<p>Different types.</p>
</details>
<details>
<summary>Warning</summary>
Different types.
</details>
MkDetailsBlock
╰── MkText('Different types.')
Example: Collapsible and expandable
Jinja
{{ "MkDetailsBlocks can also be expanded." | MkDetailsBlock(expanded=True) }}
Python
MkDetailsBlock(content='MkDetailsBlocks can also be expanded.', typ='info', expanded=True)
Info
MkDetailsBlocks can also be expanded.
:::{dropdown} Info
:open:
:color: info
MkDetailsBlocks can also be expanded.
:::
<details class="sd-dropdown sd-bg-info" open>
<summary>Info</summary>
<p>MkDetailsBlocks can also be expanded.</p>
</details>
<details open>
<summary>Info</summary>
MkDetailsBlocks can also be expanded.
</details>
MkDetailsBlock
╰── MkText('MkDetailsBlocks can also be expanded.')
Name |
Children |
Inherits |
|---|---|---|
MkBlock |
graph TD
3959722705["mkdetailsblock.MkDetailsBlock"]
1483073837["mkblock.MkBlock"]
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
1483073837 --> 3959722705
835538629 --> 1483073837
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkdetailsblock/metadata.toml¶
[metadata]
icon = "octicon:info-16"
name = "MkDetailsBlock"
[requirements.extension."pymdownx.blocks.details"]
[examples.regular]
title = "Regular"
jinja = """
{{ "Different types." | MkDetailsBlock(typ="warning") }}
"""
[examples.collapsible]
title = "Collapsible and expandable"
jinja = """
{{ "MkDetailsBlocks can also be expanded." | MkDetailsBlock(expanded=True) }}
"""
[output.markdown]
template = """
{{ node.fence_boundary }} details{% if node.argument %}" | " ~ {{ node.argument }}{% endif %}
type: {{ node.typ }}
{% if node.expanded %} open: True
{% endif %}
{{ node.get_items() | join }}
{{ node.fence_boundary }}
"""
mknodes.basenodes.mkdetailsblock.MkDetailsBlock¶
15class MkDetailsBlock(mkblock.MkBlock):
16 """Pymdownx-based details box."""
17
18 ICON = "octicons/info-16"
19 REQUIRED_EXTENSIONS = [resources.Extension("pymdownx.blocks.details")]
20 STATUS = "new"
21
22 def __init__(
23 self,
24 content: str | list | mk.MkNode | None = None,
25 *,
26 typ: datatypes.AdmonitionTypeStr = "info",
27 expanded: bool | None = None,
28 title: str | None = None,
29 **kwargs: Any,
30 ) -> None:
31 """Constructor.
32
33 Args:
34 content: Admonition content
35 typ: Admonition type
36 expanded: Whether the details block should be expanded initially
37 title: Optional Admonition title
38 kwargs: Keyword arguments passed to parent
39 """
40 super().__init__(
41 "details",
42 content=content or [],
43 argument=title or "",
44 attributes=dict(type=typ, open=expanded),
45 **kwargs,
46 )
47
48 def __repr__(self) -> str:
49 items = self.get_items()
50 content = (
51 reprhelpers.to_str_if_textnode(items[0])
52 if len(items) == 1
53 else [reprhelpers.to_str_if_textnode(i) for i in items]
54 )
55 return reprhelpers.get_repr(
56 self,
57 content=content,
58 typ=self.typ,
59 title=self.title,
60 expanded=self.expanded,
61 _filter_empty=True,
62 )
63
64 @property
65 def title(self) -> str:
66 return self.argument
67
68 @title.setter
69 def title(self, value: str) -> None:
70 self.argument = value
71
72 @property
73 def typ(self) -> datatypes.AdmonitionTypeStr:
74 return self.attributes["type"]
75
76 @typ.setter
77 def typ(self, value: datatypes.AdmonitionTypeStr) -> None:
78 self.attributes["type"] = value
79
80 @property
81 def expanded(self) -> bool:
82 return self.attributes["open"]
83
84 @expanded.setter
85 def expanded(self, value: bool) -> None:
86 self.attributes["open"] = value
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes¶
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: octicons/info-16
status: new
title: MkDetailsBlock