
    "Te7f                    0   d dl mZ d dlZd dlmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ ej                  dk\  rd dlmZ n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( d	dl)m*Z*m+Z+ d	dl,m-Z- d	dl.m/Z/m0Z0  G d d      Z1 G d de1      Z2 G d de1      Z3 G d de3      Z4 G d de3      Z5 G d  d!e3      Z6 G d" d#e3      Z7 G d$ d%e1      Z8 G d& d'e1      Z9 G d( d)e1      Z: G d* d+e1      Z; G d, d-e1      Z< G d. d/e1      Z= G d0 d1e1      Z> G d2 d3e3      Z? G d4 d5e3      Z@ G d6 d7e3      ZA G d8 d9      ZB G d: d;e"      ZCeDd<k(  rd dlEZEd dlZ eEj                  d=>      ZGeGj                  d?d@dAB       eGj                  dCdDdEdFddGH       eGj                  dIdJdKdLdMN       eGj                  dOdPdQddQN       eGj                  dRdSdTdFdUV       eGj                  dWdXeIdYddZ[       eGj                  d\d]d^dFd_V       eGj                  d`dadbdFdcV       eGj                         ZKd ddlLmZ eKj                  dek(  rej                  j                         ZPn. eQeKj                  dfdgh      5 ZReRj                         ZPddd        eCePeKj                  rdindjeKj                  eKj                  eKj                  k      ZWeKj                  rjd dlYZYd dlZZZ eYj                         Z\ ee\eKj                  eKj                  l      Zej                  eW        eZj                  e\j                                y eeKj                  eKj                  dmn      Zej                  eW       yy# 1 sw Y   xY w)o    )annotationsN)ClassVarDictIterableListOptionalTypeUnion)
MarkdownIt)Token)      )get_args)Table   box)
loop_first)Stack)ConsoleConsoleOptionsJustifyMethodRenderResult)Renderables)JupyterMixin)Panel)Rule)Segment)Style
StyleStack)Syntax)TextTextTypec                  n    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y
)MarkdownElementTzClassVar[bool]new_linec                     |        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
         clsmarkdowntokens      //usr/lib/python3/dist-packages/rich/markdown.pycreatezMarkdownElement.create!   s     u    c                     y)zuCalled when the node is entered.

        Args:
            context (MarkdownContext): The markdown context.
        Nr(   selfcontexts     r-   on_enterzMarkdownElement.on_enter.       r/   c                     y)zpCalled when text is parsed.

        Args:
            context (MarkdownContext): The markdown context.
        Nr(   r2   r3   texts      r-   on_textzMarkdownElement.on_text5   r5   r/   c                     y)zwCalled when the parser leaves the element.

        Args:
            context (MarkdownContext): [description]
        Nr(   r1   s     r-   on_leavezMarkdownElement.on_leave<   r5   r/   c                     y)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(   r2   r3   childs      r-   on_child_closezMarkdownElement.on_child_closeC   s     r/   c                     y)Nr(   r(   r2   consoleoptionss      r-   __rich_console__z MarkdownElement.__rich_console__S   s     r/   Nr+   
'Markdown'r,   r   return'MarkdownElement'r3   'MarkdownContext'rG   Noner3   rJ   r8   r#   rG   rK   r3   rJ   r>   rH   rG   bool)rB   z	'Console'rC   z'ConsoleOptions'rG   z'RenderResult')__name__
__module____qualname__r&   __annotations__classmethodr.   r4   r9   r;   r?   rD   r(   r/   r-   r%   r%      sg    #Hn#
 
(1B	  +;	r/   r%   c                      e Zd ZdZy)UnknownElementzAn unknown element.

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

    N)rO   rP   rQ   __doc__r(   r/   r-   rU   rU   Y   s    r/   rU   c                  ,    e Zd ZdZdZddZddZddZy)	TextElementz)Base class for elements that render text.nonec                f    |j                  | j                        | _        t        d      | _        y Nleftjustify)enter_style
style_namestyler"   r8   r1   s     r-   r4   zTextElement.on_enterg   s$    ((9
(	r/   c                ~    | j                   j                  |t        |t              r|j                         y d        y N)r8   append
isinstancestrcurrent_styler7   s      r-   r9   zTextElement.on_textk   s+    		
48Mw44XSWXr/   c                $    |j                          y rc   )leave_styler1   s     r-   r;   zTextElement.on_leaven   s    r/   NrI   rL   )rO   rP   rQ   rV   r`   r4   r9   r;   r(   r/   r-   rX   rX   b   s    3J)Yr/   rX   c                  N    e Zd ZU dZdZded<   ed	d       Zd
dZ	 	 	 	 	 	 ddZ	y)	ParagraphzA Paragraph.zmarkdown.paragraphr   r^   c                0     | |j                   xs d      S r[   r]   r)   s      r-   r.   zParagraph.createx   s    8++5v66r/   c                    || _         y rc   r]   r2   r^   s     r-   __init__zParagraph.__init__|   s	    r/   c              #  ^   K   | j                   | j                  _         | j                   y wrc   )r^   r8   rA   s      r-   rD   zParagraph.__rich_console__   s!      !LL		iis   +-N)r+   rF   r,   r   rG   z'Paragraph'r^   r   rG   rK   rB   r   rC   r   rG   r   )
rO   rP   rQ   rV   r`   rR   rS   r.   ro   rD   r(   r/   r-   rk   rk   r   sD    %J7 7)7	r/   rk   c                  R     e Zd ZdZedd       ZddZd fdZ	 	 	 	 	 	 d	dZ xZ	S )
Headingz
A heading.c                &     | |j                         S rc   )tagr)   s      r-   r.   zHeading.create   s    599~r/   c                X    t               | _        |j                  | j                         y rc   )r"   r8   r_   r`   r1   s     r-   r4   zHeading.on_enter   s    F	DOO,r/   c                D    || _         d| | _        t        |           y )N	markdown.)rv   r`   superro   )r2   rv   	__class__s     r-   ro   zHeading.__init__   s#    %cU+r/   c              #     K   | j                   }d|_        | j                  dk(  rt        |t        j
                  d       y | j                  dk(  rt        d       | y w)Ncenterh1zmarkdown.h1.border)r   ra   h2 )r8   r^   rv   r   r   HEAVYr"   )r2   rB   rC   r8   s       r-   rD   zHeading.__rich_console__   sZ      yy88tII*  xx42hJs   A#A%)r+   rF   r,   r   rG   z	'Heading'rI   )rv   rf   rG   rK   rr   )
rO   rP   rQ   rV   rS   r.   r4   ro   rD   __classcell__r{   s   @r-   rt   rt      s?     -
)7	r/   rt   c                  B    e Zd ZdZdZedd       ZddZ	 	 	 	 	 	 d	dZy)
	CodeBlockz&A code block with syntax highlighting.zmarkdown.code_blockc                x    |j                   xs d}|j                  d      d   } | |xs d|j                        S )Nr    r   r8   )info	partition
code_theme)r*   r+   r,   	node_info
lexer_names        r-   r.   zCodeBlock.create   s=    JJ$"	((-a0
:')<)<==r/   c                     || _         || _        y rc   )r   theme)r2   r   r   s      r-   ro   zCodeBlock.__init__   s    $
r/   c              #     K   t        | j                        j                         }t        || j                  | j
                  dd      }| y w)NTr   )r   	word_wrappadding)rf   r8   rstripr!   r   r   )r2   rB   rC   codesyntaxs        r-   rD   zCodeBlock.__rich_console__   sB      499~$$&$//tQ
 s   AAN)r+   rF   r,   r   rG   z'CodeBlock')r   rf   r   rf   rG   rK   rr   )	rO   rP   rQ   rV   r`   rS   r.   ro   rD   r(   r/   r-   r   r      s>    0&J> >
)7	r/   r   c                  D    e Zd ZdZdZddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 d	dZy)

BlockQuotezA block quote.zmarkdown.block_quotec                "    t               | _        y rc   r   elementsr2   s    r-   ro   zBlockQuote.__init__       %0]r/   c                :    | j                   j                  |       yNFr   rd   r=   s      r-   r?   zBlockQuote.on_child_close        	U#r/   c              #    K   |j                  |j                  dz
        }|j                  | j                  || j                        }| j                  }t        d      }t        d|      }|D ]  }| |E d {    |  y 7 w)N   widthra   
u   ▌ )update	max_widthrender_linesr   ra   r   )	r2   rB   rC   render_optionslinesra   r&   r   lines	            r-   rD   zBlockQuote.__rich_console__   s      !g.?.?!.CD$$T]]N$**$U

4=&%( 	DMOON	s   A9B	;B<B	NrG   rK   rM   rr   )rO   rP   rQ   rV   r`   ro   r?   rD   r(   r/   r-   r   r      sI    'J3(1B	)7	r/   r   c                  (    e Zd ZdZdZ	 	 	 	 	 	 ddZy)HorizontalRulez%A horizontal rule to divide sections.Fc              #  N   K   |j                  dd      }t        |       y w)Nzmarkdown.hrrY   defaultr   )	get_styler   )r2   rB   rC   ra   s       r-   rD   zHorizontalRule.__rich_console__   s(      !!-!@s   #%Nrr   )rO   rP   rQ   rV   r&   rD   r(   r/   r-   r   r      s'    /H  )7 	 r/   r   c                  @    e Zd ZdZddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZy)	TableElementz.MarkdownElement corresponding to `table_open`.c                     d | _         d | _        y rc   )headerbodyr   s    r-   ro   zTableElement.__init__   s    15-1	r/   c                x    t        |t              r|| _        yt        |t              r|| _        yt        d      )Nz Couldn't process markdown table.F)re   TableHeaderElementr   TableBodyElementr   RuntimeErrorr=   s      r-   r?   zTableElement.on_child_close   sB     e/0DK
 	 /0DI  ABBr/   c              #    K   t        t        j                        }| j                  V| j                  j                  @| j                  j                  j
                  D ]  }|j                  |j                          | j                  M| j                  j                  D ]4  }|j
                  D cg c]  }|j                   }} |j                  |  6 | y c c}w w)Nr   )r   r   SIMPLE_HEAVYr   rowcells
add_columncontentr   rowsadd_row)r2   rB   rC   tablecolumnr   elementrow_contents           r-   rD   zTableElement.__rich_console__   s      #**+;;"t{{'B++//// 1  01 99 yy~~ ,>AiiH7wHH{+,  Is   B0C"2CC"Nr   rM   rr   )rO   rP   rQ   rV   ro   r?   rD   r(   r/   r-   r   r      sD    82	(	1B			)7	r/   r   c                  ,    e Zd ZdZddZ	 	 	 	 	 	 ddZy)r   z@MarkdownElement corresponding to `thead_open` and `thead_close`.c                    d | _         y rc   )r   r   s    r-   ro   zTableHeaderElement.__init__  s	    +/r/   c                6    t        |t              sJ || _        yr   )re   TableRowElementr   r=   s      r-   r?   z!TableHeaderElement.on_child_close  s     %111r/   Nr   rM   rO   rP   rQ   rV   ro   r?   r(   r/   r-   r   r     s'    J0(1B	r/   r   c                  ,    e Zd ZdZddZ	 	 	 	 	 	 ddZy)r   z@MarkdownElement corresponding to `tbody_open` and `tbody_close`.c                    g | _         y rc   )r   r   s    r-   ro   zTableBodyElement.__init__  s	    +-	r/   c                ^    t        |t              sJ | j                  j                  |       yr   )re   r   r   rd   r=   s      r-   r?   zTableBodyElement.on_child_close!  s)     %111		r/   Nr   rM   r   r(   r/   r-   r   r     s'    J.(1B	r/   r   c                  ,    e Zd ZdZddZ	 	 	 	 	 	 ddZy)r   z:MarkdownElement corresponding to `tr_open` and `tr_close`.c                    g | _         y rc   )r   r   s    r-   ro   zTableRowElement.__init__,  s	    -/
r/   c                ^    t        |t              sJ | j                  j                  |       yr   )re   TableDataElementr   rd   r=   s      r-   r?   zTableRowElement.on_child_close/  s*     %!1222

% r/   Nr   rM   r   r(   r/   r-   r   r   )  s'    D0(1B	r/   r   c                  2    e Zd ZdZedd       ZddZddZy)	r   z[MarkdownElement corresponding to `td_open` and `td_close`
    and `th_open` and `th_close`.c                    t        |j                  j                  d            xs d}d|v rd}nd|v rd}n	d|v rd}nd	}|t        t              v sJ  | |
      S )Nra   r   ztext-align:rightrightztext-align:centerr}   ztext-align:leftr\   r   r]   )rf   attrsgetr   r   )r*   r+   r,   ra   r^   s        r-   r.   zTableDataElement.create;  sj    EKKOOG,-3 &G E)G%'GG(=11117##r/   c                6    t        d|      | _        || _        y )Nr   r]   )r"   r   r^   rn   s     r-   ro   zTableDataElement.__init__L  s    !"g6r/   c                    t        |t              rt        |      n|}|j                  |j                         | j
                  j                  |       y rc   )re   rf   r"   stylizerg   r   append_textr7   s      r-   r9   zTableDataElement.on_textP  s:    'c2tDzW**+  &r/   NrE   rq   rL   )rO   rP   rQ   rV   rS   r.   ro   r9   r(   r/   r-   r   r   7  s%    % $ $ 'r/   r   c                  R    e Zd ZdZedd       ZddZ	 	 	 	 	 	 d	dZ	 	 	 	 	 	 d
dZy)ListElementzA list element.c           	     n     | |j                   t        |j                  j                  dd                  S )Nstartr   )typeintr   r   r)   s      r-   r.   zListElement.createY  s'    5::s5;;??7A#>?@@r/   c                .    g | _         || _        || _        y rc   )items	list_type
list_start)r2   r   r   s      r-   ro   zListElement.__init__]  s    %'
"$r/   c                ^    t        |t              sJ | j                  j                  |       yr   )re   ListItemr   rd   r=   s      r-   r?   zListElement.on_child_closeb  s)     %***

% r/   c              #  f  K   | j                   dk(  r,| j                  D ]  }|j                  ||      E d {     y | j                  dn| j                  }|t	        | j                        z   }t        | j                        D ]$  \  }}|j                  ||||z   |      E d {    & y 7 v7 	w)Nbullet_list_openr   )r   r   render_bulletr   len	enumeraterender_number)r2   rB   rC   itemnumberlast_numberindexs          r-   rD   zListElement.__rich_console__i  s      >>//

 @--gw???@ //1QtF 3tzz?2K(4 t--Wfunk  	 @
s"   4B1B-A.B1%B/&B1/B1N)r+   rF   r,   r   rG   z'ListElement')r   rf   r   z
int | NonerG   rK   rM   rr   )	rO   rP   rQ   rV   rS   r.   ro   r?   rD   r(   r/   r-   r   r   V  sX    A A%
(1B	)7	r/   r   c                  T    e Zd ZdZdZddZ	 	 	 	 	 	 d	dZd
dZ	 	 	 	 	 	 	 	 	 	 ddZy)r   zAn item in a list.zmarkdown.itemc                "    t               | _        y rc   r   r   s    r-   ro   zListItem.__init__}  r   r/   c                :    | j                   j                  |       yr   r   r=   s      r-   r?   zListItem.on_child_close  r   r/   c              #  \  K   |j                  |j                  dz
        }|j                  | j                  || j                        }|j                  dd      }t        d|      }t        d|      }t        d	      }t        |      D ]  \  }	}
|	r|n| |
E d {    |  y 7 w)
Nr   r   r   zmarkdown.item.bulletrY   r   u    • z   r   )r   r   r   r   ra   r   r   r   )r2   rB   rC   r   r   bullet_stylebulletr   r&   firstr   s              r-   r   zListItem.render_bullet  s      g.?.?!.CD$$T]]N$**$U(()?(P,/'<04=%e, 	KE4!&w.OON	s   BB,B*B,c              #    K   t        t        |            dz   }|j                  |j                  |z
        }|j	                  | j
                  || j                        }|j                  dd      }t        d      }	t        d|z  |      }
t        | j                  |d	z
        dz   |      }t        |      D ]  \  }}|r|n|
 |E d {    |	  y 7 w)
N   r   r   zmarkdown.item.numberrY   r   r   r   r   )r   rf   r   r   r   r   ra   r   r   rjustr   )r2   rB   rC   r   r   number_widthr   r   number_styler&   r   numeralr   r   s                 r-   r   zListItem.render_number  s      3{+,q0 g.?.?,.NO$$T]]N$**$U(()?(P4=#,l;VH++L1,<=C\R%e, 	KE4"'/OON	s   CCCCNr   rM   rr   )
rB   r   rC   r   r   r   r   r   rG   r   )	rO   rP   rQ   rV   r`   ro   r?   r   r   r(   r/   r-   r   r   x  s^     J3(1B	)7ADSV	r/   r   c                  &    e Zd Zedd       ZddZy)Linkc                r    |j                   j                  dd      } | |j                  t        |            S )Nhref#)r   r   r   rf   )r*   r+   r,   urls       r-   r.   zLink.create  s+    kkoofc*5==#c(++r/   c                2    t        |      | _        || _        y rc   )r"   r8   r  )r2   r8   r  s      r-   ro   zLink.__init__  s    J		r/   NrE   )r8   rf   r  rf   )rO   rP   rQ   rS   r.   ro   r(   r/   r-   r  r    s    , ,r/   r  c                  Z     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.Fc                n     | t        |j                  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
        srcr   )rf   r   r   
hyperlinksr)   s      r-   r.   zImageItem.create  s+     3u{{ub12H4G4GHHr/   c                L    || _         || _        d | _        t        |           y rc   )destinationr  linkrz   ro   )r2   r  r  r{   s      r-   ro   zImageItem.__init__  s$    &$#'	r/   c                |    |j                   j                  | _        t        d      | _        t        |   |       y r[   )rg   r  r"   r8   rz   r4   )r2   r3   r{   s     r-   r4   zImageItem.on_enter  s/    ))..	(	!r/   c              #  Z  K   t        | j                  xs | j                  xs d       }| j                  xs7 t	        | j                  j                  d      j                  dd      d         }| j                  r|j                  |       t	        j                  d|dd      }| y w)	Nr  /r   u   🌆 r   r   )end)
r   r  r  r8   r"   striprsplitr  r   assemble)r2   rB   rC   
link_styletitler8   s         r-   rD   zImageItem.__rich_console__  s      		 ET-=-= EF
		QT$"2"2"8"8"="D"DS!"LR"PQ??MM*%}}WeSb9
s   B)B+rE   )r  rf   r  rN   rG   rK   rI   rr   )rO   rP   rQ   rV   r&   rS   r.   ro   r4   rD   r   r   s   @r-   r  r    sF    -H
I 
I"
)7	r/   r  c                  ^    e Zd ZdZ	 	 d	 	 	 	 	 	 	 	 	 	 	 d	dZed
d       ZddZddZd
dZ	y)MarkdownContextz!Manages the console render state.Nc                    || _         || _        t        |      | _        t	               | _        d | _        |t        d||      | _        y y )Nr   )r   )rB   rC   r    style_stackr   stack_syntaxr!   )r2   rB   rC   ra   inline_code_lexerinline_code_themes         r-   ro   zMarkdownContext.__init__  sL     '1%'8-2W
)-(!"&7?PQDL )r/   c                .    | j                   j                  S )z>Current style which is the product of all styles on the stack.)r  currentr   s    r-   rg   zMarkdownContext.current_style  s     '''r/   c                f   |dv r| j                   {| j                   j                  |      }|j                          | j                  j                  j                  | t        j                  || j                  j                               y| j                  j                  j                  | |       y)z#Called when the parser visits text.>   fencecode_inlineNr   )
r  	highlightr   r  topr9   r"   r  r  r#  )r2   r8   	node_typehighlight_texts       r-   r9   zMarkdownContext.on_text  s    00T\\5M!\\33D9N!!#JJNN""dmmN$:J:J:R:RS JJNN""4.r/   c                    | j                   j                  |d      }| j                  j                  |       | j                  S )zEnter a style context.rY   r   )rB   r   r  pushrg   )r2   r`   ra   s      r-   r_   zMarkdownContext.enter_style  s;    &&z6&Be$!!!r/   c                :    | j                   j                         }|S )zLeave a style context.)r  pop)r2   ra   s     r-   ri   zMarkdownContext.leave_style  s      $$&r/   )Nmonokai)rB   r   rC   r   ra   r   r   Optional[str]r!  rf   rG   rK   )rG   r   )r8   rf   r)  rf   rG   rK   )r`   Union[str, Style]rG   r   )
rO   rP   rQ   rV   ro   propertyrg   r9   r_   ri   r(   r/   r-   r  r    sv    + ,0!*RR  R 	R
 )R R 
R" ( (	/"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	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 ddZy)Markdowna  A Markdown renderable.

    Args:
        markup (str): A string containing markdown.
        code_theme (str, optional): Pygments theme for code blocks. Defaults to "monokai".
        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_openr%  
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   strongNc                    t               j                  d      j                  d      }|| _        |j                  |      | _        || _        || _        || _        || _        || _	        |xs || _
        y )Nstrikethroughr   )r   enablemarkupparseparsedr   r^   ra   r  r   r!  )	r2   rI  r   r^   ra   r  r   r!  parsers	            r-   ro   zMarkdown.__init__+  si     $$_5<<WEll6*$07
$!2!2!@jr/   c              #     K   |D ]X  }|j                   dk(  }|j                  dk(  }|j                  r(|s&|s$| j                  |j                        E d{    U| Z y7 w)zFlattens the token stream.r%  imgN)r   rv   children_flatten_tokens)r2   tokensr,   is_fenceis_images        r-   rP  zMarkdown._flatten_tokens?  s_      	EzzW,HyyE)H~~x8//???	 @s   AA#A!A#c              #  
  K   |j                  | j                  d      }|j                  d      }t        |||| j                  | j
                        }| j                  }| j                  }d}t        j                         }| j                  |      D ]  }	|	j                  }
|	j                  }|	j                  dk(  }|	j                  dk(  }|	j                  d	k(  }|
d
k(  r|j                  |	j                  |
       k|
dk(  r|j                  d|
       |
dk(  r|j                  d|
       |
dk(  rt!        |	j"                  j%                  dd            }| j&                  r5|j                  dd      }|t)        |      z  }|j+                  |       |j,                  j/                  t0        j3                  | |	             7|
dk(  r| j&                  r|j5                          [|j,                  j7                         }t9        |t0              sJ |j                  dd      }|j+                  |       |j                  |j:                  j<                  |
       |j5                          |j                  d|
       |j                  dd      }|j+                  |       |j                  |j>                  |
       |j5                          |j                  d|
       W||v r|
dk7  r|
dk7  rz|r|j+                  d|        }|r|j5                          |j+                  d|        |	j                  r|j                  |	j                  |
       |j5                          | j@                  j%                  |	j                        xs tB        }|j3                  | |	      }|s|r,|j,                  j/                  |       |jE                  |       |r|j,                  j7                         }|j,                   xs4 |j,                  xr& |j,                  jF                  jI                  ||      }|r|r| |jK                  ||jL                        E d{    n|r|j,                  j7                          |	j                  }||j                  ||       |j,                   xs4 |j,                  xr& |j,                  jF                  jI                  ||      }|r*|r| |jK                  ||jL                        E d{    |s|s|jO                  |       |jP                  } y7 7 -w)zRender markdown to the console.rY   r   N)height)r   r!  Fr   r  r   r8   	hardbreakr   	softbreakr   	link_openr  r   zmarkdown.link_urlr  
link_closezmarkdown.linkz ()r%  r7  ry   ))r   ra   r   r  r   r!  rK  inlinesr   r   rP  r   rv   nestingr9   r   rf   r   r   r  r   r_   r  r,  r  r.   ri   r.  re   r8   plainr  r   rU   r4   r(  r?   renderrC   r;   r&   )r2   rB   rC   ra   r3   rQ  inline_style_tagsr&   _new_line_segmentr,   r)  rv   enteringexitingself_closingr  r  r   link_url_styleelement_classshould_renderr8   s                         r-   rD   zMarkdown.__rich_console__I  s     !!$**f!=...-!"44"44
  LL#LLN))&1 c	0E

I))C}})Hmmr)G ==A-LF"y9k)i0k)Y/k)5;;??6267??!(!2!23FPV!2!WJ%T"22J''
3MM&&t{{4'?@l*??'')%mm//1G%gt444!(!2!2?F!2!SJ''
3OOGLL$6$6	B'')OOD)4%,%6%6+V &7 &N ''7OOGLL)<'')OOC3(((- '')C5(9: '') '')C5(9:}}yA'') !% 1 1%** = O'..tU;|MM&&w/$$W-%mm//1G(/$5 % O#MM--<<WgN "
 %#"33#*>>'7??#KKK!MM%%' ==D'6 $MM) O"== O#MM--<<WgN "
 %#"33#*>>'7??#KKKl$$W-&//HGc	0` L Ls+   Q'U)U*B+UUU "UU)r/  NrY   TNN)rI  rf   r   rf   r^   zOptional[JustifyMethod]ra   r1  r  rN   r   r0  r!  r0  rG   rK   )rQ  Iterable[Token]rG   rg  rr   )rO   rP   rQ   rV   rk   rt   r   r   r   r   r   r  r   r   r   r   r   r   rR   r[  ro   rP  rD   r(   r/   r-   r4  r4    ss   <)<< 	< 	i	<
 	:< 	n< 	K< 	[< 	(< 	< 	l< 	&< 	(< 	?< 	#<  	#!<H8 & ,G
 $+/#)+/+/AA A )	A
 !A A )A )A 
A(u0u0)7u0	u0r/   r4  __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   rm  z-tz--code-themer   r/  zpygments code theme)rp  r   rm  z-iz--inline-code-lexerr   z-yz--hyperlinksr  zenable hyperlinks)rp  rq  rm  z-wz--widthr   z*width of output (default will auto-detect))r   rp  r   rm  z-jz	--justifyr^   zenable full text justifyz-pz--pagepagezuse pager to scroll output)r   -rtzutf-8)encodingfullr\   )r^   r   r  r   )fileforce_terminalr   T)rx  r   record)b
__future__r   systypingr   r   r   r   r   r	   r
   markdown_itr   markdown_it.tokenr   version_infor   typing_extensions
rich.tabler   r   r   _loopr   _stackr   rB   r   r   r   r   
containersr   jupyterr   panelr   ruler   segmentr   ra   r   r    r   r!   r8   r"   r#   r%   rU   rX   rk   rt   r   r   r   r   r   r   r   r   r   r   r  r  r  r4  rO   argparseArgumentParserrL  add_argumentr   
parse_argsargsrich.consolerj  stdinreadmarkdown_bodyopenmarkdown_filer^   r   r  r   r+   rr  iopydocStringIOfileiorn  r   printpagergetvaluer(   r/   r-   <module>r     s   " 
 H H H " #v*     I I # !    $   8 8v_ /   ( k  F 2 8	 _ 	  ?  F  o ' '>/ D){ )X; % %P- -`w0| w0t z$X$$>F 4  
 ,   "            9   '   )   D$yyC		($))TG4 	1)..0M	1 ,,F????00H yy(8(8


 	hFOO%& ++4::d
 	h L	1 	1s   NN