truncate . #36

Merged
kibi merged 1 commits from master into 98 2026-07-28 20:06:46 +00:00

View File

@@ -1621,18 +1621,26 @@ class CommentSystem {
syncLevel(roots, list, false); syncLevel(roots, list, false);
} }
// Maximum characters to fully render in the item view per comment // Maximum characters & lines to fully render in the item view per comment
static get ITEM_VIEW_MAX_CHARS() { return 2000; } static get ITEM_VIEW_MAX_CHARS() { return 500; }
static get ITEM_VIEW_MAX_LINES() { return 6; }
renderCommentContent(content, commentId = null, bypassTruncation = false) { renderCommentContent(content, commentId = null, bypassTruncation = false) {
if (!content) return ''; if (!content) return '';
// Truncate extremely long comments before any processing // Truncate long comments before any processing
let truncated = false; let truncated = false;
if (!bypassTruncation && content.length > CommentSystem.ITEM_VIEW_MAX_CHARS) { if (!bypassTruncation) {
const lines = content.split('\n');
if (lines.length > CommentSystem.ITEM_VIEW_MAX_LINES) {
content = lines.slice(0, CommentSystem.ITEM_VIEW_MAX_LINES).join('\n');
truncated = true;
}
if (content.length > CommentSystem.ITEM_VIEW_MAX_CHARS) {
content = content.substring(0, CommentSystem.ITEM_VIEW_MAX_CHARS); content = content.substring(0, CommentSystem.ITEM_VIEW_MAX_CHARS);
truncated = true; truncated = true;
} }
}
if (typeof marked === 'undefined') { if (typeof marked === 'undefined') {
console.warn('Marked.js not loaded, falling back to plain text'); console.warn('Marked.js not loaded, falling back to plain text');
@@ -3600,9 +3608,9 @@ class CommentSystem {
// element whenever the raw content exceeds ITEM_VIEW_MAX_CHARS. Called after every // element whenever the raw content exceeds ITEM_VIEW_MAX_CHARS. Called after every
// optimistic DOM insert to guarantee the button regardless of rendering path. // optimistic DOM insert to guarantee the button regardless of rendering path.
_ensureTruncationButton(commentEl, rawContent) { _ensureTruncationButton(commentEl, rawContent) {
console.log('[ensureBtn] called, rawContent.length:', rawContent?.length, 'threshold:', CommentSystem.ITEM_VIEW_MAX_CHARS); if (!rawContent) return;
if (!rawContent || rawContent.length <= CommentSystem.ITEM_VIEW_MAX_CHARS) { const lineCount = rawContent.split('\n').length;
console.log('[ensureBtn] below threshold, skipping'); if (rawContent.length <= CommentSystem.ITEM_VIEW_MAX_CHARS && lineCount <= CommentSystem.ITEM_VIEW_MAX_LINES) {
return; return;
} }
const contentEl = commentEl.querySelector('.comment-content'); const contentEl = commentEl.querySelector('.comment-content');