fix(markdown): strip blank between bullet and indented continuation paragraph
ROOT CAUSE: imgui_md (mekhontsev/imgui_md) BLOCK_P does NOT call ImGui::NewLine()
when m_list_stack is non-empty (verified in imgui_md.cpp). So a multi-paragraph
list item like:
- bullet text (long, wraps to 2 lines)
continuation paragraph
renders BOTH paragraphs at the same Y because the second BLOCK_P enters/exits
without advancing the cursor. The continuation crashes into the previous
paragraph's last wrapped line.
FIX: Add MarkdownRenderer._normalize_list_continuations preprocessor that
strips blank lines between a list item and its indented continuation. The
continuation then becomes a lazy continuation of the first paragraph (single
BLOCK_P in imgui_md, proper text wrapping, no overlap). Trade-off: users
cannot have separate paragraphs within a single list item. Acceptable.
Also: fixed a pre-existing bug in _normalize_nested_list_endings where a
duplicate conditional caused the function to return empty string (the
out.append(line) was inside the wrong scope). It was silently corrupting
all list content since fd5f4d0e.
TESTS: 23/23 markdown unit tests pass. 3 new tests for the new preprocessor
covering: blank-strip case, blank-preservation case, simple-list passthrough.
This commit is contained in:
@@ -83,3 +83,24 @@ def test_normalize_bullet_delimiters_still_converts_asterisk():
|
||||
assert "- one" in out
|
||||
assert "- two" in out and "* two" not in out, f"* must be converted to -, got {out!r}"
|
||||
assert "+ three" in out, f"+ must be left alone, got {out!r}"
|
||||
assert "+ three" in out, f"+ must be left alone, got {out!r}"
|
||||
|
||||
def test_normalize_list_continuations_strips_blank_between_bullet_and_indented_continuation():
|
||||
r = MarkdownRenderer()
|
||||
text = "- bullet text\n\n continuation paragraph\n\nnext paragraph\n"
|
||||
out = r._normalize_list_continuations(text)
|
||||
assert " continuation paragraph" in out
|
||||
assert "- bullet text\n continuation paragraph" in out, f"blank between bullet and indented continuation must be stripped (workaround for imgui_md BLOCK_P no-NewLine-inside-list bug), got {out!r}"
|
||||
assert "next paragraph" in out
|
||||
|
||||
def test_normalize_list_continuations_preserves_blank_between_indented_and_next_paragraph():
|
||||
r = MarkdownRenderer()
|
||||
text = "- bullet\n cont\n\nnext\n"
|
||||
out = r._normalize_list_continuations(text)
|
||||
assert "- bullet\n cont\n\nnext\n" == out, f"blank between continuation and next paragraph must be preserved (it ends the list item), got {out!r}"
|
||||
|
||||
def test_normalize_list_continuations_leaves_simple_list_alone():
|
||||
r = MarkdownRenderer()
|
||||
text = "- one\n- two\n- three\n"
|
||||
out = r._normalize_list_continuations(text)
|
||||
assert out == text, f"simple list with no continuations should be unchanged, got {out!r}"
|
||||
|
||||
Reference in New Issue
Block a user