I have my own, silly Twitter alternative that I use for fun. When a user enters a URL in their comment, I want to make it clickable. I've tried this, and it correctly creates the anchor tag, but the link still isn't clickable.
This finds the URL and creates an anchor tag around it:
makeLinkWithinCommentClickable(comment: any) {
const hyperlink = (textContent) =>
textContent.replace(
/(https?:\/\/[^\s]+)/g,
(href) => `<a ng-href="${href}">${href}</a>`
);
comment.commentText = hyperlink(comment.commentText);
}
However, you can see it's just an anchor tag in plain text. How can I make it clickable?
I also tried wrapping the anchor in [code]...[/code], but that produced the same results.
This is Angular, and the HTML looks like this:
span{{comment.commentText}}/span
(The span has correct tags. Can't get it to display here.)