INNER CODE UNIT · Python
extract_content_from_chapter
voocel/ainovel-cli · scripts/check_chapter_wordcount.py:32
def extract_content_from_chapter(file_path: Path) -> str:
"""从章节文件中提取正文内容(排除标题等元数据)"""
content = file_path.read_text(encoding='utf-8')
lines = content.split('\n')
content_start = 0
for i, line in enumerate(lines):
if line.startswith('#') and '章' in line:
content_start = i + 1
break
return '\n'.join(lines[content_start:])
def check_chapter(file_path: str, min_words: int = 3000) -> dict:
"""检查单个章节的字数"""
path = Path(file_path)
if not path.exists():