25 lines
1.0 KiB
Python
25 lines
1.0 KiB
Python
import html as html_lib
|
|
|
|
from .visible_attrs import _visible_attrs
|
|
from .apply_ctx import _apply_ctx
|
|
from .style_string import _style_string
|
|
from .attr_string import _attr_string
|
|
|
|
|
|
def _render_table(el, meta, slug=None, children_map=None, ctx=None, parent_flex_direction=None):
|
|
attrs = _visible_attrs(el, meta, ctx)
|
|
header_row = (el.get("attributes") or {}).get("_header_row") in ("1", "true", "on")
|
|
content = _apply_ctx(el.get("content") or "", ctx)
|
|
style = _style_string(el, " border-collapse:collapse;", parent_flex_direction)
|
|
rows = [r for r in content.split("\n") if r.strip()]
|
|
html_rows = []
|
|
for i, r in enumerate(rows):
|
|
cells = r.split(";")
|
|
cell_tag = "th" if (header_row and i == 0) else "td"
|
|
cells_html = "".join(
|
|
f'<{cell_tag} style="border:1px solid #2b3140; padding:6px 8px;">{html_lib.escape(c.strip())}</{cell_tag}>'
|
|
for c in cells
|
|
)
|
|
html_rows.append(f"<tr>{cells_html}</tr>")
|
|
return f'<table {_attr_string(attrs, style)}>{"".join(html_rows)}</table>'
|