aboutsummaryrefslogtreecommitdiffstats
path: root/src/features
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-09 21:48:11 -0700
committerAdam Soltys <[email protected]>2026-10-09 21:48:11 -0700
commitfaec1f84ed1e9e8ee78055796a8ebc92936abe9d (patch)
tree4d31820e4b1fd762ca40727711ee1ab365bf201f /src/features
parent75ca3da7f87846f26743d0c27afc90d9f0d19a7c (diff)
downloadcoinosv3-faec1f84ed1e9e8ee78055796a8ebc92936abe9d.tar.gz
coinosv3-faec1f84ed1e9e8ee78055796a8ebc92936abe9d.zip
Posts: inline markdown. **bold** / __bold__, *italic* / _italic_, ***both***, ~~struck~~ and `code` render in a post's plain text — what newsletter bots and Amethyst users type and Amethyst shows; we showed the asterisks. Strict about edges, so snake_case, x__init__y, 2*3*4, "$5 * 2" and a lone star stay as typed, and markers never reach across a link, mention or hashtag. No headings or lists in posts: "#" at a line's start is a hashtag here, and articles render their own headings. tools/post-markdown-test.js
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vps2H27rhbG9ZqseGfMrc3
Diffstat (limited to 'src/features')
-rw-r--r--src/features/messages.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index c803d4d..06371cf 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -8016,6 +8016,30 @@ export function messagesFeature(ctx) {
// `em` is the event's own ["emoji", code, url] map (NIP-30): a :code: it
// names becomes its picture, any other :code: stays text — a message
// never borrows pictures from packs the READER happens to hold.
+ // Inline markdown in a post's plain text, the subset people actually type
+ // and Amethyst already shows: **bold** / __bold__, *italic* / _italic_,
+ // ~~struck~~ and `code`. Strict about edges so snake_case, 2*3*4 and a lone
+ // asterisk stay as typed; markers never reach across a link, mention or
+ // hashtag (those are split out first). No headings or lists in posts —
+ // "#" at a line's start is a hashtag here, and articles have their own.
+ const MD_INLINE = /(`[^`\n]+`)|(\*\*\*(?=\S)[^\n]*?\S\*\*\*)|(\*\*(?=\S)[^\n]*?\S\*\*)|((?<![\p{L}\p{N}_])__(?=\S)[^\n]*?\S__(?![\p{L}\p{N}_]))|(~~(?=\S)[^\n]*?\S~~)|((?<![\p{L}\p{N}*])\*(?=[^\s*])[^*\n]*?[^\s*]\*(?![\p{L}\p{N}*]))|((?<![\p{L}\p{N}_])_(?=[^\s_])[^_\n]*?[^\s_]_(?![\p{L}\p{N}_]))/u;
+ function mdInline(str) {
+ const out = [];
+ let rest = String(str);
+ for (let guard = 0; rest && guard < 200; guard++) {
+ const m = MD_INLINE.exec(rest);
+ if (!m) { out.push(rest); break; }
+ if (m.index) out.push(rest.slice(0, m.index));
+ const tok = m[0];
+ if (m[1]) out.push(h('code', { class: 'md-code' }, tok.slice(1, -1)));
+ else if (m[2]) out.push(h('strong', {}, h('em', {}, ...mdInline(tok.slice(3, -3)))));
+ else if (m[3] || m[4]) out.push(h('strong', {}, ...mdInline(tok.slice(2, -2))));
+ else if (m[5]) out.push(h('s', {}, ...mdInline(tok.slice(2, -2))));
+ else out.push(h('em', {}, ...mdInline(tok.slice(1, -1))));
+ rest = rest.slice(m.index + tok.length);
+ }
+ return out;
+ }
function noteBody(text, depth = 0, em = null) {
const out = [];
const emojiAt = em && em.size ? (c) => em.get(c) : null;
@@ -8062,8 +8086,8 @@ export function messagesFeature(ctx) {
onClick: (e) => { e.preventDefault(); e.stopPropagation(); openTopicFeed(part.slice(1)); },
}, part));
} else if (emojiAt && part.includes(':')) {
- for (const p of splitEmoji(part, emojiAt)) out.push(typeof p === 'string' ? p : emojiImg(p.code, p.url));
- } else out.push(part);
+ for (const p of splitEmoji(part, emojiAt)) out.push(...(typeof p === 'string' ? mdInline(p) : [emojiImg(p.code, p.url)]));
+ } else out.push(...mdInline(part));
}
return out;
}