@@ -14,6 +14,34 @@ use super::{
1414use crate :: config:: SlackConfig ;
1515use crate :: pairing:: PairingStore ;
1616
17+ // ============================================================================
18+ // Markdown to Slack mrkdwn conversion
19+ // ============================================================================
20+
21+ /// Convert standard Markdown to Slack's mrkdwn format
22+ fn markdown_to_mrkdwn ( text : & str ) -> String {
23+ let mut result = text. to_string ( ) ;
24+
25+ // Convert bold: **text** -> *text*
26+ // Be careful not to convert already-correct single asterisks
27+ // Use a simple approach: replace ** with a placeholder, then convert
28+ result = result. replace ( "**" , "\x00 BOLD\x00 " ) ;
29+ result = result. replace ( "\x00 BOLD\x00 " , "*" ) ;
30+
31+ // Convert italic: *text* -> _text_ (but only single asterisks not part of bold)
32+ // This is tricky because * is used for bold in mrkdwn
33+ // Skip this for now as it can conflict with bullet points
34+
35+ // Convert links: [text](url) -> <url|text>
36+ let link_re = regex_lite:: Regex :: new ( r"\[([^\]]+)\]\(([^)]+)\)" ) . unwrap ( ) ;
37+ result = link_re. replace_all ( & result, "<$2|$1>" ) . to_string ( ) ;
38+
39+ // Convert inline code: `code` stays the same in Slack
40+ // Convert code blocks: ```code``` stays the same in Slack
41+
42+ result
43+ }
44+
1745// ============================================================================
1846// Channel Implementation
1947// ============================================================================
@@ -61,10 +89,13 @@ impl Channel for SlackChannel {
6189 ) ;
6290 let session = self . client . open_session ( & self . token ) ;
6391
92+ // Convert markdown to Slack's mrkdwn format
93+ let mrkdwn_message = markdown_to_mrkdwn ( message) ;
94+
6495 // Build request with thread_ts if available (required for AI Assistant apps)
6596 let mut request = SlackApiChatPostMessageRequest :: new (
6697 self . channel_id . clone ( ) ,
67- SlackMessageContent :: new ( ) . with_text ( message . to_string ( ) ) ,
98+ SlackMessageContent :: new ( ) . with_text ( mrkdwn_message ) ,
6899 ) ;
69100
70101 // Reply in the thread if we have a thread_ts
0 commit comments