Private
Public Access
0
0

save to compare

This commit is contained in:
2026-06-03 15:57:41 -04:00
parent 170983b98e
commit 4f4cf0baf4
2 changed files with 32 additions and 13 deletions
+8 -6
View File
@@ -2,27 +2,28 @@ import re
from dataclasses import dataclass
from imgui_bundle import imgui
_TABLE_SEPARATOR = re.compile(r"^\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)+\|?\s*$")
_TABLE_SEPARATOR = re.compile(r"^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)+\|?\s*$")
def render_table(block: "TableBlock") -> None:
"""Render a GFM table block via imgui.begin_table.
[C: src/markdown_helper.py:MarkdownRenderer.render]
"""
from src.markdown_helper import render as render_md
n_cols = len(block.headers)
if n_cols == 0: return
flags = imgui.TableFlags_.borders | imgui.TableFlags_.row_bg | imgui.TableFlags_.resizable
flags = imgui.TableFlags_.borders | imgui.TableFlags_.row_bg | imgui.TableFlags_.resizable | imgui.TableFlags_.scroll_x
if not imgui.begin_table("md_table", n_cols, flags): return
for h in block.headers:
imgui.table_setup_column(h, imgui.TableColumnFlags_.width_stretch)
imgui.table_headers_row()
for h in block.headers:
imgui.table_next_column()
imgui.text(h)
# Note: table_headers_row() renders the headers from setup_column.
# No need for manual row here unless we want custom rendering for header cells.
for row in block.rows:
imgui.table_next_row()
for c in row:
imgui.table_next_column()
imgui.text(c)
render_md(c)
imgui.end_table()
@dataclass(frozen=True)
@@ -42,6 +43,7 @@ def _split_row(line: str) -> list[str]:
def _is_table_at(lines: list[str], i: int) -> bool:
if i + 1 >= len(lines): return False
# Header must have at least one pipe, or the separator must be very clear
if "|" not in lines[i]: return False
return bool(_TABLE_SEPARATOR.match(lines[i + 1]))