125续15l-10:成书章节粘连改回找最近标题(末行非标题也能粘)
Auto Release / build (push) Successful in 4m20s

This commit is contained in:
youpaishidifu
2026-11-20 11:56:17 +08:00
parent 39683f1af0
commit 188b0775ae
+13 -23
View File
@@ -428,24 +428,20 @@ public class RulesCLIManager implements Listener {
int addLen = seg.length() + 1;
if (curLen + addLen > pageSize && cur.length() > 0) {
String curText = cur.toString().trim();
// 下一页首段是否"条目型"(bullet / 编号 / 章节标题)
boolean nextIsEntry = seg.startsWith("- ") || seg.matches("^\\d+\\..*")
|| seg.matches("^#{1,6}\\s.*") || seg.matches("^第[一二三四五六七八九十]+、.*");
if (nextIsEntry) {
// 回找当前页内最近一个章节标题行(# / ### / N. / 第X、),把它移到下一页
// ★ 125 续15l-10:章节粘连放宽——不依赖「下一页首段是否条目」(清洗后 bullet 已无 "- " 前缀),
// 改为「当前页末段是章节标题(N. / 第X、 / ###)且剩余空间装不下下一条」时,
// 把该标题整行移到下一页,让标题与下属条目同页,避免玩家翻页看到孤儿条目
String[] curLines = curText.split("\n");
int titleIdx = -1;
for (int li = curLines.length - 1; li >= 0; li--) {
String t = curLines[li].trim();
if (t.matches("^#{1,6}\\s.*") || t.matches("^\\d+\\.\\s.*")
|| t.matches("^第[一二三四五六七八九十]+、.*")) {
titleIdx = li;
break;
}
}
if (titleIdx >= 0 && curLines.length > 1) {
int lastIdx = curLines.length - 1;
String lastLine = curLines[lastIdx].trim();
boolean lastIsTitle = lastLine.matches("^\\d+\\.\\s.*")
|| lastLine.matches("^#{1,6}\\s.*")
|| lastLine.matches("^第[一二三四五六七八九十]+、.*")
|| lastLine.matches("^[一二三四五六七八九十]+、.*");
if (lastIsTitle && curLines.length > 1) {
// 当前页末段是标题 → 把标题移到下一页(标题后空一行),正文封当前页
StringBuilder pageBody = new StringBuilder();
for (int li = 0; li < titleIdx; li++) {
for (int li = 0; li < lastIdx; li++) {
if (!curLines[li].trim().isEmpty()) {
pageBody.append(curLines[li]).append('\n');
}
@@ -454,8 +450,7 @@ public class RulesCLIManager implements Listener {
if (!bodyText.isEmpty()) {
pages.add(bodyText);
}
// 新页 = 最近标题 + 空行(让标题与后续条目之间有间隔)
String movedTitle = curLines[titleIdx].trim();
String movedTitle = lastLine;
cur.setLength(0);
cur.append(movedTitle).append("\n\n");
curLen = movedTitle.length() + 2;
@@ -464,11 +459,6 @@ public class RulesCLIManager implements Listener {
cur.setLength(0);
curLen = 0;
}
} else {
pages.add(curText);
cur.setLength(0);
curLen = 0;
}
}
cur.append(seg).append('\n');
curLen += addLen;