From f95d77f961d2267d34de6b103bba0e8a3c3f099a Mon Sep 17 00:00:00 2001 From: Jasper Date: Sat, 21 Nov 2026 17:26:18 -0800 Subject: [PATCH] fix(feishu): preserve markdown examples in multi-backtick code spans (#8460) --- backend/app/channels/feishu.py | 3 ++- backend/tests/test_feishu_card_size.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/channels/feishu.py b/backend/app/channels/feishu.py index 2af9b52474..e28de9fe27 100644 --- a/backend/app/channels/feishu.py +++ b/backend/app/channels/feishu.py @@ -161,7 +161,8 @@ _LONE_SURROGATE = re.compile("[\ud800-\udfff]") # A markdown image marker, rewritten for the card so Feishu never sees one. _MARKDOWN_IMAGE = re.compile(r"!\[(?P[^\]]*)\]\((?P[^)\s]*)[^)]*\)") _FENCED_CODE = re.compile(r"(?ms)^[ \t]*(?P`{3,}|~{3,})[^\n]*\n.*?^[ \t]*(?P=fence)[ \t]*$") -_INLINE_CODE_SPAN = re.compile(r"`[^`\n]*`") +# Both delimiters are complete backtick runs of the same length. +_INLINE_CODE_SPAN = re.compile(r"(?`+)(?!`)[^\n]*?(?`{3,}|~{3,})[^\n]*$") diff --git a/backend/tests/test_feishu_card_size.py b/backend/tests/test_feishu_card_size.py index 59b72a2712..fc8a277b6b 100644 --- a/backend/tests/test_feishu_card_size.py +++ b/backend/tests/test_feishu_card_size.py @@ -240,6 +240,9 @@ async def test_reply_without_running_card_and_push_without_source_split_too(feis ("plain answer", "plain answer", False), # Code renders literally in a card, so the shown source must not change. ("inline `![a](b)` keeps its marker", "inline `![a](b)` keeps its marker", True), + ("example ``![a](b)`` and ![c](d)", "example ``![a](b)`` and [c](d)", True), + ("example ``use ` before ![a](b)`` and ![c](d)", "example ``use ` before ![a](b)`` and [c](d)", True), + ("unclosed `` before ![c](d)", "unclosed `` before [c](d)", False), ("```\n![a](b)\n```", "```\n![a](b)\n```", True), # A snapshot streamed before the closing fence arrives keeps its open block literal. ("```\n![a](b)", "```\n![a](b)", True),