"""内容处理模块测试""" import pytest import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent / "src")) from processor import html_to_markdown class TestHtmlToMarkdown: """测试HTML转Markdown""" def test_convert_basic_html(self): html = "

Hello World

" result = html_to_markdown(html) assert "Hello World" in result def test_convert_with_links(self): html = 'Click here' result = html_to_markdown(html) assert "[Click here](https://example.com)" in result def test_convert_with_images(self): html = 'Image' result = html_to_markdown(html) assert "![Image](https://example.com/image.png)" in result def test_convert_with_headings(self): html = "

Title

Subtitle

" result = html_to_markdown(html) assert "# Title" in result assert "## Subtitle" in result def test_convert_with_lists(self): html = "" result = html_to_markdown(html) assert "Item 1" in result assert "Item 2" in result def test_convert_with_strong_emphasis(self): html = "Bold and italic" result = html_to_markdown(html) assert "**Bold**" in result assert "*italic*" in result def test_relative_link_conversion(self): html = 'Read more' result = html_to_markdown(html, base_url="https://example.com/blog") assert "https://example.com/article/123" in result def test_relative_image_conversion(self): html = '' result = html_to_markdown(html, base_url="https://example.com") assert "https://example.com/images/logo.png" in result def test_absolute_link_unchanged(self): html = 'Link' result = html_to_markdown(html, base_url="https://example.com") assert "https://other.com/page" in result def test_remove_xgo_ing_link(self): html = "

Content

[⚡ Powered by xgo.ing](https://xgo.ing)

" result = html_to_markdown(html) assert "xgo.ing" not in result assert "Content" in result def test_remove_xgo_ing_link_with_slash(self): html = "

Content

[⚡ Powered by xgo.ing](https://xgo.ing/)

" result = html_to_markdown(html) assert "xgo.ing" not in result def test_clean_extra_newlines(self): html = "

Line 1

\n\n\n\n

Line 2

" result = html_to_markdown(html) assert "\n\n\n\n" not in result def test_empty_html(self): result = html_to_markdown("") assert result.strip() == "" def test_html_with_nbsp(self): html = "

Hello World

" result = html_to_markdown(html) assert "Hello" in result assert "World" in result