
    \.iAf                       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=>      ZAeAj                  d?d@dAB       eAj                  dCdDdEdFddGH       eAj                  dIdJdKdLdMN       eAj                  dOdPdQddQN       eAj                  dRdSdTdFdUV       eAj                  dWdXeCdYddZ[       eAj                  d\d]d^dFd_V       eAj                  d`dadbdFdcV       eAj                         ZEd ddlFmZ eEj                  dek(  rej                  j                         ZJn- eKeEj                  dfg      5 ZLeLj                         ZJddd        e=eJeEj                  rdhndieEj                  eEj                  eEj                  j      ZQeEj                  rjd dlSZSd dlTZT eSj                         ZV eeVeEj                  eEj                  k      Zej                  eQ        eTj                  eVj                                y eeEj                  eEj                  dlm      Zej                  eQ       yy# 1 sw Y   xY w)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                  b    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      I/mnt/e/genesis-system/.venv/lib/python3.12/site-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    r*   r+   texts      r%   on_textzMarkdownElement.on_text0   r-   r'   c                     y)zwCalled when the parser leaves the element.

        Args:
            context (MarkdownContext): [description]
        Nr    r)   s     r%   on_leavezMarkdownElement.on_leave7   r-   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    r*   r+   childs      r%   on_child_closezMarkdownElement.on_child_close>   s     r'   c                     y)Nr    r    r*   consoleoptionss      r%   __rich_console__z MarkdownElement.__rich_console__L   s     r'   Nr#   Markdownr$   r	   returnr   r+   MarkdownContextr?   Noner+   rA   r0   r   r?   rB   r+   rA   r6   r   r?   boolr:   r   r;   r   r?   r   )__name__
__module____qualname__r   __annotations__classmethodr&   r,   r1   r3   r7   r<   r    r'   r%   r   r      sO    #Hn#
 
)7	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)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y)	TextElementz)Base class for elements that render text.nonec                f    |j                  | j                        | _        t        d      | _        y Nleftjustify)enter_style
style_namestyler   r0   r)   s     r%   r,   zTextElement.on_enter`   s$    ((9
(	r'   c                ~    | j                   j                  |t        |t              r|j                         y d        y N)r0   append
isinstancestrcurrent_styler/   s      r%   r1   zTextElement.on_textd   s+    		
48Mw44XSWXr'   c                $    |j                          y r[   )leave_styler)   s     r%   r3   zTextElement.on_leaveg   s    r'   Nr@   rC   )rG   rH   rI   rN   rX   r,   r1   r3   r    r'   r%   rP   rP   [   s    3J)Yr'   rP   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   rV   c                0     | |j                   xs d      S rS   rU   r!   s      r%   r&   zParagraph.createq   s    8++5v66r'   c                    || _         y r[   rU   r*   rV   s     r%   __init__zParagraph.__init__u   s	    r'   c              #  ^   K   | j                   | j                  _         | j                   y wr[   )rV   r0   r9   s      r%   r<   zParagraph.__rich_console__x   s!      !LL		iis   +-N)r#   r>   r$   r	   r?   rc   rV   r   r?   rB   rF   )
rG   rH   rI   rN   rX   rJ   rK   r&   rg   r<   r    r'   r%   rc   rc   k   sD    %J7 7)7	r'   rc   c                  *    e Zd ZU dZded<   dZded<   y)HeadingFormatrT   r   rV    r^   rY   N)rG   rH   rI   rV   rJ   rY   r    r'   r%   rk   rk      s    #G]#E3Or'   rk   c                  p     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_ALIGNc                &     | |j                         S r[   )tagr!   s      r%   r&   zHeading.create   s    599~r'   c                X    t               | _        |j                  | j                         y r[   )r   r0   rW   rX   r)   s     r%   r,   zHeading.on_enter   s    F	DOO,r'   c                D    || _         d| | _        t        |           y )N	markdown.)rx   rX   superrg   )r*   rx   	__class__s     r%   rg   zHeading.__init__   s#    %cU+r'   c              #     K   | j                   j                         }| j                  j                  | j                  d      }||_        | y w)NrT   )r0   copyrv   getrx   rV   )r*   r:   r;   r0   heading_justifys        r%   r<   zHeading.__rich_console__   s@      yy~~**..txx@&
   AA)r#   r>   r$   r	   r?   rn   r@   )rx   r^   r?   rB   rF   )rG   rH   rI   rN   rv   rJ   rK   r&   r,   rg   r<   __classcell__r}   s   @r%   rn   rn      sd     7K3   -
)7	r'   rn   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 )Nrl    r   r0   )info	partition
code_theme)r"   r#   r$   	node_info
lexer_names        r%   r&   zCodeBlock.create   s=    JJ$"	((-a0
:')<)<==r'   c                     || _         || _        y r[   )r   theme)r*   r   r   s      r%   rg   zCodeBlock.__init__   s    $
r'   c              #     K   t        | j                        j                         }t        || j                  | j
                  dd      }| y w)NTr   )r   	word_wrappadding)r^   r0   rstripr   r   r   )r*   r:   r;   codesyntaxs        r%   r<   zCodeBlock.__rich_console__   sB      499~$$&$//tQ
 r   N)r#   r>   r$   r	   r?   r   )r   r^   r   r^   r?   rB   rF   )	rG   rH   rI   rN   rX   rK   r&   rg   r<   r    r'   r%   r   r      s>    0&J> >
)7	r'   r   c                  8    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 r[   r   elementsr*   s    r%   rg   zBlockQuote.__init__       %0]r'   c                :    | j                   j                  |       yNFr   r\   r5   s      r%   r7   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rY   
u   ▌ )update	max_widthrender_linesr   rY   r   )	r*   r:   r;   render_optionslinesrY   r   r   lines	            r%   r<   zBlockQuote.__rich_console__   s      !g.?.?!.CD$$T]]N$**$U

4=&%( 	DMOON	s   A9B	;B<B	Nr?   rB   rD   rF   )rG   rH   rI   rN   rX   rg   r7   r<   r    r'   r%   r   r      s1    'J3)7	r'   r   c                  (    e Zd ZdZdZ	 	 	 	 	 	 ddZy)HorizontalRulez%A horizontal rule to divide sections.Fc              #  h   K   |j                  dd      }t        |d       t                y w)Nzmarkdown.hrrQ   default-)rY   
characters)	get_styler   r   )r*   r:   r;   rY   s       r%   r<   zHorizontalRule.__rich_console__   s1      !!-!@3//fs   02NrF   )rG   rH   rI   rN   r   r<   r    r'   r%   r   r      s'    /H)7	r'   r   c                  4    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 r[   )headerbodyr   s    r%   rg   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)r]   TableHeaderElementr   TableBodyElementr   RuntimeErrorr5   s      r%   r7   zTableElement.on_child_close   s@    e/0DK
 	 /0DI  ABBr'   c              #    K   t        t        j                  dddd      }| j                  w| j                  j                  a| j                  j                  j
                  D ]>  }|j                  j                         }|j                  d       |j                  |       @ | j                  M| j                  j                  D ]4  }|j
                  D cg c]  }|j                   }} |j                  |  6 | y c c}w w)NFzmarkdown.table.borderT)r   pad_edgerY   	show_edgecollapse_paddingzmarkdown.table.header)r
   r   SIMPLEr   rowcellscontentr   stylize
add_columnr   rowsadd_row)	r*   r:   r;   tablecolumnheadingr   elementrow_contents	            r%   r<   zTableElement.__rich_console__   s      

)!
 ;;"t{{'B++//// * ..--/ 78  )*
 99 yy~~ ,>AiiH7wHH{+,  Is   CDD*DNr   rD   rF   )rG   rH   rI   rN   rg   r7   r<   r    r'   r%   r   r      s,    82)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 r[   )r   r   s    r%   rg   zTableHeaderElement.__init__  s	    +/r'   c                6    t        |t              sJ || _        yr   )r]   TableRowElementr   r5   s      r%   r7   z!TableHeaderElement.on_child_close  s    %111r'   Nr   rD   rG   rH   rI   rN   rg   r7   r    r'   r%   r   r     s    J0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 r[   )r   r   s    r%   rg   zTableBodyElement.__init__  s	    +-	r'   c                ^    t        |t              sJ | j                  j                  |       yr   )r]   r   r   r\   r5   s      r%   r7   zTableBodyElement.on_child_close"  s'    %111		r'   Nr   rD   r   r    r'   r%   r   r     s    J.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 r[   )r   r   s    r%   rg   zTableRowElement.__init__+  s	    -/
r'   c                ^    t        |t              sJ | j                  j                  |       yr   )r]   TableDataElementr   r\   r5   s      r%   r7   zTableRowElement.on_child_close.  s(    %!1222

% r'   Nr   rD   r   r    r'   r%   r   r   (  s    D0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 )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  sj    EKKOOG,-3 &G E)G%'GG(=11117##r'   c                6    t        d|      | _        || _        y )Nrl   rU   )r   r   rV   rf   s     r%   rg   zTableDataElement.__init__I  s    !"g6r'   c                    t        |t              rt        |      n|}|j                  |j                         | j
                  j                  |       y r[   )r]   r^   r   r   r_   r   append_textr/   s      r%   r1   zTableDataElement.on_textM  s:    'c2tDzW**+  &r'   Nr=   ri   rC   )rG   rH   rI   rN   rK   r&   rg   r1   r    r'   r%   r   r   4  s%    % $ $ 'r'   r   c                  F    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.createV  s'    5::s5;;??7A#>?@@r'   c                .    g | _         || _        || _        y r[   )items	list_type
list_start)r*   r   r   s      r%   rg   zListElement.__init__Z  s    %'
"$r'   c                ^    t        |t              sJ | j                  j                  |       yr   )r]   ListItemr   r\   r5   s      r%   r7   zListElement.on_child_close_  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)r*   r:   r;   itemnumberlast_numberindexs          r%   r<   zListElement.__rich_console__d  s      >>//

 @--gw???@ //1QtF 3tzz?2K(4 t--Wfunk  	 @
s"   4B1B-A.B1%B/&B1/B1N)r#   r>   r$   r	   r?   r   )r   r^   r   z
int | Noner?   rB   rD   rF   )	rG   rH   rI   rN   rK   r&   rg   r7   r<   r    r'   r%   r   r   S  s@    A A%

)7	r'   r   c                  H    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 r[   r   r   s    r%   rg   zListItem.__init__x  r   r'   c                :    | j                   j                  |       yr   r   r5   s      r%   r7   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)
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$$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.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$$T]]N$**$U(()?(P4=#,l;VH++L1,<=C\R%e, 	KE4"'/OON	s   CCCCNr   rD   rF   )
r:   r   r;   r   r   r   r   r   r?   r   )	rG   rH   rI   rN   rX   rg   r7   r   r   r    r'   r%   r   r   s  sF     J3)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   r^   )r"   r#   r$   urls       r%   r&   zLink.create  s+    kkoofc*5==#c(++r'   c                2    t        |      | _        || _        y r[   )r   r0   r
  )r*   r0   r
  s      r%   rg   zLink.__init__  s    J		r'   Nr=   )r0   r^   r
  r^   )rG   rH   rI   rK   r&   rg   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
        srcrl   )r^   r   r   
hyperlinksr!   s      r%   r&   zImageItem.create  s+     3u{{ub12H4G4GHHr'   c                L    || _         || _        d | _        t        |           y r[   )destinationr  linkr|   rg   )r*   r  r  r}   s      r%   rg   zImageItem.__init__  s$    &$ $	r'   c                |    |j                   j                  | _        t        d      | _        t        |   |       y rS   )r_   r  r   r0   r|   r,   )r*   r+   r}   s     r%   r,   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   rl   )end)
r   r  r  r0   r   striprsplitr  r   assemble)r*   r:   r;   
link_styletitler0   s         r%   r<   zImageItem.__rich_console__  s      		 ET-=-= EF
		QT$"2"2"8"8"="D"DS!"LR"PQ??MM*%}}WeSb9
s   B)B+r=   )r  r^   r  rE   r?   rB   r@   rF   )rG   rH   rI   rN   r   rK   r&   rg   r,   r<   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)rA   z!Manages the console render state.Nc                    || _         || _        t        |      | _        t	               | _        d | _        |t        d||      | _        y y )Nrl   )r   )r:   r;   r   style_stackr   stack_syntaxr   )r*   r:   r;   rY   inline_code_lexerinline_code_themes         r%   rg   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%   r_   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$  topr1   r   r  r#  r)  )r*   r0   	node_typehighlight_texts       r%   r1   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.rQ   r   )r:   r   r#  pushr_   )r*   rX   rY   s      r%   rW   zMarkdownContext.enter_style  s;    &&z6&Be$!!!r'   c                :    | j                   j                         }|S )zLeave a style context.)r#  pop)r*   rY   s     r%   ra   zMarkdownContext.leave_style  s      $$&r'   )Nmonokai)r:   r   r;   r   rY   r   r&  
str | Noner'  r^   r?   rB   )r?   r   )r0   r^   r/  r^   r?   rB   )rX   str | Styler?   r   )
rG   rH   rI   rN   rg   propertyr_   r1   rW   ra   r    r'   r%   rA   rA     sv    + )-!*RR  R 	R
 &R R 
R" ( (	/"r'   rA   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)r>   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_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   rV   rY   r  r&  r'  )	r*   rN  r   rV   rY   r  r&  r'  parsers	            r%   rg   zMarkdown.__init__$  si     $$_5<<WEll6*$-4
$!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   rx   children_flatten_tokens)r*   tokensr$   is_fenceis_images        r%   rU  zMarkdown._flatten_tokens8  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	|
dk7  r| |jK                  ||jL                        E d{    |s|s|jO                  |       |jP                  } y7 7 -w)zRender markdown to the console.rQ   r   N)height)r&  r'  Fr   r  r   r0   	hardbreakr   	softbreakr   	link_openr
  rl   zmarkdown.link_urlr  
link_closezmarkdown.linkz ()r+  r<  r{   inline))r   rY   r   rA   r&  r'  rP  inlinesr   r   rU  r   rx   nestingr1   r   r^   r   r   r  r   rW   r$  r2  r  r&   ra   r4  r]   r0   plainr
  r   rM   r,   r.  r7   renderr;   r3   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_renderr0   s                         r%   r<   zMarkdown.__rich_console__B  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 "
 %#	X(="33#*>>'7??#KKKl$$W-&//HGc	0` L Ls+   Q'U
)U*B0U
UU
%"U
U
)r5  NrQ   TNN)rN  r^   r   r^   rV   zJustifyMethod | NonerY   r7  r  rE   r&  r6  r'  r6  r?   rB   )rV  Iterable[Token]r?   rm  rF   )rG   rH   rI   rN   rc   rn   r   r   r   r   r   r  r   r   r   r   r   r   rJ   ra  rg   rU  r<   r    r'   r%   r>   r>      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'   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   rs  z-tz--code-themer   r5  zpygments code theme)rv  r   rs  z-iz--inline-code-lexerr&  z-yz--hyperlinksr  zenable hyperlinks)rv  rw  rs  z-wz--widthr   z*width of output (default will auto-detect))r   rv  r   rs  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   r0   r   r   r   rM   rP   rc   rk   rn   r   r   r   r   r   r   r   r   r   r   r  r  rA   r>   rG   argparseArgumentParserrQ  add_argumentr   
parse_argsargsrich.consolerp  stdinreadmarkdown_bodyopenmarkdown_filerV   r   r  r&  r#   rx  iopydocStringIOfileiort  r   printpagergetvaluer    r'   r%   <module>r     s   " 
 ! / / " #     I I # !   $   6 6r_ /   (   
k D 2 4
_ 
&? &R	 		 		o 	' '>/ @'{ 'T; % %P- -`w0| w0t z$X$$>F 4  
 ,   "            9   '   )   D$yyC		($))g. 	1-)..0M	1 ,,F????00H yy(8(8


 	hFOO%& ++4::d
 	h L	1 	1s   <M66M?