@@ -494,17 +494,19 @@ def process_batch(
494494 # Check if Markdown output is needed but Markdown file doesn't exist
495495 if markdown_output :
496496 markdown_filename = filename .replace ('.grobid.tei.xml' , '.md' )
497- if not os .path .isfile (markdown_filename ):
497+ # Expand ~ to home directory before checking file existence
498+ markdown_filename_expanded = os .path .expanduser (markdown_filename )
499+ if not os .path .isfile (markdown_filename_expanded ):
498500 self .logger .info (f"Markdown file { markdown_filename } does not exist, generating Markdown from existing TEI..." )
499501 try :
500502 from .format .TEI2Markdown import TEI2MarkdownConverter
501503 converter = TEI2MarkdownConverter ()
502504 markdown_data = converter .convert_tei_file (filename )
503505
504506 if markdown_data :
505- with open (markdown_filename , 'w' , encoding = 'utf8' ) as markdown_file :
507+ with open (markdown_filename_expanded , 'w' , encoding = 'utf8' ) as markdown_file :
506508 markdown_file .write (markdown_data )
507- self .logger .debug (f"Successfully created Markdown file: { markdown_filename } " )
509+ self .logger .debug (f"Successfully created Markdown file: { markdown_filename_expanded } " )
508510 else :
509511 self .logger .warning (f"Failed to convert TEI to Markdown for { filename } " )
510512 except Exception as e :
@@ -588,13 +590,14 @@ def process_batch(
588590 from .format .TEI2Markdown import TEI2MarkdownConverter
589591 converter = TEI2MarkdownConverter ()
590592 markdown_data = converter .convert_tei_file (filename )
591-
593+
592594 if markdown_data :
593595 markdown_filename = filename .replace ('.grobid.tei.xml' , '.md' )
594596 # Always write Markdown file when TEI is written (respects --force behavior)
595- with open (markdown_filename , 'w' , encoding = 'utf8' ) as markdown_file :
597+ markdown_filename_expanded = os .path .expanduser (markdown_filename )
598+ with open (markdown_filename_expanded , 'w' , encoding = 'utf8' ) as markdown_file :
596599 markdown_file .write (markdown_data )
597- self .logger .debug (f"Successfully wrote Markdown file: { markdown_filename } " )
600+ self .logger .debug (f"Successfully wrote Markdown file: { markdown_filename_expanded } " )
598601 else :
599602 self .logger .warning (f"Failed to convert TEI to Markdown for { filename } " )
600603 except Exception as e :
0 commit comments