Skip to content

Commit

Permalink
LinkedText: fix torrent comment line break (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored Sep 29, 2023
1 parent 2b652f8 commit 7117764
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions client/src/javascript/components/general/LinkedText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ function isValidHttpUrl(s: string) {
}

const LinkedText: FC<LinkedTextProps> = ({text, className}: LinkedTextProps) => {
const nodes = text.split(/\s/).map((s) =>
isValidHttpUrl(s.trimEnd()) ? (
<a href={s.trimEnd()} target="_blank" rel="noopener noreferrer">
{s}
</a>
) : (
s
),
);
const nodes = text.split(/([ \n])/).map((s) => {
if (s === '\n') {
return <br />;
}
if (isValidHttpUrl(s)) {
return (
<a href={s.trimEnd()} target="_blank" rel="noopener noreferrer">
{s}
</a>
);
}
return s;
});

return <span className={className}>{nodes}</span>;
};
Expand Down

0 comments on commit 7117764

Please sign in to comment.