
    j!                         d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	 ddl
mZ ddlmZmZmZ d Zd	efd
ZdefdZedk(  r e        yy)    N)AnyDict)dedent)entry_points   )__version__)
MarkItDown
StreamInfoDocumentConverterResultc                     t        j                  ddt         j                  t        d      j	                               } | j                  ddddt         d	
       | j                  ddd       | j                  ddd       | j                  ddd       | j                  ddd       | j                         }|j                  dddd       |j                  ddddd !       | j                  d"d#t        d$%       | j                  d&t        d'%       | j                  d(t        d)%       | j                  d*t        d+%       | j                  d,d-dd.       | j                  d/dd0       | j                  d1dd2       | j                  d3d45       | j                         }|j                  }|E|j	                         j                         }t        |      d6kD  r|j                  d7      sd7|z   }nd }|j                  }|C|j	                         }t        |      d6kD  r#|j                  d8      d9k7  rt!        d:|        nd }|j"                  }|A|j	                         }t        |      d6kD  r!	 t%        j&                  |      j(                  }nd }d }|||t-        |||<      }|j.                  rt1        d=       t3        t5        d>?            }t        |      d6k(  rt1        d@       t1        dA       n9|D ])  }t1        dB|j(                  dCdD|j6                   dE       + t1        dF       t9        j:                  d6       |j<                  rR|j>                  t!        dG       n|j@                  t!        dH       tC        |jD                  |j>                  I      }	n|jF                  r|jH                  t!        dJ       n|j@                  t!        dK       dL|jH                  i}
|jJ                  |jJ                  |
dM<   |jL                  d9dNl'm(} |jL                  jS                  dO      D cg c]1  }|j	                         s|j	                         j                         3 }}g }|D ]  }	 |jU                   ||              ||
dQ<   tC        dUdR|jD                  i|
}	ntC        |jD                  S      }	|j@                  7|	jY                  t8        jZ                  j\                  ||j^                  T      }n(|	ja                  |j@                  ||j^                  T      }tc        ||       y # t*        $ r t!        d;|        Y w xY wc c}w # tV        $ r t!        dP|        Y w xY w)VNz)Convert various file formats to markdown.
markitdowna  
            SYNTAX:

                markitdown <OPTIONAL: FILENAME>
                If FILENAME is empty, markitdown reads from stdin.

            EXAMPLE:

                markitdown example.pdf

                OR

                cat example.pdf | markitdown

                OR

                markitdown < example.pdf

                OR to save to a file use

                markitdown example.pdf -o example.md

                OR

                markitdown example.pdf > example.md
            )descriptionprogformatter_classusagez-vz	--versionversionz	%(prog)s z show the version number and exit)actionr   helpz-oz--outputz?Output file name. If not provided, output is written to stdout.)r   z-xz--extensionzHProvide a hint about the file extension (e.g., when reading from stdin).z-mz--mime-typez*Provide a hint about the file's MIME type.z-cz	--charsetz5Provide a hint about the file's charset (e.g, UTF-8).z-dz--use-docintel
store_truezyUse Document Intelligence to extract text instead of offline conversion. Requires a valid Document Intelligence Endpoint.)r   r   z--use-cuz--use-content-understandinguse_cuzHUse Azure Content Understanding to extract text. Requires --cu-endpoint.)r   destr   z-ez
--endpointzHDocument Intelligence Endpoint. Required if using Document Intelligence.)typer   z--cu-endpointz;Content Understanding Endpoint. Required if using --use-cu.z--cu-analyzerzOContent Understanding analyzer ID. If not specified, auto-selects by file type.z--cu-file-typeszComma-separated list of file types to route to Content Understanding (e.g., pdf,jpeg,mp4). If omitted, all supported types are routed.z-pz--use-pluginszTUse 3rd-party plugins to convert files. Use --list-plugins to see installed plugins.z--list-pluginsz^List installed 3rd-party plugins. Plugins are loaded when using the -p or --use-plugin option.z--keep-data-urisz_Keep data URIs (like base64-encoded images) in the output. By default, data URIs are truncated.filename?)nargsr   ./r   zInvalid MIME type: zInvalid charset: )	extensionmimetypecharsetz(Installed MarkItDown 3rd-party Plugins:
zmarkitdown.plugin)groupz#  * No 3rd-party plugins installed.zI
Find plugins by searching for the hashtag #markitdown-plugin on GitHub.
z  * z<16z	(package: )zC
Use the -p (or --use-plugins) option to enable 3rd-party plugins.
zLDocument Intelligence Endpoint is required when using Document Intelligence.z6Filename is required when using Document Intelligence.)enable_pluginsdocintel_endpointzOContent Understanding Endpoint (--cu-endpoint) is required when using --use-cu.z6Filename is required when using Content Understanding.cu_endpointcu_analyzer_id)ContentUnderstandingFileType,zUnknown file type: cu_file_typesr#   )r#   )stream_infokeep_data_uris )2argparseArgumentParserRawDescriptionHelpFormatterr   stripadd_argumentr   add_mutually_exclusive_groupstr
parse_argsr   lowerlen
startswith	mime_typecount_exit_with_errorr    codecslookupnameLookupErrorr
   list_pluginsprintlistr   valuesysexituse_docintelendpointr   r	   use_pluginsr   r%   cu_analyzerr)   
convertersr'   splitappend
ValueErrorconvert_streamstdinbufferr+   convert_handle_output)parsercloud_groupargsextension_hintmime_type_hintcharset_hintr*   plugin_entry_pointsentry_pointr   	cu_kwargsr'   t
type_namescu_typesr=   results                    T/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/markitdown/__main__.pymainr`      s   $$? <<
6 %'? FD K=)/   N   W   9   D   557K I	   %W   W	   J   ^    V   c	   m   n   
#.D ^^N!'--/557~"!,,S1!$~!5!N ^^N!'--/~"##C(A- #6~6F!GH!N <<L#))+|q E%}}\:??  LK"%# $~|
 9:"<6I#JK"#q(78]  3 U[--c2,{?P?P>QQRSTUW 	== ^ ]]"UV++t}}

 
#a ]]"UV 4++%
	 '*.*:*:I&')@ ,0+=+=+C+CC+H&'AGGI	!J  H" CCOO$@$FGC *2Io&Mt/?/?M9M
t/?/?@
}}**II#.. + 
 ##MM{4CVCV $ 
 4 o  E #4\N!CDEx " C$':4&%ABCs0   9U U# U#U(U U (VVr^   c                 x   | j                   r=t        | j                   dd      5 }|j                  |j                         ddd       yt	        |j                  j                  t        j                  j                  d      j                  t        j                  j                               y# 1 sw Y   yxY w)zHandle output to stdout or filewzutf-8)encodingNreplace)errors)
outputopenwritemarkdownr@   encoderC   stdoutrc   decode)rT   r^   fs      r_   rQ   rQ     s    {{$++sW5 	%GGFOO$	% 	% 	OO""3::#6#6y"IPP

##	
		% 	%s   B00B9messagec                 D    t        |        t        j                  d       y )Nr   )r@   rC   rD   )rn   s    r_   r:   r:     s    	'NHHQK    __main__)r-   rC   r;   typingr   r   textwrapr   importlib.metadatar   	__about__r   _markitdownr	   r
   r   r`   rQ   r3   r:   __name__r,   rp   r_   <module>rx      sV     
    + " H Ht!n
!8 
c 
 zF rp   