文件
gpt_academic/crazy_functions/paper_fns/file2file_doc/markdown_doc.py
binary-husky 8042750d41 Master 4.0 (#2210)
* stage academic conversation

* stage document conversation

* fix buggy gradio version

* file dynamic load

* merge more academic plugins

* accelerate nltk

* feat: 为predict函数添加文件和URL读取功能
- 添加URL检测和网页内容提取功能,支持自动提取网页文本
- 添加文件路径识别和文件内容读取功能,支持private_upload路径格式
- 集成WebTextExtractor处理网页内容提取
- 集成TextContentLoader处理本地文件读取
- 支持文件路径与问题组合的智能处理

* back

* block unstable

---------

Co-authored-by: XiaoBoAI <liuboyin2019@ia.ac.cn>
2025-08-23 15:59:22 +08:00

41 行
1.3 KiB
Python

class MarkdownFormatter:
"""Markdown格式文档生成器 - 保留原始文档结构"""
def __init__(self):
self.content = []
def _add_content(self, text: str):
"""添加正文内容"""
if text:
self.content.append(f"\n{text}\n")
def create_document(self, content: str, processing_type: str = "文本处理") -> str:
"""
创建完整的Markdown文档,保留原始文档结构
Args:
content: 处理后的文档内容
processing_type: 处理类型(润色、翻译等)
Returns:
str: 生成的Markdown文本
"""
self.content = []
# 添加标题和说明
self.content.append(f"# 文档处理结果\n")
self.content.append(f"## 处理方式: {processing_type}\n")
# 添加处理时间
from datetime import datetime
self.content.append(f"*处理时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}*\n")
# 添加分隔线
self.content.append("---\n")
# 添加原始内容,保留结构
self.content.append(content)
# 添加结尾分隔线
self.content.append("\n---\n")
return "\n".join(self.content)