From ddee3d7e9c1f691a450c4eacdbe10b283f036b7f Mon Sep 17 00:00:00 2001 From: Johannes Klein Date: Wed, 13 May 2026 23:51:38 +0200 Subject: [PATCH] Add comments to origin and reason for stripping of body --- src/components/News/PostListItem.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/News/PostListItem.tsx b/src/components/News/PostListItem.tsx index 36a462449..af3475068 100644 --- a/src/components/News/PostListItem.tsx +++ b/src/components/News/PostListItem.tsx @@ -9,8 +9,11 @@ import React from "react"; import { formatDifferenceForHumans } from "sharedHelpers/dateAndTime"; import { useTranslation } from "sharedHooks"; -function stripHtmlForPreview( body: string ): string { - return body.replace( /<[^>]+>/g, " " ).replace( /\s+/g, " " ).trim( ); +// Similar to computeProperties in ExplorePost.m from iNaturalistIOS +function stripBodyForExcerpt( body: string ): string { + // Port of stringByStrippingHTML from NSString+Helpers.m from iNaturalistIOS + // /<[^>]+>/g matches anything between < and >, e.g. "

Hello world

" => "Hello world". + return body.replace( /<[^>]+>/g, "" ).replace( /\n/g, "" ).trim( ); } interface Props { @@ -27,7 +30,7 @@ const PostListItem = ( { } const excerpt = item.body - ? stripHtmlForPreview( item.body ) + ? stripBodyForExcerpt( item.body ) : ""; let bodyNumberOfLines = 3;