MkHtmlTable
:fa-brands-github: Show source on GitHub
Class representing a html table.¶
Description
Compared to MkTable, this will end up with a more verbose output, but it can contain more complex Markdown in cells.
Example: Regular¶
Jinja
{% set code_col = [_mk.MkCode("print('hello world')
sys.exit()"), _mk.MkCode("print('hello world')
sys.exit()")] %}
{% set admonitions = [_mk.MkAdmonition("Admonition inside cell"), _mk.MkAdmonition("Admonition inside cell")] %}
{% set tabs = [_mk.MkTabbed(dict(A=["Tab a"], B=["Tab b"])), _mk.MkTabbed(dict(A=["Tab a"], B=["Tab b"]))] %}
{% set data = {"Code": code_col, "Admonitions": admonitions, "Tabs": tabs} %}
{{ data | MkHtmlTable }}
Python
| Code | Admonitions | Tabs |
|
Info Admonition inside cell |
Tab a Tab b |
|
|
Info Admonition inside cell |
Tab a Tab b |
<table markdown="1">
<tr>
<td>
Code
</td>
<td>
Admonitions
</td>
<td>
Tabs
</td>
</tr>
<tr>
<td>
```` {.python }
print('hello world')
sys.exit()
````
</td>
<td>
!!! info
Admonition inside cell
</td>
<td>
===! "A"
Tab a
=== "B"
Tab b
</td>
</tr>
<tr>
<td>
```` {.python }
print('hello world')
sys.exit()
````
</td>
<td>
!!! info
Admonition inside cell
</td>
<td>
===! "A"
Tab a
=== "B"
Tab b
</td>
</tr>
</table>
<table>
<tr>
<td>
Code
</td>
<td>
Admonitions
</td>
<td>
Tabs
</td>
</tr>
<tr>
<td>
<div class="language-python highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="nb">print</span><span class="p">(</span><span class="s1">'hello world'</span><span class="p">)</span>
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">()</span>
</span></code></pre></div>
</td>
<td>
!!! info
Admonition inside cell
</td>
<td>
===! "A"
Tab a
=== "B"
Tab b
</td>
</tr>
<tr>
<td>
<div class="language-python highlight"><pre><span></span><code><span id="__span-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="nb">print</span><span class="p">(</span><span class="s1">'hello world'</span><span class="p">)</span>
</span><span id="__span-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">()</span>
</span></code></pre></div>
</td>
<td>
!!! info
Admonition inside cell
</td>
<td>
===! "A"
Tab a
=== "B"
Tab b
</td>
</tr>
</table>
<table>
<tr><th>Code</th><th>Admonitions</th><th>Tabs</th></tr>
<tr>
<td>
````python
print('hello world')
sys.exit()
````
</td>
<td>
> [!NOTE]
> Admonition inside cell
</td>
<td>
<details open>
<summary>A</summary>
Tab a
</details>
<details>
<summary>B</summary>
Tab b
</details>
</td>
</tr>
<tr>
<td>
````python
print('hello world')
sys.exit()
````
</td>
<td>
> [!NOTE]
> Admonition inside cell
</td>
<td>
<details open>
<summary>A</summary>
Tab a
</details>
<details>
<summary>B</summary>
Tab b
</details>
</td>
</tr>
</table>
MkHtmlTable
├── MkCode(None)
│ ╰── MkText("print('hello world')\nsys.exit()")
├── MkCode(None)
│ ╰── MkText("print('hello world')\nsys.exit()")
├── MkAdmonition(None)
│ ╰── MkText('Admonition inside cell')
├── MkAdmonition(None)
│ ╰── MkText('Admonition inside cell')
├── MkTabbed(tabs=[...])
│ ├── MkTab(title='A', content='Tab a', new=True)
│ │ ╰── MkText('Tab a')
│ ╰── MkTab(title='B', content='Tab b')
│ ╰── MkText('Tab b')
├── MkTabbed(tabs=[...])
│ ├── MkTab(title='A', content='Tab a', new=True)
│ │ ╰── MkText('Tab a')
│ ╰── MkTab(title='B', content='Tab b')
│ ╰── MkText('Tab b')
| Name | Children | Inherits |
|---|---|---|
| MkBaseTable mknodes.basenodes.mkbasetable Base Class for MkTables. Only deals with managing the data. |
graph TD
530410512["mkhtmltable.MkHtmlTable"]
3678415322["mkbasetable.MkBaseTable"]
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
3678415322 --> 530410512
835538629 --> 3678415322
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkhtmltable/metadata.toml
[metadata]
icon = "octicon:table-24"
status = "new"
name = "MkHtmlTable"
[examples.regular]
title = "Regular"
jinja = """
{% set code_col = [_mk.MkCode("print('hello world')\nsys.exit()"), _mk.MkCode("print('hello world')\nsys.exit()")] %}
{% set admonitions = [_mk.MkAdmonition("Admonition inside cell"), _mk.MkAdmonition("Admonition inside cell")] %}
{% set tabs = [_mk.MkTabbed(dict(A=["Tab a"], B=["Tab b"])), _mk.MkTabbed(dict(A=["Tab a"], B=["Tab b"]))] %}
{% set data = {"Code": code_col, "Admonitions": admonitions, "Tabs": tabs} %}
{{ data | MkHtmlTable }}
"""
[output.markdown]
template = """
{% set table = node.data %}
<table markdown="1">
<tr>
{% for header in table.keys() %}
<td>
{{ header }}
</td>
{% endfor %}
</tr>
{% for row in node.iter_rows() %}
<tr>
{% for item in row %}
<td>
{{ item }}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
"""
Page info
Code for this page
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 0x703933662e50>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[],
packages=[])