Skip to content

fix(markdown): repair CJK link boundaries - #188

Open
bingqilinweimaotai wants to merge 2 commits into
yetone:mainfrom
bingqilinweimaotai:fix/markdown-link-parsing
Open

fix(markdown): repair CJK link boundaries#188
bingqilinweimaotai wants to merge 2 commits into
yetone:mainfrom
bingqilinweimaotai:fix/markdown-link-parsing

Conversation

@bingqilinweimaotai

Copy link
Copy Markdown
Collaborator

Summary

  • Centralize URL-boundary handling for chat Markdown and link previews.
  • Repair GFM literal autolinks that absorb Markdown closing delimiters or adjacent CJK punctuation.
  • Prevent remarkCumora from generating nested links inside existing link labels.
  • Preserve explicit Markdown links and URLs containing balanced ASCII brackets.
  • Add regression coverage for bold URLs, CJK punctuation, literal links, and link previews.

Problem

Messages containing formatted URLs followed immediately by CJK text were parsed incorrectly. For example:

浏览器打开 **http://127.0.0.1:4182**(本机 preview)

The parser included **(本机 in the URL. The custom Remark transformation then parsed the URL label a second time, producing nested <a> elements.

This caused:

  • Broken Markdown emphasis.
  • Incorrectly extended link text.
  • Navigation to a malformed URL.
  • Invalid nested anchor elements.
  • Link previews using a different URL from the intended destination.

Changes

  • Add shared URL-boundary parsing for Markdown rendering and link previews.
  • Treat common CJK punctuation as prose boundaries for literal URLs.
  • Recover Markdown wrappers such as **URL** when GFM absorbs their closing delimiters.
  • Skip Cumora tokenization inside existing links and link references.
  • Reuse the shared URL parser in parseBody and LinkPreview.
  • Add regression tests covering:
    • Bold URLs followed by CJK prose.
    • Plain literal URLs.
    • URLs followed by CJK punctuation.
    • Explicit Markdown links.
    • Link-preview URL extraction.

Testing

  • Link regression tests: 5 passed.
  • Biome checks passed.
  • TypeScript typecheck passed.
  • Production build passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant