fix(weixin): stop line wrapping from breaking markdown links - #51235
fix(weixin): stop line wrapping from breaking markdown links#51235KANIKIG wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a Weixin delivery formatting regression where the “copy-friendly” long-line wrapper could insert newlines inside valid Markdown link syntax ([text](url)), causing WeChat to render links as plain text.
Changes:
- Update Weixin’s copy-friendly wrapper to skip wrapping any line that contains an inline Markdown link (detected via existing
_MARKDOWN_LINK_RE). - Add a regression test ensuring long Markdown links are not modified/wrapped even when exceeding
WEIXIN_COPY_LINE_WIDTH.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
gateway/platforms/weixin.py |
Prevents the copy-friendly line wrapper from splitting lines containing Markdown links. |
tests/gateway/test_weixin.py |
Adds regression coverage for long inline Markdown links so they remain intact after formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
teknium1
left a comment
There was a problem hiding this comment.
Thanks for tracing this to the copy-friendly wrapper; the current-main path does pass long lines through textwrap.wrap() at gateway/platforms/weixin.py:726, so protecting inline link syntax is needed.
Problems
gateway/platforms/weixin.py:722skips wrapping the entire line when it contains any Markdown link. That removes the intended copy-friendly behavior for a long prose/report line containing even a short link; the wrapper was added for long copy-unfriendly lines in7244a1f0d3c17631661fbf103440a3790ab0bab9.- The new test only covers a nearly all-link line. It does not preserve the wrapper's behavior for prose surrounding an inline link.
Suggested changes
- Protect matched
[label](url)spans as atomic tokens, but continue wrapping surrounding prose. - Add a test with a space-containing link label embedded in long prose, asserting both that the link stays contiguous and that non-link prose is still wrapped.
Automated hermes-sweeper review.
| or not stripped | ||
| or stripped.startswith("|") | ||
| or _TABLE_RULE_RE.match(stripped) | ||
| or _MARKDOWN_LINK_RE.search(stripped) |
There was a problem hiding this comment.
This bypasses the copy-friendly wrapper for the entire line, including arbitrary surrounding prose. Please protect only the matched Markdown-link span(s) and keep wrapping text before/after them; add coverage for a long prose line containing a short inline link.
What does this PR do?
Fixes a Weixin delivery-formatting regression where the copy-friendly long-line wrapper can split valid Markdown links in the middle of the
[text](url)syntax. When that happens, WeChat receives broken Markdown and shows what should have been a clickable link as plain text.This is most visible in cron/report/article-summary messages: the source Markdown is valid, but the Weixin adapter rewrites a long single-line link before delivery.
Root cause
Follow-up to #21258 / #19161.
_wrap_copy_friendly_lines_for_weixin()intentionally wraps long non-code, non-table lines atWEIXIN_COPY_LINE_WIDTHso WeChat users can copy long prose more reliably.That is still useful for plain text, but
textwrap.wrap()does not understand Markdown inline syntax. A valid link such as:can be delivered as:
At that point WeChat no longer sees a valid Markdown link. The content is correct before formatting; it is corrupted during Weixin delivery formatting.
Related Issue
Follow-up to #21258 and #19161. I did not find an existing duplicate PR/issue for the interaction between Weixin copy-friendly wrapping and long Markdown links.
Related historical context, but not duplicates:
Type of Change
Changes Made
gateway/platforms/weixin.py: skip copy-friendly wrapping for lines that contain Markdown links, reusing the existing_MARKDOWN_LINK_RE.tests/gateway/test_weixin.py: add a regression test for long Markdown links that exceedWEIXIN_COPY_LINE_WIDTH.This keeps #21258's wrapping behavior for long plain text, issue-template/log-style prose, and other copy-unfriendly lines, while treating Markdown links as atomic inline content.
How to Test
WEIXIN_COPY_LINE_WIDTH.[text](url)and break the link.Tests run on Windows:
Checklist
Code
Documentation & Housekeeping
cli-config.yaml.exampleN/A — no config changesCONTRIBUTING.md/AGENTS.mdN/A — no workflow or architecture changes