8
8
from ..core .utils .system_debug_info import system_info
9
9
from .utils .count_tokens import count_messages_tokens
10
10
from .utils .display_markdown_message import display_markdown_message
11
+ from .utils .export_to_markdown import export_to_markdown
11
12
12
13
13
14
def handle_undo (self , arguments ):
@@ -58,6 +59,7 @@ def handle_help(self, arguments):
58
59
"%help" : "Show this help message." ,
59
60
"%info" : "Show system and interpreter information" ,
60
61
"%jupyter" : "Export the conversation to a Jupyter notebook file" ,
62
+ "%markdown" : "Export the conversation to a Markdown file" ,
61
63
}
62
64
63
65
base_message = ["> **Available Commands:**\n \n " ]
@@ -220,6 +222,9 @@ def get_downloads_path():
220
222
else :
221
223
# For MacOS and Linux
222
224
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 )
223
228
return downloads
224
229
225
230
@@ -295,6 +300,19 @@ def jupyter(self, arguments):
295
300
)
296
301
297
302
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
+
298
316
def handle_magic_command (self , user_input ):
299
317
# Handle shell
300
318
if user_input .startswith ("%%" ):
@@ -316,6 +334,7 @@ def handle_magic_command(self, user_input):
316
334
"tokens" : handle_count_tokens ,
317
335
"info" : handle_info ,
318
336
"jupyter" : jupyter ,
337
+ "markdown" : markdown ,
319
338
}
320
339
321
340
user_input = user_input [1 :].strip () # Capture the part after the `%`
0 commit comments