from app.text_extract import html_to_text, markdown_to_text def test_html_to_text_strips_tags(): html = """

架构设计

DocHub 是一个基于 MinIO 的文档管理系统。

""" result = html_to_text(html) assert "架构设计" in result assert "DocHub 是一个基于 MinIO 的文档管理系统。" in result assert "浏览文档" in result assert "

" not in result assert "" not in result def test_html_to_text_collapses_whitespace(): html = "

第一段

\n\n\n

第二段

" result = html_to_text(html) assert result == "第一段 第二段" def test_markdown_to_text_strips_headers_and_emphasis(): markdown = """# 架构设计 ## 背景 DocHub 是一个 **基于 MinIO** 的 _文档管理系统_,支持全文检索。 """ result = markdown_to_text(markdown) assert "#" not in result assert "**" not in result assert "_" not in result assert "架构设计" in result assert "背景" in result assert "基于 MinIO" in result assert "文档管理系统" in result def test_markdown_to_text_strips_links_and_list_markers(): markdown = """## 功能列表 - 浏览 [MinIO](https://min.io) 中存储的文档 - 支持 [Meilisearch](https://www.meilisearch.com) 全文检索 1. 在线编辑并保存 """ result = markdown_to_text(markdown) assert "[" not in result assert "](" not in result assert "浏览 MinIO 中存储的文档" in result assert "支持 Meilisearch 全文检索" in result assert "在线编辑并保存" in result def test_html_to_text_escapes_raw_tag_like_text_content(): html_doc = "

点击查看 <img src=x onerror=alert(1)> 示例

" result = html_to_text(html_doc) assert "