From faec1f84ed1e9e8ee78055796a8ebc92936abe9d Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 9 Oct 2026 21:48:11 -0700 Subject: 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 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_01Vps2H27rhbG9ZqseGfMrc3 --- src/features/messages.js | 28 ++++++++++++++++++++++++++-- src/style.css | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'src') 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\*\*)|((? 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; } diff --git a/src/style.css b/src/style.css index 5e3ddd7..8d41124 100644 --- a/src/style.css +++ b/src/style.css @@ -1628,3 +1628,5 @@ body::after { .mention-ac { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); overflow: hidden; max-height: 280px; overflow-y: auto; } .mention-ac:empty { display: none; } .mention-ac .item { cursor: pointer; padding: 6px 10px; } +/* `code` in a post */ +.md-code { font-family: var(--mono, ui-monospace, monospace); font-size: .9em; background: color-mix(in srgb, currentColor 9%, transparent); border-radius: 4px; padding: 0 .3em; } -- cgit v1.2.3