1
This commit is contained in:
@@ -176,29 +176,30 @@
|
|||||||
}, 300);
|
}, 300);
|
||||||
});
|
});
|
||||||
// 英文截断处理
|
// 英文截断处理
|
||||||
// 处理 #rendered-content 内的内容
|
|
||||||
$('#rendered-content').html(function(i, html) {
|
$('#rendered-content').html(function(i, html) {
|
||||||
// 1. 先保护所有可能的空行格式
|
// 1. 先保护所有标签内的内容(包括标签内的 )
|
||||||
html = html.replace(/<(p|h[1-6])([^>]*)>(<[^>]+>)*\s*( )*\s*(<\/[^>]+>)*<\/\1>/gi, function(match) {
|
html = html.replace(/<[^>]+>[^<]*<\/[^>]+>/g, function(match) {
|
||||||
// 统一空行格式为 <p> </p> 形式
|
return match.replace(/</g, '___TAG_OPEN___')
|
||||||
var tag = match.match(/<(p|h[1-6])/i)[1];
|
.replace(/>/g, '___TAG_CLOSE___');
|
||||||
return '<' + tag + '> </' + tag + '>';
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. 只替换单词间的 (确保后面跟着字母或数字)
|
// 2. 替换非标签内容中的 为普通空格
|
||||||
html = html.replace(/ (?=[a-zA-Z0-9])/g, ' ');
|
html = html.replace(/ /g, ' ');
|
||||||
|
|
||||||
|
// 3. 恢复被保护的标签内容
|
||||||
|
html = html.replace(/___TAG_OPEN___/g, '<')
|
||||||
|
.replace(/___TAG_CLOSE___/g, '>');
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 添加CSS样式
|
// 添加CSS样式确保英文单词完整换行
|
||||||
$('#rendered-content').css({
|
$('#rendered-content').css({
|
||||||
'word-wrap': 'break-word',
|
'word-wrap': 'break-word',
|
||||||
'overflow-wrap': 'break-word',
|
'overflow-wrap': 'break-word',
|
||||||
'word-break': 'normal',
|
'word-break': 'normal',
|
||||||
'white-space': 'normal',
|
'white-space': 'normal',
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{/block}
|
{/block}
|
||||||
Reference in New Issue
Block a user