t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Bare URLs followed by CJK text or full-width punctuation link the rest of the sentence (and swallow **bold**)

Open yu2001-s opened this issue 2 weeks ago • 0 comments

Area

apps/web (desktop chat markdown), packages/shared/src/markdownPipeline.ts

Steps to reproduce

  1. Have an agent reply in Chinese (or Japanese) with a bare URL followed directly by CJK text or full-width punctuation, with no space in between. This is the normal way to write in these languages. For example:
    可以看了:**http://localhost:18780**(已重启,跑的是提交后的版本)。
    
  2. Look at the rendered message in the desktop app.

Expected behavior

http://localhost:18780 is bold and is a link. The rest of the sentence, (已重启,跑的是提交后的版本)。, is plain text.

Actual behavior

The link runs to the end of the sentence. Its href is http://localhost:18780**(已重启,跑的是提交后的版本)。, so clicking it opens a broken URL. The ** around the URL is shown as literal asterisks, because the closing ** became part of the link and the bold never closes.

The same happens without bold: in 打开 http://localhost:18780,然后刷新 the link swallows ,然后刷新, and in URL:https://example.com/a。下一句 it swallows 。下一句.

Seen on T3 Code (Nightly) 0.1.10-nightly.20261112.4564 on macOS.

Why (root cause)

Chat markdown goes through remark-gfm (CHAT_MARKDOWN_REMARK_PLUGINS in packages/shared/src/markdownPipeline.ts). Its autolink-literal extension (micromark-extension-gfm-autolink-literal) continues a URL until whitespace or <. Only ASCII trailing punctuation (. , : ; ! ? * _ ~ and an unbalanced )) is trimmed afterwards. Full-width punctuation (( ) , 。 :) and CJK letters count as URL characters. Because autolink literals are tokenized before emphasis is resolved, a ** in the middle of that run is taken into the URL too.

Reproduced with plain unified().use(remarkParse).use(remarkGfm) (remark-gfm 4.0.1):

input link href
Open **http://localhost:18780**(restarted)。 http://localhost:18780**(restarted)。
Open http://localhost:18780,然后刷新 http://localhost:18780,然后刷新
URL:https://example.com/a。下一句 https://example.com/a。下一句
Open **http://localhost:18780** restarted (ASCII space) http://localhost:18780 ✅

remarkKeepAutolinkSuffixes already post-processes bare autolinks, extending them over _ and ~. Nothing trims them at a CJK boundary.

Suggested fix

Add a remark pass next to remarkKeepAutolinkSuffixes for bare autolinks (label equals URL, source slice equals the label). It cuts the URL at the first full-width or CJK punctuation character (U+3000–U+303F, U+FF00–U+FFEF), at the first CJK ideograph or kana, or at a **, __ or ~~ run. Then it re-parses the cut-off tail as inline markdown, so the emphasis that was swallowed is rebuilt. URLs with percent-encoded CJK keep working. Only raw CJK characters in a bare URL would stop being linked, and those are rare in agent output. Users can still write <…> or [text](url) for such URLs.

A smaller first step is to trim only at full-width punctuation and **. That covers every case above.

Impact

Minor, but frequent for anyone whose agents write in Chinese or Japanese: most replies with a local preview URL or a PR link produce a broken link.

Workaround

Ask the agent to put a space after URLs, or to use <url> or [text](url).

🤖 Generated with Claude Code

yu2001-s avatar Nov 12 '26 10:11 yu2001-s