fix(markdown): revert table to simple form with text_wrapped + add regression tests
This commit is contained in:
@@ -2,28 +2,27 @@ import re
|
||||
from dataclasses import dataclass
|
||||
from imgui_bundle import imgui
|
||||
|
||||
_TABLE_SEPARATOR = re.compile(r"^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)+\|?\s*$")
|
||||
_TABLE_SEPARATOR = re.compile(r"^\|?\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 | imgui.TableFlags_.scroll_x
|
||||
flags = imgui.TableFlags_.borders | imgui.TableFlags_.row_bg | imgui.TableFlags_.resizable
|
||||
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_setup_column(h)
|
||||
imgui.table_headers_row()
|
||||
# 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 h in block.headers:
|
||||
imgui.table_next_column()
|
||||
imgui.text_wrapped(h)
|
||||
for row in block.rows:
|
||||
imgui.table_next_row()
|
||||
for c in row:
|
||||
imgui.table_next_column()
|
||||
render_md(c)
|
||||
imgui.text_wrapped(c)
|
||||
imgui.end_table()
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -43,7 +42,6 @@ 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]))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user