Skip to content

Commit

Permalink
chore: metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Nov 14, 2023
1 parent cb968da commit 7d22a79
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 50 deletions.
32 changes: 16 additions & 16 deletions mknodes/basenodes/mkadmonition/metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ template = """
{% endif %}
"""

# [output.block]
# template = """
# {{ node.fence_boundary }} admonition {{ node.typ }} | {{ node.title }}
# {{ node.items | join }}
# {{ node.fence_boundary }}
# """
[output.block]
template = """
{{ node.fence_boundary }} admonition {{ node.typ }} | {{ node.title }}
{{ node.items | join }}
{{ node.fence_boundary }}
"""

# [output.github]
# template = """
# > [!{{ node.typ | upper }}]\
# {{ node.items | join | indent(width="> ", first=True) }}
# """
[output.github]
template = """
> [!{{ node.typ | upper }}]\
{{ node.items | join | indent(width="> ", first=True) }}
"""

# [output.rst]
# template = """
# .. {{ self.typ }}:: {{ node.title }}
# {{ node.items | join(node.block_separator) | indent(first=True) }}
# """
[output.rst]
template = """
.. {{ node.typ }}:: {{ node.title }}
{{ node.items | join(node.block_separator) | indent(first=True) }}
"""
10 changes: 5 additions & 5 deletions mknodes/basenodes/mkcode/metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ template = """
{{ node.fence_boundary }}
"""

# [output.rst]
# template = """
# .. sourcecode:: {{ node.language }}
# {{ node.text | indent(first=True) }}
# """
[output.rst]
template = """
.. sourcecode:: {{ node.language }}
{{ node.text | indent(first=True) }}
"""
12 changes: 6 additions & 6 deletions mknodes/basenodes/mkfootnotes/metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ template = """
{{ node.items | sort(attribute="num") | join }}
"""

# [output.rst]
# template = """
# .. rubric:: Footnotes
[output.rst]
template = """
.. rubric:: Footnotes
# {% for item in node.items | sort(attribute="num") %}
# .. {{ item }}
# """
{% for item in node.items | sort(attribute="num") %}
.. {{ item }}
"""
14 changes: 7 additions & 7 deletions mknodes/basenodes/mkheader/metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ template = """
{{ "#" * node.level }} {{ node.text }}{% if node.exclude_from_search %} { data-search-exclude }{% endif %}
"""

# [output.rst]
# template = """
# {% set line = {1: '#' , 2: '*' , 3: '=' , 4: '-' , 5: '^' , 6: '"' }[node.level] * (node.text | length) %}
# {{ line }}
# {{ node.text }}
# {{ line }}
# """
[output.rst]
template = """
{% set line = {1: '#' , 2: '*' , 3: '=' , 4: '-' , 5: '^' , 6: '"' }[node.level] * (node.text | length) %}
{{ line }}
{{ node.text }}
{{ line }}
"""
20 changes: 10 additions & 10 deletions mknodes/basenodes/mkimage/metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ template = """
{{ markdown_link }}{% endif %}
"""

# [output.github]
# template = """
# <picture>
# {% if node.path_dark_mode %}
# <source media="(prefers-color-scheme: dark)" srcset="{{ node.path_dark_mode }}">
# <source media="(prefers-color-scheme: light)" srcset="{{ node.path }}">
# {% endif %}
# <img alt="{{ node.caption }}" src="{{ node.path }}">
# </picture>
# """
[output.github]
template = """
<picture>
{% if node.path_dark_mode %}
<source media="(prefers-color-scheme: dark)" srcset="{{ node.path_dark_mode }}">
<source media="(prefers-color-scheme: light)" srcset="{{ node.path }}">
{% endif %}
<img alt="{{ node.caption }}" src="{{ node.path }}">
</picture>
"""
8 changes: 4 additions & 4 deletions mknodes/basenodes/mklink/metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ template = """
[{{ node.icon | add(suffix=" ") }}{{ node.title }}]({{ node.url }}{{ node.tooltip | add(prefix=" '", suffix="'")}})
"""

# [output.rst]
# template = """
# `{{ node.title }} <{{ node.url }}>`_
# """
[output.rst]
template = """
`{{ node.title }} <{{ node.url }}>`_
"""
4 changes: 4 additions & 0 deletions mknodes/info/nodefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def get_representations(jinja: str, parent: mk.MkNode) -> dict[str, str | mk.MkN
Markdown=mk.MkCode(node, language="markdown"),
Html=mk.MkCode(node.to_html(), language="html"),
)
if "rst" in node.nodefile.output:
dct["reST"] = mk.MkCode(node.env.render_template("output/rst/template"))
if "github" in node.nodefile.output:
dct["GitHub"] = mk.MkCode(node.env.render_template("output/github/template"))
if len(node.children) > 0:
dct["Repr tree"] = mk.MkTreeView(node)
return dct
Expand Down
6 changes: 4 additions & 2 deletions tests/test_nodefiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def test_if_example_can_get_rendered(node):

@pytest.mark.parametrize("node", example_instances(), ids=lambda x: x.__class__.__name__)
def test_if_template_output_equals_code_output(node: mk.MkNode):
if (nodefile := node.nodefile) and (output := nodefile.output):
for v in output.values():
if nodefile := node.nodefile:
for k, v in nodefile.output.items():
if k not in ["markdown", "html"]:
continue
result = node.env.render_string(v["template"], dict(node=node))
assert result == node._to_markdown()

0 comments on commit 7d22a79

Please sign in to comment.