Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion apps/app/src/components/comments/CommentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ type PendingAttachment = {
signedUrl: string;
};

function renderContentWithLinks(text: string): React.ReactNode[] {
const regex = /(https?:\/\/[^\s]+|www\.[^\s]+|(?<!@)(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(?:\/[^\s]*)?)/gi;
return text.split(regex).map((part, index) => {
if (/^(https?:\/\/[^\s]+|www\.[^\s]+|(?<!@)(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(?:\/[^\s]*)?)$/i.test(part)) {
const href = /^https?:\/\//i.test(part) ? part : `https://${part}`;
return (
<a
key={index}
href={href}
target="_blank"
rel="noopener noreferrer"
className="text-primary underline"
>
{part}
</a>
);
}
return part;
});
}

export function CommentItem({ comment }: { comment: CommentWithAuthor }) {
const [isEditing, setIsEditing] = useState(false);
const [editedContent, setEditedContent] = useState(comment.content);
Expand Down Expand Up @@ -279,7 +300,9 @@ export function CommentItem({ comment }: { comment: CommentWithAuthor }) {
</div>

{!isEditing ? (
<p className="whitespace-pre-wrap">{comment.content}</p>
<p className="whitespace-pre-wrap break-words">
{renderContentWithLinks(comment.content)}
</p>
) : (
<Textarea
value={editedContent}
Expand Down
Loading