This commit is contained in:
2025-07-17 15:13:01 +08:00
parent decc1e52dc
commit a46293e615

View File

@@ -173,28 +173,28 @@
}, 300); }, 300);
}); });
// 英文截断 // 英文截断
function processContent() { // function processContent() {
$('#rendered-content').html(function(i, html) { // $('#rendered-content').html(function(i, html) {
// 处理空行 // // 处理空行
html = html.replace(/(<(p|h[1-6]|div)[^>]*>)\s*(&nbsp;)*\s*(<\/\2>)/g, function(match, p1, p2, p3, p4) { // html = html.replace(/(<(p|h[1-6]|div)[^>]*>)\s*(&nbsp;)*\s*(<\/\2>)/g, function(match, p1, p2, p3, p4) {
return p1 + '&nbsp;' + p4; // return p1 + '&nbsp;' + p4;
}); // });
// 替换其他&nbsp;为普通空格,但保留数字后的&nbsp;(如版本号) // // 替换其他&nbsp;为普通空格,但保留数字后的&nbsp;(如版本号)
html = html.replace(/([^0-9])&nbsp;/g, '$1 '); // html = html.replace(/([^0-9])&nbsp;/g, '$1 ');
// 处理英文单词间的多个空格 // // 处理英文单词间的多个空格
html = html.replace(/([a-zA-Z])\s+([a-zA-Z])/g, '$1 $2'); // html = html.replace(/([a-zA-Z])\s+([a-zA-Z])/g, '$1 $2');
return html; // return html;
}); // });
// 添加CSS类而不是直接内联样式 // // 添加CSS类而不是直接内联样式
$('#rendered-content').addClass('word-wrap-optimized'); // $('#rendered-content').addClass('word-wrap-optimized');
} // }
// 初始处理 // // 初始处理
processContent(); // processContent();
// 如果内容是异步加载的可以在加载完成后调用processContent() // 如果内容是异步加载的可以在加载完成后调用processContent()
}); });