
    PiAf                       d dl mZ d dlZd dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dl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mZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)  G d d          Z* G d de*          Z+ G d de*          Z, G d de,          Z-e G d d                      Z. G d de,          Z/ G d  d!e,          Z0 G d" d#e,          Z1 G d$ d%e*          Z2 G d& d'e*          Z3 G d( d)e*          Z4 G d* d+e*          Z5 G d, d-e*          Z6 G d. d/e*          Z7 G d0 d1e*          Z8 G d2 d3e,          Z9 G d4 d5e,          Z: G d6 d7e,          Z; G d8 d9          Z< G d: d;e          Z=e>d<k    r,d dl?Z?d dlZ e?j@        d=>          ZAeAB                    d?d@dAB           eAB                    dCdDdEdFddGH           eAB                    dIdJdKdLdMN           eAB                    dOdPdQddQN           eAB                    dRdSdTdFdUV           eAB                    dWdXeCdYddZ[           eAB                    d\d]d^dFd_V           eAB                    d`dadbdFdcV           eAD                                ZEd ddlFmZ eEjG        dek    rejH        I                                ZJn> eKeEjG        dfg          5 ZLeLI                                ZJddd           n# 1 swxY w Y    e=eJeEjM        rdhndieEjN        eEjO        eEjP        j          ZQeEjR        rhd dlSZSd dlTZT eSjU                    ZV eeVeEjW        eEjX        k          ZeY                    eQ            eTjZ        eV[                                           dS  eeEjW        eEjX        dlm          ZeY                    eQ           dS dS )n    )annotationsN)	dataclass)ClassVarIterableget_args)
MarkdownIt)Token)Table   )box)
loop_first)Stack)ConsoleConsoleOptionsJustifyMethodRenderResult)Renderables)JupyterMixin)Rule)Segment)Style
StyleStack)Syntax)TextTextTypec                  ^    e Zd ZU dZded<   edd	            ZddZddZddZ	ddZ
d dZdS )!MarkdownElementTzClassVar[bool]new_linemarkdownMarkdowntokenr	   returnc                     |             S )zFactory to create markdown element,

        Args:
            markdown (Markdown): The parent Markdown object.
            token (Token): A node from markdown-it.

        Returns:
            MarkdownElement: A new markdown element
         clsr   r!   s      a/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/rich/markdown.pycreatezMarkdownElement.create   s     suu    contextMarkdownContextNonec                    dS )zuCalled when the node is entered.

        Args:
            context (MarkdownContext): The markdown context.
        Nr$   selfr*   s     r'   on_enterzMarkdownElement.on_enter)         r)   textr   c                    dS )zpCalled when text is parsed.

        Args:
            context (MarkdownContext): The markdown context.
        Nr$   r/   r*   r2   s      r'   on_textzMarkdownElement.on_text0   r1   r)   c                    dS )zwCalled when the parser leaves the element.

        Args:
            context (MarkdownContext): [description]
        Nr$   r.   s     r'   on_leavezMarkdownElement.on_leave7   r1   r)   childboolc                    dS )a|  Called when a child element is closed.

        This method allows a parent element to take over rendering of its children.

        Args:
            context (MarkdownContext): The markdown context.
            child (MarkdownElement): The child markdown element.

        Returns:
            bool: Return True to render the element, or False to not render the element.
        Tr$   r/   r*   r8   s      r'   on_child_closezMarkdownElement.on_child_close>   s	     tr)   consoler   optionsr   r   c                    dS )Nr$   r$   r/   r=   r>   s      r'   __rich_console__z MarkdownElement.__rich_console__L   s	     rr)   Nr   r    r!   r	   r"   r   r*   r+   r"   r,   r*   r+   r2   r   r"   r,   r*   r+   r8   r   r"   r9   r=   r   r>   r   r"   r   )__name__
__module____qualname__r   __annotations__classmethodr(   r0   r5   r7   r<   rA   r$   r)   r'   r   r      s         #H####
 
 
 [
                 r)   r   c                      e Zd ZdZdS )UnknownElementzAn unknown element.

    Hopefully there will be no unknown elements, and we will have a MarkdownElement for
    everything in the document.

    N)rG   rH   rI   __doc__r$   r)   r'   rM   rM   R   s           r)   rM   c                  .    e Zd ZdZdZddZdd
ZddZdS )TextElementz)Base class for elements that render text.noner*   r+   r"   r,   c                n    |                     | j                  | _        t          d          | _        d S Nleftjustify)enter_style
style_namestyler   r2   r.   s     r'   r0   zTextElement.on_enter`   s/    ((99
(((			r)   r2   r   c                t    | j                             |t          |t                    r|j        nd            d S N)r2   append
isinstancestrcurrent_styler4   s      r'   r5   zTextElement.on_textd   s8    	
48M8MWw44SWXXXXXr)   c                .    |                                  d S r[   )leave_styler.   s     r'   r7   zTextElement.on_leaveg   s    r)   NrC   rD   )rG   rH   rI   rN   rX   r0   r5   r7   r$   r)   r'   rP   rP   [   s_        33J) ) ) )Y Y Y Y     r)   rP   c                  J    e Zd ZU dZdZded<   edd
            ZddZddZ	dS )	ParagraphzA Paragraph.zmarkdown.paragraphr   rV   r   r    r!   r	   r"   c                (     | |j         pd          S rS   rU   r%   s      r'   r(   zParagraph.createq   s    s8+5v6666r)   r,   c                    || _         d S r[   rU   r/   rV   s     r'   __init__zParagraph.__init__u   s    r)   r=   r   r>   r   r   c              #  >   K   | j         | j        _         | j        V  d S r[   )rV   r2   r@   s      r'   rA   zParagraph.__rich_console__x   s#       !L	ir)   N)r   r    r!   r	   r"   rc   rV   r   r"   r,   rF   )
rG   rH   rI   rN   rX   rJ   rK   r(   rg   rA   r$   r)   r'   rc   rc   k   ss         %J7 7 7 [7        r)   rc   c                  ,    e Zd ZU dZded<   dZded<   dS )HeadingFormatrT   r   rV    r^   rY   N)rG   rH   rI   rV   rJ   rY   r$   r)   r'   rk   rk      s.         #G####EOOOOOOr)   rk   c                  j     e Zd ZU dZdddddddZded<   edd            ZddZd fdZ	ddZ
 xZS )Headingz
A heading.centerrT   )h1h2h3h4h5h6z"ClassVar[dict[str, JustifyMethod]]LEVEL_ALIGNr   r    r!   r	   r"   c                "     | |j                   S r[   )tagr%   s      r'   r(   zHeading.create   s    s59~~r)   r*   r+   r,   c                `    t                      | _        |                    | j                   d S r[   )r   r2   rW   rX   r.   s     r'   r0   zHeading.on_enter   s)    FF	DO,,,,,r)   rx   r^   c                j    || _         d| | _        t                                                       d S )N	markdown.)rx   rX   superrg   )r/   rx   	__class__s     r'   rg   zHeading.__init__   s5    +c++r)   r=   r   r>   r   r   c              #     K   | j                                         }| j                            | j        d          }||_        |V  d S )NrT   )r2   copyrv   getrx   rV   )r/   r=   r>   r2   heading_justifys        r'   rA   zHeading.__rich_console__   sG       y~~*..tx@@&




r)   )r   r    r!   r	   r"   rn   rC   )rx   r^   r"   r,   rF   )rG   rH   rI   rN   rv   rJ   rK   r(   r0   rg   rA   __classcell__r}   s   @r'   rn   rn      s          7 7K        [- - - -     
       r)   rn   c                  >    e Zd ZdZdZedd            ZddZddZdS )	CodeBlockz&A code block with syntax highlighting.zmarkdown.code_blockr   r    r!   r	   r"   c                p    |j         pd}|                    d          d         } | |pd|j                  S )Nrl    r   r2   )info	partition
code_theme)r&   r   r!   	node_info
lexer_names        r'   r(   zCodeBlock.create   s@    J$"	((--a0
s:')<===r)   r   r^   themer,   c                "    || _         || _        d S r[   )r   r   )r/   r   r   s      r'   rg   zCodeBlock.__init__   s    $


r)   r=   r   r>   r   r   c              #     K   t          | j                                                  }t          || j        | j        dd          }|V  d S )NTr   )r   	word_wrappadding)r^   r2   rstripr   r   r   )r/   r=   r>   codesyntaxs        r'   rA   zCodeBlock.__rich_console__   sS       49~~$$&&$/tQ
 
 
 r)   N)r   r    r!   r	   r"   r   )r   r^   r   r^   r"   r,   rF   )	rG   rH   rI   rN   rX   rK   r(   rg   rA   r$   r)   r'   r   r      se        00&J> > > [>
        r)   r   c                  .    e Zd ZdZdZddZddZddZdS )
BlockQuotezA block quote.zmarkdown.block_quoter"   r,   c                ,    t                      | _        d S r[   r   elementsr/   s    r'   rg   zBlockQuote.__init__       %0]]r)   r*   r+   r8   r   r9   c                :    | j                             |           dS NFr   r\   r;   s      r'   r<   zBlockQuote.on_child_close       U###ur)   r=   r   r>   r   r   c              #     K   |                     |j        dz
            }|                    | j        || j                  }| j        }t          d          }t          d|          }|D ]}|V  |E d {V  |V  d S )N   widthrY   
u   ▌ )update	max_widthrender_linesr   rY   r   )	r/   r=   r>   render_optionslinesrY   r   r   lines	            r'   rA   zBlockQuote.__rich_console__   s       !g.?!.CDD$$T]N$*$UU
4==&%(( 	 	DMMMOOOOOOONNNN	 	r)   Nr"   r,   rE   rF   )rG   rH   rI   rN   rX   rg   r<   rA   r$   r)   r'   r   r      s[        'J3 3 3 3        r)   r   c                      e Zd ZdZdZdd	Zd
S )HorizontalRulez%A horizontal rule to divide sections.Fr=   r   r>   r   r"   r   c              #  ~   K   |                     dd          }t          |d          V  t                      V  d S )Nzmarkdown.hrrQ   default-)rY   
characters)	get_styler   r   )r/   r=   r>   rY   s       r'   rA   zHorizontalRule.__rich_console__   sJ       !!-!@@3//////ffr)   NrF   )rG   rH   rI   rN   r   rA   r$   r)   r'   r   r      s3        //H     r)   r   c                  *    e Zd ZdZddZdd
ZddZdS )TableElementz.MarkdownElement corresponding to `table_open`.r"   r,   c                "    d | _         d | _        d S r[   )headerbodyr   s    r'   rg   zTableElement.__init__   s    15-1			r)   r*   r+   r8   r   r9   c                    t          |t                    r|| _        n,t          |t                    r|| _        nt          d          dS )Nz Couldn't process markdown table.F)r]   TableHeaderElementr   TableBodyElementr   RuntimeErrorr;   s      r'   r<   zTableElement.on_child_close   sP    e/00 	CDKK/00 	CDIIABBBur)   r=   r   r>   r   r   c              #    K   t          t          j        dddd          }| j        c| j        j        W| j        j        j        D ]E}|j                                        }|                    d           |	                    |           F| j
        *| j
        j        D ]}d |j        D             } |j        |  |V  d S )NFzmarkdown.table.borderT)r   pad_edgerY   	show_edgecollapse_paddingzmarkdown.table.headerc                    g | ]	}|j         
S r$   )content).0elements     r'   
<listcomp>z1TableElement.__rich_console__.<locals>.<listcomp>
  s    HHH7wHHHr)   )r
   r   SIMPLEr   rowcellsr   r   stylize
add_columnr   rowsadd_row)r/   r=   r>   tablecolumnheadingr   row_contents           r'   rA   zTableElement.__rich_console__   s       
)!
 
 
 ;"t{'B+// * * .--// 7888  ))))9 y~ , ,HHciHHH{+++r)   Nr   rE   rF   )rG   rH   rI   rN   rg   r<   rA   r$   r)   r'   r   r      sV        882 2 2 2        r)   r   c                  "    e Zd ZdZddZdd
ZdS )r   z@MarkdownElement corresponding to `thead_open` and `thead_close`.r"   r,   c                    d | _         d S r[   )r   r   s    r'   rg   zTableHeaderElement.__init__  s    +/r)   r*   r+   r8   r   r9   c                B    t          |t                    sJ || _        dS r   )r]   TableRowElementr   r;   s      r'   r<   z!TableHeaderElement.on_child_close  s$    %11111ur)   Nr   rE   rG   rH   rI   rN   rg   r<   r$   r)   r'   r   r     sB        JJ0 0 0 0     r)   r   c                  "    e Zd ZdZddZdd
ZdS )r   z@MarkdownElement corresponding to `tbody_open` and `tbody_close`.r"   r,   c                    g | _         d S r[   )r   r   s    r'   rg   zTableBodyElement.__init__  s    +-			r)   r*   r+   r8   r   r9   c                h    t          |t                    sJ | j                            |           dS r   )r]   r   r   r\   r;   s      r'   r<   zTableBodyElement.on_child_close"  s3    %11111	ur)   Nr   rE   r   r$   r)   r'   r   r     sB        JJ. . . .     r)   r   c                  "    e Zd ZdZddZdd
ZdS )r   z:MarkdownElement corresponding to `tr_open` and `tr_close`.r"   r,   c                    g | _         d S r[   )r   r   s    r'   rg   zTableRowElement.__init__+  s    -/


r)   r*   r+   r8   r   r9   c                h    t          |t                    sJ | j                            |           dS r   )r]   TableDataElementr   r\   r;   s      r'   r<   zTableRowElement.on_child_close.  s4    %!122222
%   ur)   Nr   rE   r   r$   r)   r'   r   r   (  sB        DD0 0 0 0     r)   r   c                  :    e Zd ZdZedd            ZddZddZdS )r   z[MarkdownElement corresponding to `td_open` and `td_close`
    and `th_open` and `th_close`.r   r    r!   r	   r"   r   c                    t          |j                            d                    pd}d|v rd}nd|v rd}n	d|v rd}nd	}|t          t                    v sJ  | |
          S )NrY   rl   ztext-align:rightrightztext-align:centerro   ztext-align:leftrT   r   rU   )r^   attrsr   r   r   )r&   r   r!   rY   rV   s        r'   r(   zTableDataElement.create8  s    EKOOG,,--3 &&GG E))GG%''GGG(=111111s7####r)   rV   r   r,   c                @    t          d|          | _        || _        d S )Nrl   rU   )r   r   rV   rf   s     r'   rg   zTableDataElement.__init__I  s!    !"g666r)   r*   r+   r2   r   c                    t          |t                    rt          |          n|}|                    |j                   | j                            |           d S r[   )r]   r^   r   r   r_   r   append_textr4   s      r'   r5   zTableDataElement.on_textM  sQ    'c22<tDzzzW*+++  &&&&&r)   NrB   ri   rD   )rG   rH   rI   rN   rK   r(   rg   r5   r$   r)   r'   r   r   4  sf        % % $ $ $ [$    ' ' ' ' ' 'r)   r   c                  B    e Zd ZdZedd            ZddZddZddZdS )ListElementzA list element.r   r    r!   r	   r"   c           	     p     | |j         t          |j                            dd                              S )Nstartr   )typeintr   r   r%   s      r'   r(   zListElement.createV  s.    s5:s5;??7A#>#>??@@@r)   	list_typer^   
list_start
int | Noner,   c                0    g | _         || _        || _        d S r[   )itemsr   r   )r/   r   r   s      r'   rg   zListElement.__init__Z  s    %'
"$r)   r*   r+   r8   r   r9   c                h    t          |t                    sJ | j                            |           dS r   )r]   ListItemr   r\   r;   s      r'   r<   zListElement.on_child_close_  s3    %*****
%   ur)   r=   r   r>   r   r   c              #  4  K   | j         dk    r(| j        D ]}|                    ||          E d {V  d S | j        dn| j        }|t	          | j                  z   }t          | j                  D ]&\  }}|                    ||||z   |          E d {V  'd S )Nbullet_list_openr   )r   r   render_bulletr   len	enumeraterender_number)r/   r=   r>   itemnumberlast_numberindexs          r'   rA   zListElement.__rich_console__d  s       >///
 @ @--gw??????????@ @ /1QQtF 3tz??2K(44  t--Wfunk          r)   N)r   r    r!   r	   r"   r   )r   r^   r   r   r"   r,   rE   rF   )	rG   rH   rI   rN   rK   r(   rg   r<   rA   r$   r)   r'   r   r   S  sx        A A A [A% % % %
   
     r)   r   c                  6    e Zd ZdZdZddZddZddZddZdS )r   zAn item in a list.zmarkdown.itemr"   r,   c                ,    t                      | _        d S r[   r   r   s    r'   rg   zListItem.__init__x  r   r)   r*   r+   r8   r   r9   c                :    | j                             |           dS r   r   r;   s      r'   r<   zListItem.on_child_close{  r   r)   r=   r   r>   r   r   c              #  h  K   |                     |j        dz
            }|                    | j        || j                  }|                    dd          }t          d|          }t          d|          }t          d	          }t          |          D ]\  }	}
|	r|n|V  |
E d {V  |V  d S )
N   r   r   zmarkdown.item.bulletrQ   r   u    • z   r   )r   r   r   r   rY   r   r   r   )r/   r=   r>   r   r   bullet_stylebulletr   r   firstr   s              r'   r   zListItem.render_bullet  s       g.?!.CDD$$T]N$*$UU(()?(PP,//'<004==%e,, 	 	KE4!.&&w...OOOOOOONNNN	 	r)   r   r   r   c              #    K   t          t          |                    dz   }|                    |j        |z
            }|                    | j        || j                  }|                    dd          }t          d          }	t          d|z  |          }
t          | 	                    |d	z
            dz   |          }t          |          D ]\  }}|r|n|
V  |E d {V  |	V  d S )
N   r   r   zmarkdown.item.numberrQ   r   r   r   r   )r   r^   r   r   r   r   rY   r   r   rjustr   )r/   r=   r>   r   r   number_widthr   r   number_styler   r   numeralr  r   s                 r'   r   zListItem.render_number  s      3{++,,q0 g.?,.NOO$$T]N$*$UU(()?(PP4==#,l;;V+++L1,<==C\RR%e,, 	 	KE4"/''///OOOOOOONNNN	 	r)   Nr   rE   rF   )
r=   r   r>   r   r   r   r   r   r"   r   )	rG   rH   rI   rN   rX   rg   r<   r   r   r$   r)   r'   r   r   s  so         J3 3 3 3           r)   r   c                  .    e Zd Zedd            ZddZdS )Linkr   r    r!   r	   r"   r   c                t    |j                             dd          } | |j        t          |                    S )Nhref#)r   r   r   r^   )r&   r   r!   urls       r'   r(   zLink.create  s1    koofc**s5=#c((+++r)   r2   r^   r  c                <    t          |          | _        || _        d S r[   )r   r2   r  )r/   r2   r  s      r'   rg   zLink.__init__  s    JJ				r)   NrB   )r2   r^   r  r^   )rG   rH   rI   rK   r(   rg   r$   r)   r'   r  r    sF        , , , [,     r)   r  c                  T     e Zd ZdZdZedd	            Zd fdZd fdZddZ	 xZ
S )	ImageItemz#Renders a placeholder for an image.Fr   r    r!   r	   r"   r   c                p     | t          |j                            dd                    |j                  S )zFactory to create markdown element,

        Args:
            markdown (Markdown): The parent Markdown object.
            token (Any): A token from markdown-it.

        Returns:
            MarkdownElement: A new markdown element
        srcrl   )r^   r   r   
hyperlinksr%   s      r'   r(   zImageItem.create  s1     s3u{ub1122H4GHHHr)   destinationr^   r  r9   r,   c                r    || _         || _        d | _        t                                                       d S r[   )r  r  linkr|   rg   )r/   r  r  r}   s      r'   rg   zImageItem.__init__  s5    &$ $	r)   r*   r+   c                    |j         j        | _        t          d          | _        t	                                          |           d S rS   )r_   r  r   r2   r|   r0   )r/   r*   r}   s     r'   r0   zImageItem.on_enter  s@    ).	(((	!!!!!r)   r=   r   r>   r   r   c              #  F  K   t          | j        p| j        pd           }| j        p@t	          | j                            d                              dd          d                   }| j        r|                    |           t	          j	        d|dd          }|V  d S )	Nr  /r   u   🌆 r   rl   )end)
r   r  r  r2   r   striprsplitr  r   assemble)r/   r=   r>   
link_styletitler2   s         r'   rA   zImageItem.__rich_console__  s       	 ET-= EFFF
	QT$"2"8"8"="="D"DS!"L"LR"PQQ? 	&MM*%%%}WeSb999




r)   rB   )r  r^   r  r9   r"   r,   rC   rF   )rG   rH   rI   rN   r   rK   r(   rg   r0   rA   r   r   s   @r'   r  r    s        --H
I 
I 
I [
I     " " " " " "
       r)   r  c                  P    e Zd ZdZ	 	 dddZedd            ZddZddZddZ	dS )r+   z!Manages the console render state.Nmonokair=   r   r>   r   rY   r   inline_code_lexer
str | Noneinline_code_themer^   r"   r,   c                    || _         || _        t          |          | _        t	                      | _        d | _        |t          d||          | _        d S d S )Nrl   )r   )r=   r>   r   style_stackr   stack_syntaxr   )r/   r=   r>   rY   r&  r(  s         r'   rg   zMarkdownContext.__init__  s^     '1%'8'8-2WW
&*(!"&7?PQQQDLLL )(r)   c                    | j         j        S )z>Current style which is the product of all styles on the stack.)r*  currentr   s    r'   r_   zMarkdownContext.current_style  s     ''r)   r2   	node_typec                8   |dv ru| j         n| j                             |          }|                                 | j        j                            | t          j        || j        j	                             dS | j        j                            | |           dS )z#Called when the parser visits text.>   fencecode_inlineNr   )
r,  	highlightr   r+  topr5   r   r!  r*  r.  )r/   r2   r/  highlight_texts       r'   r5   zMarkdownContext.on_text  s    000T\5M!\33D99N!!###JN""dmN$:J:RSSS     JN""4.....r)   rX   str | Stylec                |    | j                             |d          }| j                            |           | j        S )zEnter a style context.rQ   r   )r=   r   r*  pushr_   )r/   rX   rY   s      r'   rW   zMarkdownContext.enter_style  s<    &&z6&BBe$$$!!r)   c                8    | j                                         }|S )zLeave a style context.)r*  pop)r/   rY   s     r'   ra   zMarkdownContext.leave_style  s     $$&&r)   )Nr%  )r=   r   r>   r   rY   r   r&  r'  r(  r^   r"   r,   )r"   r   )r2   r^   r/  r^   r"   r,   )rX   r6  r"   r   )
rG   rH   rI   rN   rg   propertyr_   r5   rW   ra   r$   r)   r'   r+   r+     s        ++ )-!*R R R R R" ( ( ( X(	/ 	/ 	/ 	/" " " "     r)   r+   c                      e Zd ZU dZi dedededededede	d	e	d
e
dededededededeZded<   h dZ	 	 	 	 	 	 d1d2d'Zd3d*Zd4d0ZdS )5r    a  A Markdown renderable.

    Args:
        markup (str): A string containing markdown.
        code_theme (str, optional): Pygments theme for code blocks. Defaults to "monokai". See https://pygments.org/styles/ for code themes.
        justify (JustifyMethod, optional): Justify value for paragraphs. Defaults to None.
        style (Union[str, Style], optional): Optional style to apply to markdown.
        hyperlinks (bool, optional): Enable hyperlinks. Defaults to ``True``.
        inline_code_lexer: (str, optional): Lexer to use if inline code highlighting is
            enabled. Defaults to None.
        inline_code_theme: (Optional[str], optional): Pygments theme for inline code
            highlighting, or None for no highlighting. Defaults to None.
    paragraph_openheading_openr1  
code_blockblockquote_openhrr   ordered_list_openlist_item_openimage
table_open
tbody_open
thead_opentr_opentd_openth_openz*ClassVar[dict[str, type[MarkdownElement]]]r   >   semr   strongr%  NrQ   Tmarkupr^   r   rV   JustifyMethod | NonerY   r6  r  r9   r&  r'  r(  r"   r,   c                   t                                          d                              d          }|| _        |                    |          | _        || _        || _        || _        || _        || _	        |p|| _
        d S )Nstrikethroughr   )r   enablerN  parseparsedr   rV   rY   r  r&  r(  )	r/   rN  r   rV   rY   r  r&  r(  parsers	            r'   rg   zMarkdown.__init__$  sz     $$_55<<WEEll6**$-4
$!2!2!@jr)   tokensIterable[Token]c              #     K   |D ]H}|j         dk    }|j        dk    }|j        r%|s#|s!|                     |j                  E d{V  D|V  IdS )zFlattens the token stream.r1  imgN)r   rx   children_flatten_tokens)r/   rV  r!   is_fenceis_images        r'   r[  zMarkdown._flatten_tokens8  s       	 	EzW,HyE)H~ x 8 //??????????	 	r)   r=   r   r>   r   r   c              #  h
  K   |                     | j        d          }|                    d          }t          |||| j        | j                  }| j        }| j        }d}t          j	                    }| 
                    |          D ]}	|	j        }
|	j        }|	j        dk    }|	j        dk    }|	j        d	k    }|
d
k    r|                    |	j        |
           T|
dk    r|                    d|
           q|
dk    r|                    d|
           |
dk    rt!          |	j                            dd                    }| j        rA|                     dd          }|t)          |          z  }|                    |           |j                            t0                              | |	                     9|
dk    r6| j        r|                                 ]|j                                        }t9          |t0                    sJ |                     dd          }|                    |           |                    |j        j        |
           |                                 |                    d|
           |                     dd          }|                    |           |                    |j        |
           |                                 |                    d|
           v||v r|
dk    r|
dk    r|r|                    d|            |r|                                 |                    d|            |	j        r|                    |	j        |
           |                                 
| j                             |	j                  ptB          }|                    | |	          }|s|r/|j                            |           |"                    |           |rr|j                                        }|j         p&|j        o|j        j#        $                    ||          }|r'|r|V  |%                    ||j&                  E d{V  n|r|j                                         |	j        }||                    ||           |j         p&|j        o|j        j#        $                    ||          }|r-|r
|
dk    r|V  |%                    ||j&                  E d{V  |s|r|'                    |           |j(        }dS )zRender markdown to the console.rQ   r   N)height)r&  r(  Fr   r  r   r2   	hardbreakr   	softbreakr   	link_openr  rl   zmarkdown.link_urlr  
link_closezmarkdown.linkz ()r1  r?  r{   inline))r   rY   r   r+   r&  r(  rT  inlinesr   r   r[  r   rx   nestingr5   r   r^   r   r   r  r   rW   r+  r8  r  r(   ra   r:  r]   r2   plainr  r   rM   r0   r4  r<   renderr>   r7   r   )r/   r=   r>   rY   r*   rV  inline_style_tagsr   _new_line_segmentr!   r/  rx   enteringexitingself_closingr  r"  r   link_url_styleelement_classshould_renderr2   s                         r'   rA   zMarkdown.__rich_console__B  s      !!$*f!==...--!"4"4
 
 
  L#LNN))&11 c	0 c	0E
I)C})Hmr)G =A-LF""y9999k))i0000k))Y////k))5;??626677? A!(!2!23FPV!2!W!WJ%T"2"2"22J''
3333M&&t{{4'?'?@@@@l**? 4''))))%m//11G%gt44444!(!2!2?F!2!S!SJ''
333OOGL$6	BBB'')))OOD)444%,%6%6+V &7 & &N ''777OOGL)<<<'')))OOC3333(((((-- * ''(9C(9(9:::: 	* '')))) ''(9C(9(9:::} ByAAA'')))) !% 1 1%* = = O'..tU;; .| .M&&w///$$W--- L%m//11G(/$5 % O#M-<<WgNN "
 % L# 4"3333#*>>'7?#K#KKKKKKKK! LM%%''' =D'666 $M) O"= O#M-<<WgNN "
 % L# 4	X(=(="3333#*>>'7?#K#KKKKKKKK 0l 0$$W---&/HGc	0 c	0r)   )r%  NrQ   TNN)rN  r^   r   r^   rV   rO  rY   r6  r  r9   r&  r'  r(  r'  r"   r,   )rV  rW  r"   rW  rF   )rG   rH   rI   rN   rc   rn   r   r   r   r   r   r  r   r   r   r   r   r   rJ   rf  rg   r[  rA   r$   r)   r'   r    r       sh         <)<< 	< 	i	<
 	:< 	n< 	K< 	[< 	(< 	< 	l< 	&< 	(< 	?< 	#<  	#!<H    & ,++G
 $(,#(,(,A A A A A(   u0 u0 u0 u0 u0 u0r)   r    __main__z(Render Markdown to the console with Rich)descriptionpathPATHz%path to markdown file, or - for stdin)metavarhelpz-cz--force-colorforce_color
store_truezforce color for non-terminals)destactionr   rw  z-tz--code-themer   r%  zpygments code theme)rz  r   rw  z-iz--inline-code-lexerr&  z-yz--hyperlinksr  zenable hyperlinks)rz  r{  rw  z-wz--widthr   z*width of output (default will auto-detect))r   rz  r   rw  z-jz	--justifyrV   zenable full text justifyz-pz--pagepagezuse pager to scroll output)r   r   zutf-8)encodingfullrT   )rV   r   r  r&  )fileforce_terminalr   T)r  r   record)\
__future__r   sysdataclassesr   typingr   r   r   markdown_itr   markdown_it.tokenr	   
rich.tabler
   rl   r   _loopr   _stackr   r=   r   r   r   r   
containersr   jupyterr   ruler   segmentr   rY   r   r   r   r   r2   r   r   r   rM   rP   rc   rk   rn   r   r   r   r   r   r   r   r   r   r   r  r  r+   r    rG   argparseArgumentParserrU  add_argumentr   
parse_argsargsrich.consolert  stdinreadmarkdown_bodyopenmarkdown_filerV   r   r  r&  r   r|  iopydocStringIOfileiorx  r   printpagergetvaluer$   r)   r'   <module>r     s5   " " " " " " 



 ! ! ! ! ! ! / / / / / / / / / / " " " " " " # # # # # #                         I I I I I I I I I I I I # # # # # # ! ! ! ! ! !             $ $ $ $ $ $ $ $                      6 6 6 6 6 6 6 6r    _       /           (        
    k   D       2       4
 
 
 
 
_ 
 
 
& & & & &? & & &R	 	 	 	 	 	 	 		 	 	 	 	 	 	 		 	 	 	 	o 	 	 	' ' ' ' ' ' ' '>    /   @' ' ' ' '{ ' ' 'T    ;   % % % % % % % %P- - - - - - - -`w0 w0 w0 w0 w0| w0 w0 w0t zOOOJJJ$X$>  F 4    
 ,     "                  9     '     )     D$$$$$$yC	((T$)g... 	1-)..00M	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 x,2F??0  H y  			'(8

 
 
 	hFOO%%&&&&& '+4:d
 
 
 	h s   K88K<?K<