a
    OcA                     @   sl   d dl Z d dlZd dlmZ dejZdd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd ZdS )    N)ArgumentParserzmistletoe [version {}]c                 C   s,   t | }|jrt|j|j n
t|j d S N)parse	filenamesconvertrendererinteractive)args	namespace r   E/var/www/html/megastudio/lib/python3.9/site-packages/mistletoe/cli.pymain	   s    r   c                 C   s   | D ]}t || qd S r   )convert_file)r   r   filenamer   r   r   r      s    r   c                 C   sx   zPt | ddd.}t||}tjj|  W d   n1 sD0    Y  W n" tyr   t	d
|  Y n0 dS )z>
    Parse a Markdown file and dump the output to stdout.
    rzutf-8)encodingNzCannot open file "{}".)open	mistletoemarkdownsysstdoutbufferwriteencodeOSErrorexitformat)r   r   Zfinrenderedr   r   r   r      s    4r   c              	   C   s   t   t|  g }d}z&|r dnd\}}|t|d  W q tyn   tdt||  dd d}g }Y q ty   td Y qY q0 qdS )	zT
    Parse user input, dump to stdout, rinse and repeat.
    Python REPL style.
    F)z... T)z>>> T
 )endz	
Exiting.N)	_import_readline_print_headingappendinputEOFErrorprintr   r   KeyboardInterrupt)r   contentsmorepromptr   r   r   r   "   s    r   c                 C   sF   t  }|jddtddd |jdddtd	 |jd
ddd || S )Nz-rz
--rendererzmistletoe.HTMLRendererz$specify an importable renderer class)typedefaulthelpz-vz	--versionversion)actionr.   r   *z,specify an optional list of files to convert)nargsr-   )r   add_argument_importversion_str
parse_args)r	   parserr   r   r   r   8   s    
r   c              	   C   s   dd l }z:tdd | d d d dd\}}||}t||W S  ty^   td Y nD ty~   td	| Y n$ t
y   td		|| Y n0 d S )
Nr   c                 S   s   | d d d S )Nr   )sr   r   r   <lambda>F       z_import.<locals>.<lambda>r7   .   z8[error] please supply full path to your custom renderer.z"[error] cannot import module "{}".z3[error] cannot find renderer "{}" from module "{}".)	importlibmapsplitimport_modulegetattr
ValueErrorr   r   ImportErrorr   AttributeError)argr=   cls_namepathmoduler   r   r   r3   C   s    $
r3   c                  C   s,   zdd l } W n ty&   td Y n0 d S )Nr   z)[warning] readline library not available.)readlinerC   r&   )rI   r   r   r   r!   Q   s    r!   c                 C   s4   t dt t d | tjur0t d| j d S )Nz{} (interactive)z1Type Ctrl-D to complete input, or Ctrl-C to exit.zUsing renderer: {})r&   r   r4   r   ZHTMLRenderer__name__)r   r   r   r   r"   X   s    
r"   )r   r   argparser   r   __version__r4   r   r   r   r   r   r3   r!   r"   r   r   r   r   <module>   s   