Skip to content

新增 tools/fix_wrap.py:修复中文 txt 小说的错误换行 - #1

Open
JasonJarvan wants to merge 2 commits into
zouwen198317:masterfrom
JasonJarvan:fix-line-wrapping-tool
Open

新增 tools/fix_wrap.py:修复中文 txt 小说的错误换行#1
JasonJarvan wants to merge 2 commits into
zouwen198317:masterfrom
JasonJarvan:fix-line-wrapping-tool

Conversation

@JasonJarvan

Copy link
Copy Markdown

背景

仓库中不少 txt 小说为保持固定行宽,会在段落中间强行断行,同一段被拆成多行,在不同宽度的阅读器上显得杂乱。例如 阿里布达年代记.txt

  坐在垫着豹皮毯的大椅子上,我徐徐饮下红酒,让炽热酒液温暖胸膛,兼松
懈疲惫的身躯。

排版规律

  • 空行 = 段落分隔;
  • 段落首行(及标题、章节标题)以全角空格  (U+3000)缩进 / 居中;
  • 为控制行宽被硬折断的续行以全角空格开头。

本 PR

新增 tools/fix_wrap.pytools/README.md

  • 空行保留为段落分隔(连续空行折叠为一个);
  • 全角空格开头的行 → 新段落 / 标题,另起一行;
  • 其它行 → 硬折断续行,拼回上一段末尾;
  • 去掉所有段首缩进(含标题、章节标题)。

用法:

python tools/fix_wrap.py 阿里布达年代记.txt            # 输出到 *_fixed.txt
python tools/fix_wrap.py 阿里布达年代记.txt --in-place  # 原地覆盖(自动备份 .bak)

本 PR 仅新增工具脚本,不改动任何小说文件。

🤖 Generated with Claude Code

JasonJarvan and others added 2 commits July 11, 2026 01:28
Many txt novels hard-wrap paragraphs to keep a fixed line width, which
renders poorly across readers. This tool detects paragraph/title boundaries
by their full-width-space (U+3000) indentation, re-joins the hard-wrapped
continuation lines, and strips the leading indentation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…able

- fix_wrap.py: strip half-width/tab/full-width indentation on every line so
  paragraph indents are fully removed and per-line-space layouts rejoin cleanly;
  detect paragraph starts by U+3000 after optional leading spaces.
- reflow.py: companion tool for layouts fix_wrap can't handle — punctuation /
  speaker-based reflow (--drop-blank for mechanical blank lines), --strip-html
  for <div>-wrapped text, --mode lines for one-paragraph-per-line files.
- tools/format_status.md: per-file formatting-status manifest for the corpus.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant