import textwrap import pytest from bs4 import BeautifulSoup from markdown import Markdown from xml.etree.ElementTree import Element, SubElement from lib.markdown_parser import ( HeadingCollector, HeadingExtension, build_component_structure, markdown_to_html_lines, parse_markdown_file, ) def test_h4_creates_card_details(): md = textwrap.dedent(""" # Page Title ## Section One ### Card One Card intro paragraph. #### Detail A Detail content line 1. - item 1 - item 2 #### Detail B Another detail paragraph with [a link](https://example.com). """) page = build_component_structure(md, "test.md") assert page['title'] == 'Page Title' assert len(page['sections']) == 1 section = page['sections'][0] assert section['title'] == 'Section One' assert len(section['cards']) == 1 card = section['cards'][0] assert card['title'] == 'Card One' # content should include the intro paragraph converted to HTML assert 'Card intro paragraph' in card['content'] # details should be present assert 'details' in card assert len(card['details']) == 2 assert card['details'][0]['title'] == 'Detail A' assert 'item 1' in card['details'][0]['content'] assert card['details'][1]['title'] == 'Detail B' assert 'https://example.com' in card['details'][1]['content'] def test_section_content_preserves_lists_before_first_card(): md = textwrap.dedent(""" # Title ## Section One - Item A - Item B ### Card Title Card body """) page = build_component_structure(md, "test.md") section = page['sections'][0] assert '