This commit is contained in:
2025-07-17 16:02:31 +08:00
parent 49ab384666
commit 85d02439fc

View File

@@ -176,16 +176,15 @@
}, 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*(&nbsp;)*\s*(<\/[^>]+>)*<\/\1>/gi, function(match) { html = html.replace(/<([a-zA-Z][a-zA-Z0-9]*)(?:\s+[^>]*)?>(?:\s*<[^>]+>\s*)*(&nbsp;| )*(?:\s*<\/[^>]+>\s*)*<\/\1>/g, function(match) {
// 统一空行格式为 <p>&nbsp;</p> 形式 // 统一格式为 <tag>&nbsp;</tag>
var tag = match.match(/<(p|h[1-6])/i)[1]; var tagName = match.match(/^<([a-zA-Z][a-zA-Z0-9]*)/)[1];
return '<' + tag + '>&nbsp;</' + tag + '>'; return '<' + tagName + '>&nbsp;</' + tagName + '>';
}); });
// 2. 替换单词间的 &nbsp;确保后面跟着字母或数字) // 2. 替换其他情况下的&nbsp;(后面跟着字母或数字)
html = html.replace(/&nbsp;(?=[a-zA-Z0-9])/g, ' '); html = html.replace(/&nbsp;(?=[a-zA-Z0-9])/g, ' ');
return html; return html;