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