88from ..core .utils .system_debug_info import system_info
99from .utils .count_tokens import count_messages_tokens
1010from .utils .display_markdown_message import display_markdown_message
11+ from .utils .export_to_markdown import export_to_markdown
1112
1213
1314def handle_undo (self , arguments ):
@@ -58,6 +59,7 @@ def handle_help(self, arguments):
5859 "%help" : "Show this help message." ,
5960 "%info" : "Show system and interpreter information" ,
6061 "%jupyter" : "Export the conversation to a Jupyter notebook file" ,
62+ "%markdown" : "Export the conversation to a Markdown file" ,
6163 }
6264
6365 base_message = ["> **Available Commands:**\n \n " ]
@@ -220,6 +222,9 @@ def get_downloads_path():
220222 else :
221223 # For MacOS and Linux
222224 downloads = os .path .join (os .path .expanduser ("~" ), "Downloads" )
225+ # For some GNU/Linux distros, there's no '~/Downloads' dir by default
226+ if not os .path .exists (downloads ):
227+ os .makedirs (downloads )
223228 return downloads
224229
225230
@@ -295,6 +300,19 @@ def jupyter(self, arguments):
295300 )
296301
297302
303+ def markdown (self , export_path : str ):
304+ # If it's an empty conversations
305+ if len (self .messages ) == 0 :
306+ print ("No messages to export." )
307+ return
308+
309+ # If user doesn't specify the export path, then save the exported PDF in '~/Downloads'
310+ if not export_path :
311+ export_path = get_downloads_path () + f"/{ self .conversation_filename [:- 4 ]} md"
312+
313+ export_to_markdown (self .messages , export_path )
314+
315+
298316def handle_magic_command (self , user_input ):
299317 # Handle shell
300318 if user_input .startswith ("%%" ):
@@ -316,6 +334,7 @@ def handle_magic_command(self, user_input):
316334 "tokens" : handle_count_tokens ,
317335 "info" : handle_info ,
318336 "jupyter" : jupyter ,
337+ "markdown" : markdown ,
319338 }
320339
321340 user_input = user_input [1 :].strip () # Capture the part after the `%`
0 commit comments