This commit is contained in:
2025-07-17 16:27:14 +08:00
parent 6925061380
commit 7e66a9ecfb

View File

@@ -175,28 +175,28 @@
}) })
}, 300); }, 300);
}); });
// 英文截断处理 // // 英文截断处理
$('#rendered-content').html(function(i, html) { // $('#rendered-content').html(function(i, html) {
// 1. 保护只包含 的标签(包括嵌套情况) // // 1. 保护只包含 的标签(包括嵌套情况)
html = html.replace(/<([a-zA-Z][a-zA-Z0-9]*)(?:\s+[^>]*)?>(?:\s*<[^>]+>\s*)*(&nbsp;| )*(?:\s*<\/[^>]+>\s*)*<\/\1>/g, function(match) { // html = html.replace(/<([a-zA-Z][a-zA-Z0-9]*)(?:\s+[^>]*)?>(?:\s*<[^>]+>\s*)*(&nbsp;| )*(?:\s*<\/[^>]+>\s*)*<\/\1>/g, function(match) {
// 统一格式为 <tag>&nbsp;</tag> // // 统一格式为 <tag>&nbsp;</tag>
var tagName = match.match(/^<([a-zA-Z][a-zA-Z0-9]*)/)[1]; // var tagName = match.match(/^<([a-zA-Z][a-zA-Z0-9]*)/)[1];
return '<' + tagName + '>&nbsp;</' + tagName + '>'; // 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;
}); // });
// 添加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>