fix(web): clean web-page markup out of TXT chapters before typesetting

Novels saved from a site keep the page's <div>, <br/> and &nbsp; in the
TXT. Escaped, the tags were drawn as text and the chapter ran together
as one paragraph. cleanTextMarkup turns block tags into line breaks,
drops inline tags, decodes common entities and treats whitespace-only
lines as blank, before paragraphs and the chapter heading are inferred.
Only real tag names match; other markup is still escaped as text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hectorqinandClaude Opus 5.5 committed 2026-10-29 05:51:18 +00:00
1 parent f58a171920
commit 52b757bbd3
4 files changed
+97 -8

No files matched your search

+5
View File
@@ -599,6 +599,11 @@ TXT 是唯一一种**没有作者排版**的书,所以它也是唯一一处「
传输看起来不一样。它同时负责**去掉段前空格**(`  正文` 里那个全角空格是
「段前空格」的来源,留着就是和读者的缩进**叠加**),以及**章节标题行提升成
`<h3>`**(`splitChapterHeading`,否则正文会变成 `第二章 落雨雨来了。`)。
分段之前先过 `cleanTextMarkup`:从网页另存的 TXT 常带着 `<div>`、`<br/>`、
`&nbsp;`,原样转义就会把标签画成文字、每个 `<br/>` 行都成一段空白。块级标签
(`br`/`p`/`div`/标题/列表项)换成换行、行内标签(`span`/`font`/`b`…)去掉、
常见实体解码、只有空白的行算空行;只认真实的标签名,正文里的 `a<b`、`<书名>`
不动,其余标签照旧转义成文字。
`ReaderView` 在 `retypePlainText` 里对拿到的章节过这一段逻辑;如果内容带着
历史的 `.txt-body` 标记(旧服务端、旧缓存),就按块读回文本再拆,所以旧
响应不会被当成新响应渲染。