1
This commit is contained in:
@@ -176,41 +176,32 @@
|
||||
}, 300);
|
||||
});
|
||||
// 英文截断处理
|
||||
$('#rendered-content').html(function (i, html) {
|
||||
// 1. 先保护真正的空行(只包含 的标签)
|
||||
html = html.replace(/<(p|h[1-6])>(<strong>)?( | )*(<\/strong>)?<\/\1>/g, function (match) {
|
||||
// 统一空行格式为 <p> </p> 或 <h2> </h2> 形式
|
||||
return match.replace(/(<p>|<h[1-6]>)\s*(<strong>)?\s*( | )*\s*(<\/strong>)?\s*(<\/p>|<\/h[1-6]>)/,
|
||||
function (m) {
|
||||
var tag = m.match(/<(p|h[1-6])>/)[1];
|
||||
return '<' + tag + '> </' + tag + '>';
|
||||
});
|
||||
// 处理 #rendered-content 内的内容
|
||||
$('#rendered-content').html(function(i, html) {
|
||||
// 1. 先保护所有可能的空行格式
|
||||
html = html.replace(/<(p|h[1-6])([^>]*)>(<[^>]+>)*\s*( )*\s*(<\/[^>]+>)*<\/\1>/gi, function(match) {
|
||||
// 统一空行格式为 <p> </p> 形式
|
||||
var tag = match.match(/<(p|h[1-6])/i)[1];
|
||||
return '<' + tag + '> </' + tag + '>';
|
||||
});
|
||||
// 2. 替换其他 为普通空格(保留单词间的空格)
|
||||
html = html.replace(/ (?=\w)/g, ' ');
|
||||
|
||||
// 2. 只替换单词间的 (确保后面跟着字母或数字)
|
||||
html = html.replace(/ (?=[a-zA-Z0-9])/g, ' ');
|
||||
|
||||
return html;
|
||||
});
|
||||
|
||||
// 添加CSS样式确保英文单词完整换行
|
||||
// 添加CSS样式
|
||||
$('#rendered-content').css({
|
||||
'word-wrap': 'break-word',
|
||||
'overflow-wrap': 'break-word',
|
||||
'word-break': 'normal',
|
||||
'white-space': 'normal'
|
||||
'white-space': 'normal',
|
||||
'line-height': '1.6'
|
||||
});
|
||||
|
||||
// 优化英文单词间的空格处理
|
||||
$('#rendered-content').find('p, h1, h2, h3, h4, h5, h6').each(function () {
|
||||
var $el = $(this);
|
||||
// 只处理非空行
|
||||
if ($el.html().trim() !== ' ') {
|
||||
var html = $el.html()
|
||||
.replace(/([a-zA-Z])( | )+([a-zA-Z])/g, '$1 $3') // 单词间保留一个空格
|
||||
.replace(/(\d)( | )+([a-zA-Z])/g, '$1 $3') // 数字和单词间
|
||||
.replace(/([a-zA-Z])( | )+(\d)/g, '$1 $3'); // 单词和数字间
|
||||
$el.html(html);
|
||||
}
|
||||
});
|
||||
// 优化段落间距
|
||||
$('#rendered-content p').css('margin-bottom', '1em');
|
||||
});
|
||||
</script>
|
||||
{/block}
|
||||
Reference in New Issue
Block a user