Skip to content

Commit 7fc69fc

Browse files
committed
v0.1.0 - fix: email ids getting highlighted as bsky username
1 parent 40e4772 commit 7fc69fc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ export const formatParagraph = (text: string): string => {
44
/\b((?:https?:\/\/)?(?:www\.)?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\/[a-zA-Z0-9._~:/?#\[\]@!$&'()*+,;=%-]*)?)|@[a-zA-Z0-9._]+/gi;
55

66
// Replace URLs with anchor tags
7-
let formattedText = text.replace(urlPattern, (url) => {
7+
let formattedText = text.replace(urlPattern, (url, _a, _b, index) => {
8+
9+
810
if (url.startsWith("@")) {
911
if (!url.includes(".")) {
1012
// Probably just random tag and not bsky profile
1113
return url;
1214
}
1315

16+
const charBeforeAt = index > 0 ? text.at(index - 1) : '';
17+
// if character before `@` is not white space or next line, then its probably email id
18+
const isEmail = charBeforeAt?.trim() !== '';
19+
20+
if (isEmail) {
21+
return url;
22+
}
23+
1424
const href = `https://bsky.app/profile/${url.slice(1)}`;
1525
// its a bluesky handle!!
1626
return `<a href="${href}" target="_blank" rel="noopener noreferrer">${url}</a>`;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bsky-widget",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Profile Card / Widget for Bluesky",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

0 commit comments

Comments
 (0)