Skip to content

Commit

Permalink
Fix urls conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloalba committed Jul 21, 2023
1 parent b5c28ca commit 2be8adf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions api/templates/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ <h2>{{section.subtitle}}</h2>
const texts = document.getElementsByClassName('tm-text');
for (const text of texts) {
// Regular expression to match web addresses in the text
const webAddressRegex = /(https?:\/\/[^\s]+)/g;
//const webAddressRegex = /(https?:\/\/[^\s]+)/g;
const webAddressRegex = /(https?:\/\/\S+)|\((https?:\/\/\S+)\)/g;

// Replace web addresses with clickable links
text.innerHTML = text.innerHTML.replace(
webAddressRegex,
'<a href="$1" target="_blank">$1</a>'
(match, url1, url2) => {
const url = url1 || url2;
return `<a href="${url}" target="_blank">${url}</a>`;
}
);
}
}
Expand Down

0 comments on commit 2be8adf

Please sign in to comment.