mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-24 16:54:43 +00:00
fix(slack): add bold-text zero-width-space guard for trailing non-word chars
Slack's mrkdwn parser can fail to recognize the closing * of a bold span when it is immediately preceded by a non-word character (), ], }, ., :, em-dash, ...), mis-rendering the span and in reported cases truncating the rest of the message. Insert a zero-width space (U+200B) between the last character and the closing * whenever the last character is not alphanumeric or underscore. Reapplied from #35144 by @gonzalofrancoceballos — the original patched gateway/platforms/slack.py, which was migrated to plugins/platforms/slack/adapter.py in the plugin migration.
This commit is contained in:
parent
b810711e4e
commit
cc64f0289a
1 changed files with 12 additions and 1 deletions
|
|
@ -3298,9 +3298,20 @@ class SlackAdapter(BasePlatformAdapter):
|
|||
)
|
||||
|
||||
# 9) Convert bold: **text** → *text* (Slack bold)
|
||||
# Slack's mrkdwn parser fails to recognize the closing * when it is
|
||||
# immediately preceded by non-word characters (e.g. ), ], }, ., :, —).
|
||||
# This causes the parser to silently truncate the rest of the message.
|
||||
# Insert a zero-width space (U+200B) between the last character and
|
||||
# the closing * whenever the last character is not alphanumeric or _.
|
||||
def _convert_bold(m):
|
||||
inner = m.group(1)
|
||||
if inner and not (inner[-1].isalnum() or inner[-1] == "_"):
|
||||
return _ph(f"*{inner}\u200b*")
|
||||
return _ph(f"*{inner}*")
|
||||
|
||||
text = re.sub(
|
||||
r"\*\*(.+?)\*\*",
|
||||
lambda m: _ph(f"*{m.group(1)}*"),
|
||||
_convert_bold,
|
||||
text,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue