Skip to content

Commit 1fafc6d

Browse files
committed
优化text下载的内容
1 parent 5985421 commit 1fafc6d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

server/api/public/v1/download.get.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ function normalizeHtml(rawHTML: string, format: 'html' | 'text' = 'html'): strin
8888

8989
if (format === 'text') {
9090
// 获取纯文本内容
91-
return $jsArticleContent.text().trim();
91+
const text = $jsArticleContent.text().trim().replace(/\n+/g, '\n').replace(/ +/g, ' ');
92+
// 分割成行
93+
const lines = text.split('\n');
94+
// 过滤掉全空白行(^\s*$ 表示行首到行尾全是空白字符)
95+
const filteredLines = lines.filter(line => !/^\s*$/.test(line));
96+
97+
// 重新连接行
98+
return filteredLines.join('\n');
9299
} else if (format === 'html') {
93100
// 获取修改后的 HTML
94101
let bodyCls = $('body').attr('class');

0 commit comments

Comments
 (0)