mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 11:29:58 +08:00
Merge #2343 from rudycelekli
This commit is contained in:
@@ -177,8 +177,8 @@ def _render_flash_cards(payload: dict[str, Any], labels: dict[str, str]) -> str:
|
||||
for card in cards:
|
||||
if not isinstance(card, dict):
|
||||
continue
|
||||
front = _payload_text(card, "front").replace("|", "\\|")
|
||||
back = _payload_text(card, "back").replace("|", "\\|")
|
||||
front = _payload_text(card, "front").replace("|", "\\|").replace("\n", "<br>")
|
||||
back = _payload_text(card, "back").replace("|", "\\|").replace("\n", "<br>")
|
||||
rows.append(f"| {front} | {back} |")
|
||||
return "\n".join(rows) if len(rows) > 2 else ""
|
||||
|
||||
|
||||
@@ -64,6 +64,20 @@ def test_flash_cards_become_a_table_with_escaped_pipes() -> None:
|
||||
assert r"a\|b" in md
|
||||
|
||||
|
||||
def test_flash_card_newlines_stay_inside_the_table_row() -> None:
|
||||
md = render_block(
|
||||
_ready(
|
||||
BlockType.FLASH_CARDS,
|
||||
{"cards": [{"front": "Define X", "back": "First line\nSecond line"}]},
|
||||
)
|
||||
)
|
||||
table_rows = [line for line in md.splitlines() if line.startswith("|")]
|
||||
# The front/back of every card must stay on a single table row; a raw
|
||||
# newline would split the GFM row and corrupt the rest of the table.
|
||||
assert any("First line" in row and "Second line" in row for row in table_rows)
|
||||
assert "First line<br>Second line" in md
|
||||
|
||||
|
||||
def test_unrendered_blocks_contribute_nothing() -> None:
|
||||
pending = Block(type=BlockType.TEXT, status=BlockStatus.PENDING, payload={"body": "x"})
|
||||
assert render_block(pending) == ""
|
||||
|
||||
Reference in New Issue
Block a user