markdown fix but introduces a regresssion...
This commit is contained in:
+37
-2
@@ -134,9 +134,9 @@ class MarkdownRenderer:
|
||||
if md_buf:
|
||||
chunk = "".join(md_buf)
|
||||
if chunk.strip():
|
||||
imgui_md.render(chunk)
|
||||
imgui.spacing()
|
||||
self._render_md_no_bullet_overlap(chunk)
|
||||
md_buf.clear()
|
||||
|
||||
def flush_code() -> None:
|
||||
nonlocal block_idx
|
||||
if code_buf:
|
||||
@@ -182,6 +182,41 @@ class MarkdownRenderer:
|
||||
|
||||
flush_md()
|
||||
flush_code()
|
||||
|
||||
def _render_md_no_bullet_overlap(self, chunk: str) -> None:
|
||||
"""Render markdown, but split out bulleted-list sections and render them
|
||||
as plain text via imgui.text to avoid imgui_md's known bullet-overlap bug.
|
||||
"""
|
||||
import re
|
||||
list_pattern = re.compile(r"^(?P<indent>[ \t]*)(?:[-*+])\s+", re.MULTILINE)
|
||||
current_pos = 0
|
||||
for m in list_pattern.finditer(chunk):
|
||||
if m.start() > current_pos:
|
||||
pre = chunk[current_pos:m.start()]
|
||||
if pre.strip(): imgui_md.render(pre)
|
||||
list_start = m.start()
|
||||
indent_len = len(m.group("indent"))
|
||||
i = list_start
|
||||
while i < len(chunk):
|
||||
line_end = chunk.find("\n", i)
|
||||
if line_end == -1: line_end = len(chunk)
|
||||
line = chunk[i:line_end]
|
||||
stripped = line.lstrip(" \t")
|
||||
leading_ws = len(line) - len(stripped)
|
||||
if leading_ws == indent_len and (stripped.startswith(("- ", "* ", "+ ")) or stripped == ""):
|
||||
i = line_end + 1
|
||||
continue
|
||||
if leading_ws < indent_len:
|
||||
break
|
||||
i = line_end + 1
|
||||
list_block = chunk[list_start:i]
|
||||
for line in list_block.splitlines():
|
||||
imgui.text(line) if line.strip() else imgui.spacing()
|
||||
current_pos = i
|
||||
if current_pos < len(chunk):
|
||||
tail = chunk[current_pos:]
|
||||
if tail.strip(): imgui_md.render(tail)
|
||||
|
||||
def render_unindented(self, text: str) -> None:
|
||||
"""Render Markdown text with automatic unindentation."""
|
||||
imgui_md.render_unindented(text)
|
||||
|
||||
Reference in New Issue
Block a user