fix(home): preserve popular thread preview markers

This commit is contained in:
Tommaso Casaburi
2026-04-30 00:32:45 +07:00
parent b0219fe6b1
commit c7b5f6e2c5
2 changed files with 22 additions and 2 deletions
@@ -138,6 +138,26 @@ describe('PopularThreadsBox', () => {
expect(container.textContent).toContain('thread title');
});
it('preserves literal preview markers without applying body markdown styles', () => {
testState.popularPosts = [
{
cid: 'thread-markers',
communityAddress: 'music-posting.eth',
content: '>we got 5chan before Half Life 3\n*poisons u*',
link: 'https://cdn.example/thread-markers.jpg',
thumbnailUrl: 'https://cdn.example/thread-markers-thumb.jpg',
title: '',
},
];
renderPopularThreadsBox();
expect(container.textContent).toContain('>we got 5chan before Half Life 3');
expect(container.textContent).toContain('*poisons u*');
expect(container.querySelector('.greentext')).toBeNull();
expect(container.querySelector('.spoilertext')).toBeNull();
});
it('subscribes to feed state only while popular threads are loading', () => {
testState.isLoading = true;
testState.popularPosts = [];
@@ -14,7 +14,7 @@ import { DirectoryCommunity, findDirectoryByAddress } from '../../../hooks/use-d
import { useCommunityIdentifiers } from '../../../hooks/use-community-identifiers';
import { getCommentCommunityAddress } from '../../../lib/utils/comment-utils';
import { getBoardPath } from '../../../lib/utils/route-utils';
import { removeMarkdown } from '../../../lib/utils/post-utils';
import { CATALOG_PREVIEW_MARKDOWN_OPTIONS, removeMarkdown } from '../../../lib/utils/post-utils';
interface PopularThreadProps {
post: Comment;
@@ -30,7 +30,7 @@ const PopularThreadsLoading = ({ boardAddresses }: { boardAddresses: string[] })
};
const ContentPreview = ({ content, maxLength = 99 }: { content: string; maxLength?: number }) => {
const plainText = removeMarkdown(content).trim().replaceAll(' ', '').replace(/\n\n/g, '\n').replaceAll('\n\n', '');
const plainText = removeMarkdown(content, CATALOG_PREVIEW_MARKDOWN_OPTIONS).trim().replaceAll(' ', '').replace(/\n\n/g, '\n').replaceAll('\n\n', '');
const truncatedText = plainText.length > maxLength ? `${plainText.substring(0, maxLength).trim()}...` : plainText;
return truncatedText;