Repository navigation
fix(emoji): show custom emoji after a link that ends at CJK punctuation - #2772
cheng-block wants to merge 22 commits into
Conversation
A custom emoji typed right after a bare link and fullwidth or CJK punctuation, as in `看这个 https://example.com,:party:`, stayed text. messageParts still ended http(s) links only at whitespace, so the sender added no NIP-30 emoji tag and the renderer kept the shortcode inside the link part. Bare links now end with the same pattern messageLinkParts uses, moved to relay/message-content.ts so relay/emoji.ts stays loadable by Node's native loader. `<url>` and `](url)` keep CJK punctuation as before. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The first commit also changed two cases outside the bare-link fix. A Markdown destination with whitespace after `](`, or a pasted `]\(`, ended at CJK punctuation like a bare link, so `[a]( https://example.com/a,:party:)` tagged a shortcode inside the link, and a send could wait for the emoji catalog. The case-insensitive linkPart also hid the shortcode in `[a](HTTPS://example.com),:party:`, which showed the emoji before. The destination check now accepts the `]\(` opener and the whitespace that messageLinkParts accepts, and linkPart is case-sensitive again. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The previous commit kept the emoji split case-insensitive, so an uppercase link could take a lowercase link after it into one part that linkPart then treats as text. In `HTTPS://example.com/?redirect=https://other.com/:party:` the sender newly tagged `:party:`, a send could wait for the emoji catalog, and the rendered link kept the final colon. The split is case-sensitive again, as it was before this PR, and BARE_URL_REST spells out A-Z in its host label check instead of relying on the i flag, so messageLinkParts still matches exactly what it did. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The first commit kept a URL whole only right after `<` or `](`. A Markdown destination after a line break or space, as in `[a](\nhttps://x.com/a,@honey)` or `[[a]]( https://x.com/a,@Honey)`, or after a pasted `]\(`, ended at the CJK punctuation instead. Edit then turned `@Honey` into a mention link inside the URL, which would change it on save, and Copy did the same for `]\(`. The timeline shows these as one link, as before. The check now accepts the `]\(` opener and the whitespace that messageLinkParts accepts, the same lookbehind block#2772 uses in emoji.ts. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
An http(s) URL nested in a destination whose own scheme the split does not see, such as an uppercase or ftp link, took the bare-link boundary and ended at CJK punctuation. So `[a](HTTPS://example.com/?redirect=https://other.com/a,:party:)` and the same URL in `<...>` tagged a shortcode inside the link, and a send could wait for the emoji catalog. A URL right after `/`, `?`, `#`, `=` or `&` is nested in another one, so it now keeps the boundary it had before, as a URL after `<` or `](` does. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
block#2772 now splits emoji text with a case-sensitive regex, so its copy of BARE_URL_REST spells out A-Z in the host label check instead of relying on the i flag. This takes the same hunk, so relay/message-content.ts stays byte for byte the same in both PRs. messageLinkParts and the mention check both use the i flag, so neither changes what it matches. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The previous commit kept a nested URL whole only when `/`, `?`, `#`, `=` or `&` came right before it, so `[a](HTTPS://x.com/(https://y.com/a,:party:))` still tagged a shortcode inside the link, and prose such as `链接=https://example.com,:party:` lost the fix. The split now reads a `<url>` or `](url)` destination from its opener: the text up to its first http(s) URL stays text, and that URL runs to whitespace as before. The scan stops at the next opener, so it stays linear. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The previous commit kept only a destination's first URL whole. A quote ends that URL, so in `[a](https://x.com/?url="https://y.com/a,:party:")` the next URL still ended at CJK punctuation and tagged a shortcode inside the link. The split now takes each `<url>` autolink, `](url)` or `](<url>)` destination as one piece, then splits every piece with the pattern used before this PR, so inside a destination every URL ends only at whitespace or `<>"`, as on main, while a bare link outside one ends at CJK punctuation. An autolink needs a scheme after `<`, so a stray `<` in text such as `价格<100看这个https://example.com,:party:` no longer hides the fix. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The bare-link pattern also matched an empty `http://` that the pattern before this PR left as text, so `see :http://` no longer referenced `:http:`. A bare link now needs one URL character after `//`, as before. With that, a message with no fullwidth or CJK punctuation splits exactly as it did on main (checked over 200,000 random messages). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
An angle destination may contain an escaped `\>` or `\<`, and an autolink or a destination may contain a Unicode space such as U+3000, but the destination pieces ended there, so in `[a](<https://x.com/a\>https://y.com/a,:party:>)` the next URL ended at CJK punctuation and tagged a shortcode inside the link. The `](<url>)` piece now skips escaped characters, and the autolink and `](url)` pieces end only at ASCII whitespace, as CommonMark does. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The previous commit read an escape in `](<url>)` with `.`, which skips U+2028 and U+2029, so `\` followed by one of them ended the piece and the next URL took the bare-link boundary. The whitespace after `](` was `\s`, which also takes U+2028 and U+3000, so `[a](\u2028<x>...)` started an angle piece where CommonMark reads a plain destination. An escape now pairs `\` with any character but CR or LF, and only space, tab, CR and LF count as whitespace after `](`. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
A link reference definition such as `[x]: https://example.com/a,:party:` is never drawn, but its URL took the bare-link boundary and ended at the fullwidth comma, so the shortcode after it got a tag, and a send could wait for the emoji catalog. The destination split now also takes a CommonMark definition as one piece: a line that starts with up to three spaces and `[label]:`, optional whitespace with at most one line ending, then a plain or `<...>` destination. Every URL in it keeps the pattern used before this PR, as in the other destinations. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The previous commit required a reference definition to start a line with up to three spaces, so one inside a blockquote or a list, as in `> [x]: https://example.com/a,:party:` or a list item's continuation, still took the bare-link boundary and tagged a shortcode inside the link. The definition's line may now start with any blockquote and list markers and indentation, and its destination may follow a line ending and a `>`. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
Sending stores the trimmed text but reads emoji from the text as typed, so a message that starts with a BOM, U+3000 or another space before a reference definition, as in `\uFEFF[x]: https://example.com/a,:party:`, missed the definition check and tagged a shortcode the stored message never draws. The first definition may now follow any leading whitespace that trimming removes. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
A plain destination piece ran to the next whitespace, so when it held another link's `](<` opener, as in `[x]: [a](<https://x.com/a b?u=https://y.com/a,:party:>)`, it stopped at the space inside that angle destination and the rest took the bare-link boundary, tagging a shortcode inside the link. A plain destination now ends before `](<` or `]\(<`, so the angle destination gets its own piece. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The renderer splits a message at mentions and runs the same link split on each piece, so treating the start of any split text as a line start let `[x]:` right after a mention, as in `@Mic [x]: https://example.com,:party:`, hide a shortcode the renderer still draws. A definition now needs a preceding line ending. Senders split the trimmed text the app stores behind one line ending, so a definition on the first line, including one after a BOM or other leading whitespace, is still found. A message that starts with an empty `http://` or `https://` now also tags the shortcodes after it, which the renderer already draws. The send side used to skip them as part of a link. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
The guard kept a `[label]: url` destination whole for custom emoji, but a pattern cannot tell a definition from paragraph text without Markdown's block structure. Each round found another shape it missed, and it then hid shortcodes in text the renderer draws, as in `Check this\n[x]: https://example.com,:party:`. Emoji splitting is back to autolinks, inline destinations and bare links. A shortcode right after CJK punctuation inside a definition's URL is tagged again; the renderer never draws it there, because definitions are literal. This reverts 86eb30f, 62080fe, 0d205e6, 6eac882 and e7815c9, and keeps the renderer check that an emoji after a mention and a link that ends at CJK punctuation is drawn. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz>
menglinblock
left a comment
There was a problem hiding this comment.
🤖 Approved by menglin's AI agent (OpusBot) after review. menglin confirmed the approval in Buzz.
|
🤖 Design review at Must-fix: a literal reference URL can now prevent sending while the emoji catalog is loading or unavailable. For Keep reference-definition destinations protected during emoji discovery and add a cold/error-catalog send regression. Preserve the intended Evidence: changed splitting, Send readiness gate. Exact base/head diagnostics confirmed the new false match; the Send failure follows from the existing readiness gate. Unchecked: native app/IME, keyboard/focus and screen-reader integration, themes, widths, enlarged text and many-agent states. No attached screenshots; no app run or package test suite in this review. |
`[ref]: https://example.com/a,:party:` is a reference definition, which renders no text, but the sender tagged `party` there. Without a ready catalog that blocked the send. Senders now find definitions with the same Markdown parser the renderer uses for literal ranges and skip shortcodes inside them. A paragraph line that only looks like a definition, such as `Check this\n[x]: https://example.com,:party:`, is still tagged. The parse runs only when the message has a shortcode and `]:`. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Cheng Peng <cheng@block.xyz>
Two gaps in finding reference definitions for emoji tags: - Joining the text around a definition with a line ending let a stray `](` before it reach a later link, as in `](\n\n[x]: https://example.com\n\nhttps://example.com,:party:`, so a shortcode the renderer draws lost its tag. Each piece is now split on its own. - The app stores trimmed text but tagged the untrimmed draft. A leading U+3000 or four spaces made `[ref]: https://example.com/a,:party:` a paragraph or code there, so the send still waited for the catalog. Sends, replies and edits now tag the text they store. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Cheng Peng <cheng@block.xyz>
`definitionRanges` returned nothing when Markdown nested more than 100 levels, so a definition there was still tagged and its send waited for the emoji catalog. The parser still returns the whole tree with positions; only the renderer's own walk stops at that depth, so the ranges now come from the full tree. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Cheng Peng <cheng@block.xyz>
Fixed in c3151a3, with 31c6441 and 9fb2009 before it. Emoji tagging now skips reference definition destinations that the Markdown parser finds, so |
…Ranges Edit now uses the `definitionRanges` helper that block#2772 adds for emoji, copied byte for byte, instead of walking the Markdown tree itself. The helper skips the parse when the body has no `]:`, so the separate early return for bodies without a bound name goes away. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
`definitionRanges` gave up on Markdown nested past the depth limit, so Edit turned a name inside a definition under 101 quote levels into a link inside its URL. Take block#2772's fix, which walks the whole tree, byte for byte, and cover that case in the Edit round trip. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
|
🤖 Could you add a screenshot or short video of the change to the PR? Design uses these for faster reviews. |
src/features/relay/messages.ts: main added the media target tag to thread replies next to emojiTags(content); keep it and this branch's emojiTags(content.trim()). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cheng Peng <cheng@block.xyz> Co-authored-by: Cursor <cursoragent@cursor.com>
Added under Screenshots in the description. They come from the debug build I tested. |
wesbillman
left a comment
There was a problem hiding this comment.
🤖 Carl, an automated reviewer, commenting via Wes's GitHub account.
No correctness blockers. The CJK fix is worth shipping. Merges cleanly onto current main (265 behind) and alongside #2768 and #2777. The affected suites pass on the combined tree. A 56-case renderer probe found no visible emoji left untagged, and <url>, ](url) and /:party: stay untagged.
One optional simplification, inline. Not a merge blocker.
| content.split(links).flatMap((part) => part.split(runs)); | ||
| export const linkPart = (part: string) => /^https?:\/\//.test(part); | ||
| /** Message parts outside reference definitions, which render no emoji. */ | ||
| function sentParts(content: string) { |
There was a problem hiding this comment.
Optional subtraction. This guard is most of the PR's complexity and cost. It adds a Markdown parse on the send path, which runs twice on a ready-catalog send with ]: and a shortcode, and it grows the buzz-mcp bundle by about 236 kB (+52 kB gzip, reproduced). The only case it covers is a shortcode after CJK punctuation inside a reference-definition URL, which renders nothing. The cold-catalog send wait it avoids still applies to code spans and quoted multiline destinations, which this PR accepts as known limits. Treating definitions the same way would let you drop sentParts, definitionRanges and the .trim() changes in messages.ts, and keep only the BARE_URL_REST split. If you keep the guard, it is correct as written, including the trim.
A link destination that starts on the next quoted line, as in `> [a](\n> https://example.com/a,:party:)`, was cut at the `>` marker, so the shortcode inside the URL was tagged though the view never draws it, and the send waited for the emoji catalog. Skip `>` markers before the destination, as the renderer does. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Signed-off-by: Cheng Peng <cheng@block.xyz>
GFM renders `[^1]: :party:` as a footnote, so the view draws the emoji, but the CommonMark parse saw a reference definition and the sender left the shortcode untagged. Skip only definitions that GFM keeps as definitions. Parse with fromMarkdown directly, since nothing else from scanMarkdown is used here. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Signed-off-by: Cheng Peng <cheng@block.xyz>
GFM only stops a footnote label at ASCII whitespace, so `[^a\u3000b]:` is still a footnote the view draws. Match the label the same way. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Signed-off-by: Cheng Peng <cheng@block.xyz>
The marker checked the character after the URL only inside the same part, so a URL that the part split had already ended, at `"` or at CJK punctuation once block#2772's split lands, got no marker and GFM ran on. Check the next character of the message instead. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Signed-off-by: Cheng Peng <cheng@block.xyz>
Why
A custom emoji right after a bare link and CJK punctuation stays text. In
看这个 https://example.com,:party:, the message gets noemojitag for:party:, and the view does not draw it.messageParts(src/features/relay/emoji.ts) splits text into link and non-link parts for custom emoji. Since #2404, rendered bare links end at CJK punctuation, but this split kept the old pattern. So,:party:stayed in a link part, which sending and rendering both skip.What
messagePartsnow ends a bare link at the same punctuation as rendered links, so the shortcode gets its tag and is drawn.How
BARE_URL_RESTinsrc/features/relay/message-content.ts, andmessageLinkPartsbuilds the same regex from it as onmain.emoji.tsdirectly, andmessage-link-parts.tshas an import Node cannot resolve.<url>autolinks and[label](url)destinations are split off whole first, so shortcodes inside them stay untagged, as onmain. That includes a destination that starts on the next quoted line.[x]: https://example.com/a,:party:, which render no text.definitionRangesinmessage-content.tsfinds them with the Markdown parser the renderer already uses. A footnote such as[^1]: :party:is drawn, so it keeps its tag.]:. A line that only looks like a definition inside a paragraph is still tagged.main, only a lowercasehttp(s)://counts here.buzz://links are out of scope.Risk
Small. Where links end does not change; only emoji tags and drawing after a link do.
http:// [](a) :party:(an emptyhttp://first), the shortcode now gets its tag and is drawn.[a](https://example.com),:party:the shortcode stays text, because a](url)destination runs to the next whitespace.pnpm buzz-mcpoutput grows by about 236 KB, because Buzz MCP now bundles the Markdown parser for this check.Testing
mainon 200,000 random messages.emojitag.Screenshots
Debug build of this PR: links end at the Chinese comma or full stop, and the custom emoji after them shows as an image.
In-app check
Verified in the macOS app by Cheng, except the changes after
6a095e805noted below.Pending: the footnote and quoted-link cases added after that check. Send
See[^1]and[^1]: :party:on the next lines: the emoji shows in the footnote. Send a link split over two lines with the second line in a>quote and:party:inside the link: it stays part of the link.Build: this PR at
86eb30fbf, merged locally with my other open PRs ontomainatc037057a1. It ran as a debug app bundle (BUZZ_DEV_VIEWER= just desktop-bundle). Later commits change only how reference definitions are tagged, so the steps behave the same.party.看这个 https://example.com,:party:. The link covers onlyhttps://example.com, then,and the emoji.https://example.com/a。:party:. The link ends before。, then the emoji shows.<https://example.com/a,:party:>. It stays one link with no emoji.https://example.com/:party:. It stays one link with no emoji.