Add comments to origin and reason for stripping of body

This commit is contained in:
Johannes Klein
2026-05-13 23:51:38 +02:00
parent 04669a4650
commit ddee3d7e9c

View File

@@ -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. "<p>Hello world</p>" => "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;