-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown.py
More file actions
25 lines (20 loc) · 912 Bytes
/
Copy pathmarkdown.py
File metadata and controls
25 lines (20 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""A plugin in its own module — the import-time caveat, made concrete.
Nothing imports this module for its names; it is imported (by the package
``__init__``) purely so the ``@EXPORTERS.register`` below runs. Comment out
that import and ``"markdown"`` vanishes from the registry without any other
code changing — which is exactly why real plugin systems pair registries
with entry points or explicit plugin loading.
"""
from __future__ import annotations
from patterns.modern.registry.examples.export_plugins.exporters import EXPORTERS, Rows
@EXPORTERS.register("markdown")
def to_markdown(rows: Rows) -> str:
if not rows:
return ""
headers = list(rows[0])
lines = [
"| " + " | ".join(headers) + " |",
"| " + " | ".join("---" for _ in headers) + " |",
]
lines += ["| " + " | ".join(row[h] for h in headers) + " |" for row in rows]
return "\n".join(lines)