aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/messages.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/messages.js')
-rw-r--r--src/features/messages.js35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 0299c5f..2351e2b 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -7517,7 +7517,7 @@ export function messagesFeature(ctx) {
for (const part of String(content || '').split(NOTE_SPLIT)) {
if (!part || urls.length >= 2) continue;
const md = MD_PARTS.exec(part);
- const url = md ? md[3] : (/^https?:\/\//i.test(part) ? part : null);
+ const url = md ? md[3] : partUrl(part);
if (url && !(md && md[1]) && previewable(url) && !PACK_LINK_RE.test(url)) urls.push(url);
}
return urls;
@@ -7546,7 +7546,7 @@ export function messagesFeature(ctx) {
for (const part of String(content || '').split(NOTE_SPLIT)) {
if (!part) continue;
const md = MD_PARTS.exec(part);
- const url = md ? md[3] : (/^https?:\/\//i.test(part) ? part : null);
+ const url = md ? md[3] : partUrl(part);
if (!url) continue;
if ((md && md[1]) || /\.(png|jpe?g|gif|webp|avif)(\?[^\s]*)?$/i.test(url)) urls.push(url);
else if (youtubeId(url)) urls.push('https://i.ytimg.com/vi/' + youtubeId(url) + '/hqdefault.jpg');
@@ -7558,7 +7558,7 @@ export function messagesFeature(ctx) {
const urls = [];
for (const part of String(content || '').split(NOTE_SPLIT)) {
const md = part && MD_PARTS.exec(part);
- const url = md ? md[3] : (/^https?:\/\//i.test(part || '') ? part : null);
+ const url = md ? md[3] : partUrl(part);
if (url && !(md && md[1]) && isVideoUrl(url)) urls.push(url);
}
return urls;
@@ -8496,7 +8496,25 @@ export function messagesFeature(ctx) {
// A bare npub/nprofile — with or without an @ in front, no nostr: prefix —
// is how Vector (and people) write a mention; it resolves to the name too.
const BARE_KEY = '(?<![\\w/])@?(?:npub|nprofile)1[a-z0-9]{20,}(?![\\w])';
- const NOTE_SPLIT = new RegExp('(' + MD_LINK + '|https?:\\/\\/[^\\s]+|wss?:\\/\\/[^\\s]+|nostr:(?:npub|nprofile|note|nevent|naddr)1[a-z0-9]+|' + BARE_KEY + '|' + MENTION + '|' + HASHTAG + ')', 'gi');
+ // A web address written without its https:// ("Join the rally:
+ // saturdaybitcoin.com/rally/1?utm_source=nostr", Adam, 2026-11-22: Amethyst
+ // made it a link, we left it as text). Only names ending in a TLD people
+ // actually link to, so "node.js", "app.py", "e.g." and "README.md" stay
+ // words; never the domain of an email or nip05 (an @ or word sits before
+ // it) nor anything inside a longer URL (a / or : sits before it).
+ const BARE_TLDS = 'com|org|net|io|co|app|dev|me|xyz|info|biz|news|blog|tv|ai|gg|ly|fm|so|tech|site|online|store|shop|live|social|club|world|space|cloud|pub|wtf|lol|art|money|cash|finance|capital|network|chat|email|link|page|wiki|pro|academy|ca|us|uk|de|fr|nl|ch|at|be|es|it|pt|se|no|dk|fi|pl|cz|ie|eu|au|nz|jp|kr|in|br|mx|ar|cl|sv|za|ng|ke|ru|ua|tr|il|sg|hk|tw|cn|vc';
+ const BARE_URL = '(?<![\\w@./:#-])(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+(?:' + BARE_TLDS + ')(?![\\w-])(?::\\d{2,5})?(?:\\/[^\\s]*)?';
+ const BARE_URL_RE = new RegExp('^' + BARE_URL + '$', 'i');
+ // A bare address's href and what to show: trailing sentence punctuation
+ // stays text, as it does after a full URL in prose.
+ const bareLink = (part) => {
+ if (!part || /^https?:/i.test(part) || !BARE_URL_RE.test(part)) return null;
+ const [, addr, tail] = /^(.*?)([.,;:!?)\]'"]*)$/.exec(part);
+ return { url: 'https://' + addr, text: addr, tail };
+ };
+ // the https URL a split part stands for, written in full or bare
+ const partUrl = (part) => (/^https?:\/\//i.test(part || '') ? part : bareLink(part)?.url || null);
+ const NOTE_SPLIT = new RegExp('(' + MD_LINK + '|https?:\\/\\/[^\\s]+|wss?:\\/\\/[^\\s]+|nostr:(?:npub|nprofile|note|nevent|naddr)1[a-z0-9]+|' + BARE_KEY + '|' + MENTION + '|' + HASHTAG + '|' + BARE_URL + ')', 'gi');
const MD_PARTS = new RegExp('^(!?)\\[([^\\]\\n]{0,300})\\]\\(\\s*<?(https?:\\/\\/[^\\s>)]+)>?[^)\\n]{0,300}\\)$', 'i');
// A YouTube link is a video, so show the video. All three shapes it comes
@@ -11029,7 +11047,7 @@ export function messagesFeature(ctx) {
const x = e.clientX - (r.left + (r.width - w) / 2), y = e.clientY - (r.top + (r.height - hh) / 2);
return x >= 0 && x <= w && y >= 0 && y <= hh;
}
- function urlNode(url, { label = null, isImage = false } = {}) {
+ function urlNode(url, { label = null, isImage = false, shown: written = null } = {}) {
if (isVideoUrl(url)) {
return videoNode(url, { stable: !!feedPaint });
}
@@ -11088,7 +11106,8 @@ export function messagesFeature(ctx) {
}
if (pv) return linkCard(url, pv);
}
- const shown = label || (url.length > 64 ? url.slice(0, 61) + '…' : url);
+ const text = written || url;
+ const shown = label || (text.length > 64 ? text.slice(0, 61) + '…' : text);
return h('a', { href: url, target: '_blank', rel: 'noopener noreferrer' }, shown);
}
@@ -11434,6 +11453,10 @@ export function messagesFeature(ctx) {
} else if (/^https?:\/\//i.test(part)) {
const pack = PACK_LINK_RE.exec(part);
out.push(pack ? packLinkNode(part, pack[1]) : urlNode(part));
+ } else if (bareLink(part)) {
+ const { url, text, tail } = bareLink(part);
+ out.push(urlNode(url, { shown: text }));
+ if (tail) out.push(tail);
} else if (/^wss?:\/\//i.test(part)) {
// a relay named in a post opens what's on it (the raw firehose)
const [, addr, tail] = /^(.*?)([.,;:!?)\]'"]*)$/.exec(part);