fix(telegram): preserve numbering with malformed nested lists (#202)

This commit is contained in:
banteg
2026-02-11 01:47:43 +04:00
committed by GitHub
parent 13ea8298d9
commit 56bc1681c6
2 changed files with 80 additions and 1 deletions
+30
View File
@@ -1,3 +1,5 @@
import re
from takopi.telegram.render import render_markdown, split_markdown_body
@@ -20,6 +22,34 @@ def test_render_markdown_code_fence_language_is_string() -> None:
assert any(e.get("type") == "code" for e in entities)
def test_render_markdown_keeps_ordered_numbering_with_unindented_sub_bullets() -> None:
md = (
"1. Tune maker\n"
"- Sweep\n"
"- Keep data\n"
"1. Increase\n"
"- Raise target\n"
"- Keep\n"
"1. Train\n"
"- Start\n"
"1. Add\n"
"- Keep exposure\n"
"1. Run\n"
"- Target pnl\n"
)
text, _ = render_markdown(md)
numbered = [line for line in text.splitlines() if re.match(r"^\d+\.\s", line)]
assert numbered == [
"1. Tune maker",
"2. Increase",
"3. Train",
"4. Add",
"5. Run",
]
def test_split_markdown_body_closes_and_reopens_fence() -> None:
body = "```py\n" + ("line\n" * 10) + "```\n\npost"