@cloud411716/fancy-webnovel 4.26.1 → 4.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -149,55 +149,41 @@ export function sanitizeBookFields(book) {
149
149
  * 番茄/晋江/七猫的"简介"没有冒号(不像 `**标签:**` 那样一眼看出是字段),
150
150
  * 而且简介前多一个空行,跟前面的字段行断开了。
151
151
  *
152
- * 统一成一个无序列表项(2026-11-05 调整):
152
+ * 统一成一个无序列表项(2026-11-05 调整,2026-11-25 压缩空行):
153
153
  *
154
- * - **简介:** 首段
155
- *
156
- * 第二段
154
+ * - **简介:** 首段
155
+ * 第二段
156
+ * 第三段
157
157
  *
158
158
  * 规则:
159
159
  * - 简介本身是一个 `- ` 列表项,和作者/状态/在读等字段同一层级;
160
- * - 单换行 = 段内硬换行(行尾两个空格),四个平台统一;
161
- * - 空行 = 段落分隔,用缩进 + 空行留在同一个列表项里;
162
- * - **每段首尾的空白字符都去掉**(半角空格 / 全角空格 / 换行)。
160
+ * - 连续空行(两个及以上换行,包括只含空格/全角空格的空行)一律压成单换行;
161
+ * - 每一行都用行尾两个空格做硬换行,简介内部不出现空行;
162
+ * - **每行首尾的空白字符都去掉**(半角空格 / 全角空格 / 换行)。
163
163
  *
164
164
  * @param {string|string[]} raw - 简介正文,或已切好的段落数组
165
165
  * @returns {string[]} markdown 行;没有简介时返回空数组
166
166
  */
167
167
  export function renderIntroLines(raw) {
168
- const source = Array.isArray(raw)
169
- ? raw
170
- : String(raw == null ? '' : raw)
171
- .replace(/\r\n?/g, '\n')
172
- // 只有空行(允许空行里夹空格/全角空格)才是段落分隔
173
- .replace(/\n[ \t ]*\n/g, '\n\n')
174
- .split(/\n{2,}/);
175
- const paras = source
176
- // 去掉每段首尾的空白字符:\s 已含全角空格 U+3000,这里再写一遍是防它被漏
177
- .map(p => String(p).replace(/^[\s ]+|[\s ]+$/g, ''))
168
+ const source = Array.isArray(raw) ? raw.join('\n') : String(raw == null ? '' : raw);
169
+ const parts = source
170
+ .replace(/\r\n?/g, '\n')
171
+ // 连续空行(含只含半角空格/制表符/全角空格的行)压成单换行。
172
+ // 四个平台都会把作者原文的段落分隔保留成 \n\n,这里统一成逐行硬换行。
173
+ .replace(/\n(?:[ \t ]*\n)+/g, '\n')
174
+ .split('\n')
175
+ .map((line) => sanitizeMarkdownLine(line.trim()))
178
176
  .filter(Boolean);
179
- if (!paras.length) return [];
177
+ if (!parts.length) return [];
180
178
 
181
- // 简介本身是列表项;段落之间用空行 + 两格缩进,段落内部的单换行
182
- // (番茄/起点的 <br> 转出来的)用两个尾随空格做硬换行。
179
+ // 简介本身是列表项;第一行紧跟标签,后续行用两个尾随空格做硬换行。
183
180
  const lines = [];
184
- let first = true;
185
- for (const para of paras) {
186
- const parts = String(para)
187
- .split('\n')
188
- .map((line) => sanitizeMarkdownLine(line.trim()))
189
- .filter(Boolean);
190
- for (let i = 0; i < parts.length; i += 1) {
191
- const text = parts[i];
192
- if (first) {
193
- lines.push('- **简介:** ' + text);
194
- first = false;
195
- } else if (i === 0) {
196
- lines.push('', ' ' + text);
197
- } else {
198
- lines[lines.length - 1] += ' ';
199
- lines.push(' ' + text);
200
- }
181
+ for (const text of parts) {
182
+ if (!lines.length) {
183
+ lines.push('- **简介:** ' + text);
184
+ } else {
185
+ lines[lines.length - 1] += ' ';
186
+ lines.push(' ' + text);
201
187
  }
202
188
  }
203
189
  return lines;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "4.26.1",
3
+ "version": "4.26.2",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -363,17 +363,9 @@ function renderQidianMarkdown(rankLabel, url, books) {
363
363
  lines.push(`- **打赏:** 今日 ${t} / 本周 ${w}`);
364
364
  }
365
365
  if (b.intro) {
366
- // 格式与其它字段保持一致:首段紧跟标签,其余行各自缩进。
367
- //
368
- // 起点桌面页的 #book-intro-detail 会把作者原文里的 \n\n 段落压成
369
- // 单个 <br>。例如《凡人:聚宝盆里出灵石》的移动端 desc 每句之间都是
370
- // \n\n,但 https://www.qidian.com/book/1051335496/ 页面上只换行、不空行。
371
- // 扫描结果以页面展示为准,先把段间空行压成单换行,再交给公共渲染函数,
372
- // 这样简介只会出现段内硬换行,不会多出空行。
373
- const intro = (Array.isArray(b.intro) ? b.intro.join('\n') : String(b.intro))
374
- .replace(/\r\n?/g, '\n')
375
- .replace(/\n(?:[ \t ]*\n)+/g, '\n');
376
- lines.push(...renderIntroLines(intro));
366
+ // 简介和其他字段一样是 `- ` 列表项;连续空行由公共渲染函数
367
+ // 统一压成单换行,四个平台保持一致。
368
+ lines.push(...renderIntroLines(b.intro));
377
369
  }
378
370
  if (b.url) lines.push(`- [作品页](${b.url})`);
379
371
  lines.push('', '---', '');
@@ -832,9 +832,9 @@ function buildMarkdown(catName, books) {
832
832
  if (b.wordCount) lines.push(`- **字数:** ${b.wordCount}`);
833
833
  if (b.tags && b.tags.length) lines.push(`- **标签:** ${b.tags.join('、')}`);
834
834
  if (b.rankChange) lines.push(`- **排名变动:** ${b.rankChange}`);
835
- // 简介和其他字段一样是 `- ` 列表项;单换行用硬换行,空行才是段落分隔。
836
- // 之前是「空行 + `**简介**` + 简介整块」—— 没有冒号,且和上下文粘成一段,
837
- // 而且简介首尾的空白字符原样留在文件里。
835
+ // 简介和其他字段一样是 `- ` 列表项;连续空行由公共渲染函数压成单换行,
836
+ // 每行用硬换行保留。之前是「空行 + `**简介**` + 简介整块」—— 没有冒号,
837
+ // 且和上下文粘成一段,而且简介首尾的空白字符原样留在文件里。
838
838
  lines.push(...renderIntroLines(b.desc || ''));
839
839
  if (b.url) lines.push(`- [作品页](https://fanqienovel.com${b.url})`);
840
840
  lines.push('');
@@ -191,8 +191,8 @@ async function extractRankData(page, columns = {}) {
191
191
  * 1. **积分不带千分位逗号**:晋江榜单页写的是 "1,099,899,136",
192
192
  * 存成纯数字,下游才好比较/求和,模型抄数字时也不会把逗号抄进去
193
193
  * ("327,650,784" 和 "327650784" 在模型的算术里不是一回事);
194
- * 2. **简介是 `- ` 列表项**:单换行用硬换行保留,空行才是段落分隔;
195
- * 每段首尾无空白,作品页也单独作为一个列表项。
194
+ * 2. **简介是 `- ` 列表项**:连续空行压成单换行,每行用硬换行保留;
195
+ * 每行首尾无空白,作品页也单独作为一个列表项。
196
196
  *
197
197
  * @param {object} b - 一本书
198
198
  * @returns {string[]} markdown 行
@@ -207,9 +207,9 @@ export function renderBookLines(raw) {
207
207
  // 积分是 10 亿级的,榜单页必带千分位逗号 —— 写盘前去掉。
208
208
  if (b.score) lines.push(`- **积分:** ${stripThousands(b.score)}`);
209
209
  if (b.tags && b.tags.length) lines.push(`- **标签:** ${b.tags.join('、')}`);
210
- // 简介和其他字段一样是 `- ` 列表项;单换行用硬换行,空行才是段落分隔。
211
- // 之前是「空行 + `**简介**` + 简介整块」—— 没有冒号,且和上下文粘成一段,
212
- // 而且简介首尾的空白字符原样留在文件里。
210
+ // 简介和其他字段一样是 `- ` 列表项;连续空行由公共渲染函数压成单换行,
211
+ // 每行用硬换行保留。之前是「空行 + `**简介**` + 简介整块」—— 没有冒号,
212
+ // 且和上下文粘成一段,而且简介首尾的空白字符原样留在文件里。
213
213
  lines.push(...renderIntroLines(b.intro || ''));
214
214
  if (b.novelid) lines.push(`- [作品页](https://www.jjwxc.net/onebook.php?novelid=${b.novelid})`);
215
215
  return lines;
@@ -408,9 +408,9 @@ function renderMarkdown(ch, rt, period, url, books, rawCount, now = new Date().t
408
408
  if (b.status) lines.push(`- **状态:** ${b.status}`);
409
409
  if (b.words) lines.push(`- **字数:** ${b.words}`);
410
410
  if (b.heat) lines.push(`- **热度:** ${b.heat}`);
411
- // 简介和其他字段一样是 `- ` 列表项;单换行用硬换行,空行才是段落分隔。
412
- // 之前是「空行 + `**简介**` + 分段」—— 没有冒号、前后多一个空行,
413
- // 而且段首尾的空白字符原样留在文件里。
411
+ // 简介和其他字段一样是 `- ` 列表项;连续空行由公共渲染函数压成单换行,
412
+ // 每行用硬换行保留。之前是「空行 + `**简介**` + 分段」—— 没有冒号、
413
+ // 前后多一个空行,而且段首尾的空白字符原样留在文件里。
414
414
  lines.push(...renderIntroLines(cleanDesc(b.desc)));
415
415
  // 作品页链接放在简介之后,与起点/番茄/晋江产物保持同一字段顺序。
416
416
  if (b.url) lines.push(`- [作品页](${b.url})`);