- 创建 scripts/ 目录作为核心代码根目录 - 移动 core/, readers/, utils/ 到 scripts/ 下 - 移动 config.py, lyxy_document_reader.py 到 scripts/ - 移动 encoding_detection.py 到 scripts/utils/ - 更新 pyproject.toml 中的入口点路径和 pytest 配置 - 更新所有内部导入语句为 scripts.* 模块 - 更新 README.md 目录结构说明 - 更新 openspec/config.yaml 添加目录结构说明 - 删除无用的 main.py 此变更使项目结构更清晰,便于区分核心代码与测试、文档等支撑文件。
31 lines
926 B
Python
31 lines
926 B
Python
"""使用 trafilatura 解析 HTML"""
|
|
|
|
from typing import Optional, Tuple
|
|
|
|
|
|
def parse(html_content: str) -> Tuple[Optional[str], Optional[str]]:
|
|
"""使用 trafilatura 解析 HTML"""
|
|
try:
|
|
import trafilatura
|
|
except ImportError:
|
|
return None, "trafilatura 库未安装"
|
|
|
|
try:
|
|
markdown_content = trafilatura.extract(
|
|
html_content,
|
|
output_format="markdown",
|
|
include_formatting=True,
|
|
include_links=True,
|
|
include_images=False,
|
|
include_tables=True,
|
|
favor_recall=True,
|
|
include_comments=True,
|
|
)
|
|
if markdown_content is None:
|
|
return None, "trafilatura 返回 None"
|
|
if not markdown_content.strip():
|
|
return None, "解析内容为空"
|
|
return markdown_content, None
|
|
except Exception as e:
|
|
return None, f"trafilatura 解析失败: {str(e)}"
|