aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/features/messages.js40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index dbbe05e..f2a3f8e 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -7514,11 +7514,12 @@ export function messagesFeature(ctx) {
// the first two plain links of a post (a wall of links is a list, not cards)
function notePreviewUrls(content) {
const urls = [];
- 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] : partUrl(part);
- if (url && !(md && md[1]) && previewable(url) && !PACK_LINK_RE.test(url)) urls.push(url);
+ const parts = String(content || '').split(NOTE_SPLIT);
+ for (let i = 1; i < parts.length && urls.length < 2; i += 2) {
+ const part = parts[i];
+ if (!part || MD_PARTS.test(part) || !linkAlone(parts, i)) continue; // a [label](url) is a link by its author's choice
+ const url = partUrl(part);
+ if (url && previewable(url) && !PACK_LINK_RE.test(url)) urls.push(url);
}
return urls;
}
@@ -8514,6 +8515,18 @@ export function messagesFeature(ctx) {
};
// 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);
+ // A link becomes a card (a page preview, a PAFF player) only standing on a
+ // line of its own. One in the middle of a sentence, or with punctuation
+ // after it, belongs to the sentence and stays a link ("can i also create a
+ // PR on <link>?" painted a big card between "on" and "?", Adam 2026-12-05).
+ // `parts` is a NOTE_SPLIT result: text at even indexes, matches at odd.
+ const linkAlone = (parts, i) => {
+ const part = parts[i] || '', before = parts[i - 1] ?? '', after = parts[i + 1] ?? '';
+ if (/^https?:\/\//i.test(part) ? /[.,;:!?'"]$|\)$(?<=^[^(]*)/.test(part) : bareLink(part)?.tail) return false;
+ if (before === '' ? i > 1 : !/(^|\n)[ \t]*$/.test(before)) return false;
+ if (after === '' ? i + 1 < parts.length - 1 : !/^[ \t]*(\n|$)/.test(after)) return false;
+ return true;
+ };
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');
@@ -11050,7 +11063,8 @@ export function messagesFeature(ctx) {
// A bio's links stay links: no page cards or PAFF players in a profile header.
let bareLinks = false;
const bareLinkBody = (text) => { bareLinks = true; try { return noteBody(text); } finally { bareLinks = false; } };
- function urlNode(url, { label = null, isImage = false, shown: written = null } = {}) {
+ function urlNode(url, { label = null, isImage = false, shown: written = null, card = true } = {}) {
+ if (bareLinks) card = false;
if (isVideoUrl(url)) {
return videoNode(url, { stable: !!feedPaint });
}
@@ -11084,7 +11098,7 @@ export function messagesFeature(ctx) {
});
}
if (youtubeId(url)) return youtubeEmbed(url, youtubeId(url));
- if (!label && !bareLinks && paffMusicUrl(url)) {
+ if (!label && card && paffMusicUrl(url)) {
let pv = previews.get(url) || null;
if (feedPaint) {
if (!feedPaint.media.has('pv:' + url)) feedPaint.media.set('pv:' + url, pv);
@@ -11092,7 +11106,7 @@ export function messagesFeature(ctx) {
}
return paffSongCard(url, pv);
}
- if (!label && !bareLinks && paffEmbedUrl(url)) {
+ if (!label && card && paffEmbedUrl(url)) {
let pv = previews.get(url) || null;
if (feedPaint) {
if (!feedPaint.media.has('pv:' + url)) feedPaint.media.set('pv:' + url, pv);
@@ -11100,7 +11114,7 @@ export function messagesFeature(ctx) {
}
return paffEmbed(url, pv);
}
- if (!label && !bareLinks && previewable(url)) {
+ if (!label && card && previewable(url)) {
// a frozen feed row keeps the card (or the bare link) it first painted
let pv = previews.get(url) || null;
if (feedPaint) {
@@ -11447,7 +11461,9 @@ export function messagesFeature(ctx) {
function noteBody(text, depth = 0, em = null) {
const out = [];
const emojiAt = em && em.size ? (c) => em.get(c) : null;
- for (const part of String(text || '').split(NOTE_SPLIT)) {
+ const parts = String(text || '').split(NOTE_SPLIT);
+ for (let i = 0; i < parts.length; i++) {
+ const part = parts[i];
if (!part) continue;
const md = MD_PARTS.exec(part);
if (md) {
@@ -11455,10 +11471,10 @@ export function messagesFeature(ctx) {
out.push(urlNode(url, { label: label || null, isImage: !!bang }));
} else if (/^https?:\/\//i.test(part)) {
const pack = PACK_LINK_RE.exec(part);
- out.push(pack ? packLinkNode(part, pack[1]) : urlNode(part));
+ out.push(pack ? packLinkNode(part, pack[1]) : urlNode(part, { card: linkAlone(parts, i) }));
} else if (bareLink(part)) {
const { url, text, tail } = bareLink(part);
- out.push(urlNode(url, { shown: text }));
+ out.push(urlNode(url, { shown: text, card: linkAlone(parts, i) }));
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)