"""内容处理模块测试""" 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 = '
'
result = html_to_markdown(html)
assert "" in result
def test_convert_with_headings(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\nLine 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