From 7711115f1e2a7f8cd73017d548274d4fab9f3d86 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 22 Nov 2026 21:01:33 -0700 Subject: A web address written without https:// is a link. "Amethyst is able to render that link as a link, but we don't. So can we?" (Adam, 2026-11-22, Saturday Bitcoin's rally post a6cea731: "Join the rally: saturdaybitcoin.com/rally/1?utm_source=nostr&utm_campaign=rally1-announce"). Only text starting http(s):// was a link, so a bare address stayed plain text. A name ending in a TLD people link to (.com, .org, .io, .co.uk, …), with an optional port and path, is now a link to its https:// address, shown as written, with trailing sentence punctuation left as text, and it gets a preview card like any other link. Never the domain of an email or nip05 (an @ before it), anything inside a longer URL, or names like node.js, app.py, README.md, e.g. New bare-link-test passes; relay-link, link-preview, post-markdown and features-smoke pass (markdown-note-test fails the same way without this change). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6Upic5L6MMJzkTn8zg --- src/features/messages.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'src') 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 = '(? { + 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*)]+)>?[^)\\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); -- cgit v1.2.3