"""Tests for app/markdown_render.py — the curator-content render+sanitize path.""" from __future__ import annotations from app.markdown_render import render_safe # --- Empty / null inputs ------------------------------------------------- def test_render_safe_none_returns_empty_string(): assert render_safe(None) == "" def test_render_safe_empty_string_returns_empty_string(): assert render_safe("") == "" def test_render_safe_whitespace_only_returns_empty_or_trivial(): # Whitespace-only markdown renders to "" or a single empty paragraph; # either is acceptable — both render as nothing visually. out = render_safe(" \n ") assert out.strip() in {"", "

"} # --- Allowed formatting survives ----------------------------------------- def test_render_safe_renders_paragraph_with_bold(): assert render_safe("**hello** world").strip() == "

hello world

" def test_render_safe_renders_italic(): assert "x" in render_safe("*x*") def test_render_safe_renders_inline_code(): assert "foo()" in render_safe("`foo()`") def test_render_safe_renders_fenced_code_block(): out = render_safe("```py\nprint('hi')\n```") assert "
" in out
    assert "" in out
    # The literal `print('hi')` must end up inside  — apostrophe is
    # safe in attribute-free body text so escaping is not strictly required.
    assert "print(" in out
    assert "'hi'" in out or "'hi'" in out


def test_render_safe_renders_lists():
    out = render_safe("- one\n- two\n- three")
    assert out.count("
  • ") == 3 assert "