This commit is contained in:
2025-07-17 15:18:38 +08:00
parent 5221b43c01
commit 0e0ed64b38

View File

@@ -173,30 +173,44 @@
}, 300); }, 300);
}); });
// 英文截断 // 英文截断
// function processContent() { // 处理 #rendered-content 内的内容
// $('#rendered-content').html(function(i, html) { $('#rendered-content').html(function(i, html) {
// // 处理空行 // 1. 先保护真正的空行(只包含 的标签)
// 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])>(<strong>)?(&nbsp;| )*(<\/strong>)?<\/\1>/g, function(match) {
// return p1 + '&nbsp;' + p4; // 统一空行格式为 <p>&nbsp;</p> 或 <h2>&nbsp;</h2> 形式
// }); return match.replace(/(<p>|<h[1-6]>)\s*(<strong>)?\s*(&nbsp;| )*\s*(<\/strong>)?\s*(<\/p>|<\/h[1-6]>)/,
function(m) {
var tag = m.match(/<(p|h[1-6])>/)[1];
return '<' + tag + '>&nbsp;</' + tag + '>';
});
});
// // 替换其他&nbsp;为普通空格,但保留数字后的&nbsp;(如版本号) // 2. 替换其他&nbsp;为普通空格(保留单词间的空格)
// html = html.replace(/([^0-9])&nbsp;/g, '$1 '); html = html.replace(/&nbsp;(?=\w)/g, ' ');
// // 处理英文单词间的多个空格 return html;
// html = html.replace(/([a-zA-Z])\s+([a-zA-Z])/g, '$1 $2'); });
// return html; // 添加CSS样式确保英文单词完整换行
// }); $('#rendered-content').css({
'word-wrap': 'break-word',
'overflow-wrap': 'break-word',
'word-break': 'normal',
'white-space': 'normal'
});
// // 添加CSS类而不是直接内联样式 // 优化英文单词间的空格处理
// $('#rendered-content').addClass('word-wrap-optimized'); $('#rendered-content').find('p, h1, h2, h3, h4, h5, h6').each(function() {
// } var $el = $(this);
// 只处理非空行
// // 初始处理 if ($el.html().trim() !== '&nbsp;') {
// processContent(); var html = $el.html()
.replace(/([a-zA-Z])(&nbsp;| )+([a-zA-Z])/g, '$1 $3') // 单词间保留一个空格
// 如果内容是异步加载的可以在加载完成后调用processContent() .replace(/(\d)(&nbsp;| )+([a-zA-Z])/g, '$1 $3') // 数字和单词间
.replace(/([a-zA-Z])(&nbsp;| )+(\d)/g, '$1 $3'); // 单词和数字间
$el.html(html);
}
});
}); });
</script> </script>
{/block} {/block}