Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gateway/platforms/weixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ def _wrap_copy_friendly_lines_for_weixin(content: str) -> str:
or not stripped
or stripped.startswith("|")
or _TABLE_RULE_RE.match(stripped)
or _MARKDOWN_LINK_RE.search(stripped)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

):
wrapped.append(line)
continue
Expand Down
15 changes: 15 additions & 0 deletions tests/gateway/test_weixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ def test_format_message_wraps_long_plain_lines_for_copying(self):
assert all(len(line) <= weixin.WEIXIN_COPY_LINE_WIDTH for line in formatted.splitlines())
assert " ".join(formatted.split()) == " ".join(content.split())

def test_format_message_does_not_wrap_long_markdown_links(self):
adapter = _make_adapter()

content = (
"Read [Designcenter NX中的分析载荷]"
"(https://example.com/articles/"
+ "a" * weixin.WEIXIN_COPY_LINE_WIDTH
+ ")"
)

formatted = adapter.format_message(content)

assert formatted == content
assert "\n" not in formatted

def test_format_message_does_not_wrap_long_code_block_lines(self):
adapter = _make_adapter()

Expand Down