From 79ac9210ef79efeab316320e978e66c6b86ca90a Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 3 Jun 2026 11:10:30 -0400 Subject: [PATCH] feat(markdown): intercept GFM tables and render via imgui.begin_table --- src/markdown_helper.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/markdown_helper.py b/src/markdown_helper.py index 5d3ee168..c37c3284 100644 --- a/src/markdown_helper.py +++ b/src/markdown_helper.py @@ -108,23 +108,38 @@ class MarkdownRenderer: def render(self, text: str, context_id: str = "default") -> None: """ - - Render Markdown text with code block interception. + + Render Markdown text with code block interception and GFM table substitution. [C: src/theme_2.py:render_post_fx, tests/test_theme_nerv_alert.py:test_alert_pulsing_render_active, tests/test_theme_nerv_alert.py:test_alert_pulsing_render_inactive, tests/test_theme_nerv_fx.py:TestThemeNervFx.test_alert_pulsing_render, tests/test_theme_nerv_fx.py:TestThemeNervFx.test_crt_filter_disabled, tests/test_theme_nerv_fx.py:TestThemeNervFx.test_crt_filter_render] """ if not text: return - # Split into markdown and code blocks - parts = re.split(r'(```[\s\S]*?```)', text) - + from src.markdown_table import parse_tables, render_table + blocks = parse_tables(text) + sentinel = "\x00TBL{}\x00" + masked = text + for idx, block in enumerate(blocks): + start, end = block.span + original_block = "\n".join(masked.splitlines()[start:end]) + masked = masked.replace(original_block, sentinel.format(idx), 1) + + parts = re.split(r"(```[\s\S]*?```)", masked) + block_idx = 0 for part in parts: - if part.startswith('```') and part.endswith('```'): + if part.startswith("```") and part.endswith("```"): self._render_code_block(part, context_id, block_idx) block_idx += 1 elif part.strip(): - imgui_md.render(part) + sub_parts = re.split(r"(\x00TBL\d+\x00)", part) + for sp in sub_parts: + if sp.startswith("\x00TBL") and sp.endswith("\x00"): + tbl_idx = int(sp[4:-1]) + try: render_table(blocks[tbl_idx]) + except Exception: imgui.text(sp) + else: + if sp.strip(): imgui_md.render(sp) def render_unindented(self, text: str) -> None: """Render Markdown text with automatic unindentation."""