
    kh                         d dl Z d dlZd dlZd dlZd dlZd dlZddlmZ d Z G d de	      Z
d Zd Zed	k(  r e        yy)
    N   )writersc                     t               } | j                  d }n.t        | j                        5 }|j                         }d d d        t        | j                  d      5 }| j
                  d }| j                  }nt        j                  j                  t        | j
                              }dj                  t        j                  j                  | j                        j                  d      d         }t        j                  j                  | j
                  |      }t        j                   ||| j"                        }|j$                  D ]J  }t&        j(                  j+                  |j,                         t&        j(                  j+                  d       L t/        ||j0                         d d d        y # 1 sw Y   }xY w# 1 sw Y   y xY w)Nrbz{0}.html.r   )	style_mapconvert_imageoutput_format
)_parse_argsr   openreadpath
output_diroutputmammothimagesimg_elementImageWriterformatosbasename
rpartitionjoinconvertr
   messagessysstderrwritemessage_write_outputvalue)	argsr   style_map_fileobjdocx_fileobjr	   output_pathoutput_filenameresultr    s	            G/var/www/teggl/fontify/venv/lib/python3.12/site-packages/mammoth/cli.pymainr*      se   =D~~	$..! 	1%6)..0I	1 
dii	 1,??" M++K#NN66{4??7STM(//0@0@0K0V0VWZ0[\]0^_O'',,tHK',,	
  	#GJJW__-JJT"	# 	k6<<0'1 1	1 	11 1s   F;EG;GGc                       e Zd Zd Zd Zy)r   c                      || _         d| _        y )Nr   )_output_dir_image_number)selfr   s     r)   __init__zImageWriter.__init__+   s    %    c                    |j                   j                  d      d   }dj                  | j                  |      }t	        t
        j                  j                  | j                  |      d      5 }|j	                         5 }t        j                  ||       d d d        d d d        | xj                  dz  c_        d|iS # 1 sw Y   *xY w# 1 sw Y   .xY w)N/   z{0}.{1}wbr   src)content_type	partitionr   r.   r   r   r   r   r-   shutilcopyfileobj)r/   element	extensionimage_filename
image_destimage_sources         r)   __call__zImageWriter.__call__/   s    ((2237:	"))$*<*<iH"'',,t//@$G 	=: =<""<<=	= 	a~&&= =	= 	=s$   /C C C C		CCN)__name__
__module____qualname__r0   r@    r1   r)   r   r   *   s    	'r1   r   c                 h   | rt         j                  d   dk  rt         j                  }nt         j                  j                  }|j	                  |j                  d             |j                          y t        j                  | dd      5 }|j	                  |       d d d        y # 1 sw Y   y xY w)Nr   r4   zutf-8w)encoding)	r   version_infostdoutbufferr   encodeflushior   )r   contentsrI   fileobjs       r)   r!   r!   ;   s    |A!#ZZFZZ&&FX__W-.WWT31 	$WMM(#	$ 	$ 	$s   B((B1c                  X   t        j                         } | j                  ddd       | j                         }|j                  dddd	       |j                  d
d       | j                  ddt	        j
                         d       | j                  ddd       | j                         S )Nr   z	docx-pathz"Path to the .docx file to convert.)metavarhelpr   ?zoutput-pathzOutput path for the generated document. Images will be stored inline in the output document. Output is written to stdout if not set.)nargsrQ   rR   z--output-dirz}Output directory for generated HTML and images. Images will be stored in separate files. Mutually exclusive with output-path.)rR   z--output-formatFzOutput format.)requiredchoicesrR   z--style-mapzFile containg a style map.)rU   rR   )argparseArgumentParseradd_argumentadd_mutually_exclusive_groupr   formats
parse_args)parseroutput_groups     r)   r   r   I   s    $$&F
1  3
 668L T	  U
  M  N !	  
 )  + r1   __main__)rW   rM   r   r9   r   r    r   r*   objectr   r!   r   rA   rD   r1   r)   <module>rb      sI     	 	  
  1>'& '"$: zF r1   