HEX
Server: nginx/1.28.0
System: Linux server-one 5.15.0-153-generic #163-Ubuntu SMP Thu Aug 7 16:37:18 UTC 2025 x86_64
User: root (0)
PHP: 8.3.23
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/rich/__pycache__/markdown.cpython-310.pyc
o

.��f7f�@sddlmZddlZddlmZmZmZmZmZm	Z	m
Z
ddlmZddl
mZejdkr4ddlmZnddlmZddlmZd	d
lmZd	dlmZd	dlmZd	d
lmZmZmZmZd	dlm Z d	dl!m"Z"d	dl#m$Z$d	dl%m&Z&d	dl'm(Z(d	dl)m*Z*m+Z+d	dl,m-Z-d	dl.m/Z/m0Z0Gdd�d�Z1Gdd�de1�Z2Gdd�de1�Z3Gdd�de3�Z4Gdd�de3�Z5Gd d!�d!e3�Z6Gd"d#�d#e3�Z7Gd$d%�d%e1�Z8Gd&d'�d'e1�Z9Gd(d)�d)e1�Z:Gd*d+�d+e1�Z;Gd,d-�d-e1�Z<Gd.d/�d/e1�Z=Gd0d1�d1e1�Z>Gd2d3�d3e3�Z?Gd4d5�d5e3�Z@Gd6d7�d7e3�ZAGd8d9�d9�ZBGd:d;�d;e"�ZCeDd<k�rddlEZEddlZeEjFd=d>�ZGeGjHd?d@dAdB�eGjHdCdDdEdFddGdH�eGjHdIdJdKdLdMdN�eGjHdOdPdQddQdN�eGjHdRdSdTdFdUdV�eGjHdWdXeIdYddZd[�eGjHd\d]d^dFd_dV�eGjHd`dadbdFdcdV�eG�J�ZKdddlLmZeKjMdek�r�ejN�O�ZPneQeKjMdfdgdh��ZReR�O�ZPWd�n	1�s�wYeCePeKjS�r�dindjeKjTeKjUeKjVdk�ZWeKjX�r�ddlYZYddlZZZeY�[�Z\ee\eKj]eKj^dl�Ze�_eW�eZ�`e\�a��dSeeKj]eKj^dmdn�Ze�_eW�dSdS)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@sZeZdZUdZded<ed#d
d��Zd$dd�Zd%dd�Zd$dd�Z	d&dd�Z
d'd d!�Zd"S)(�MarkdownElementTzClassVar[bool]�new_line�markdown�
'Markdown'�tokenr�return�'MarkdownElement'cCs|�S)z�Factory 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'r*r*�8/usr/local/lib/python3.10/dist-packages/rich/markdown.py�create!szMarkdownElement.create�context�'MarkdownContext'�NonecC�dS)zuCalled when the node is entered.

        Args:
            context (MarkdownContext): The markdown context.
        Nr*��selfr/r*r*r-�on_enter.�zMarkdownElement.on_enter�textr"cCr2)zpCalled when text is parsed.

        Args:
            context (MarkdownContext): The markdown context.
        Nr*�r4r/r7r*r*r-�on_text5r6zMarkdownElement.on_textcCr2)zwCalled when the parser leaves the element.

        Args:
            context (MarkdownContext): [description]
        Nr*r3r*r*r-�on_leave<r6zMarkdownElement.on_leave�child�boolcCr2)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*�r4r/r;r*r*r-�on_child_closeCszMarkdownElement.on_child_close�console�	'Console'�options�'ConsoleOptions'�'RenderResult'cCr2)Nr*r*�r4r?rAr*r*r-�__rich_console__Ssz MarkdownElement.__rich_console__N�r%r&r'rr(r)�r/r0r(r1�r/r0r7r"r(r1�r/r0r;r)r(r<)r?r@rArBr(rC)�__name__�
__module__�__qualname__r$�__annotations__�classmethodr.r5r9r:r>rEr*r*r*r-r#s




r#c@seZdZdZdS)�UnknownElementz�An unknown element.

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

    N)rJrKrL�__doc__r*r*r*r-rOYsrOc@s2eZdZdZdZddd�Zddd�Zdd
d�ZdS)�TextElementz)Base class for elements that render text.�noner/r0r(r1cCs|�|j�|_tdd�|_dS�N�left��justify)�enter_style�
style_name�styler!r7r3r*r*r-r5gszTextElement.on_enterr7r"cCs(|j�|t|t�r|j�dSd�dS�N)r7�append�
isinstance�str�
current_styler8r*r*r-r9ks(zTextElement.on_textcCs|��dSrZ)�leave_styler3r*r*r-r:n�zTextElement.on_leaveNrGrH)rJrKrLrPrXr5r9r:r*r*r*r-rQbs

rQc@s@eZdZUdZdZded<eddd��Zddd�Zddd�Z	dS)�	ParagraphzA Paragraph.zmarkdown.paragraphrrVr%r&r'rr(�'Paragraph'cCs||jpdd�SrSrUr+r*r*r-r.xszParagraph.creater1cCs
||_dSrZrU�r4rVr*r*r-�__init__|�
zParagraph.__init__r?rrArrccs�|j|j_|jVdSrZ)rVr7rDr*r*r-rEs�
zParagraph.__rich_console__N)r%r&r'rr(rb�rVrr(r1�r?rrArr(r)
rJrKrLrPrXrMrNr.rdrEr*r*r*r-rars

racsDeZdZdZeddd	��Zdd
d�Zd�fdd�Zddd�Z�Z	S)�Headingz
A heading.r%r&r'rr(�	'Heading'cCs
||j�SrZ)�tagr+r*r*r-r.�s
zHeading.creater/r0r1cCst�|_|�|j�dSrZ)r!r7rWrXr3r*r*r-r5�szHeading.on_enterrjr]cs ||_d|��|_t���dS)N�	markdown.)rjrX�superrd)r4rj��	__class__r*r-rd�szHeading.__init__r?rrArrccsL�|j}d|_|jdkrt|tjdd�VdS|jdkr!td�V|VdS)N�center�h1zmarkdown.h1.border)rrY�h2�)r7rVrjrr�HEAVYr!)r4r?rAr7r*r*r-rE�s�
�


zHeading.__rich_console__)r%r&r'rr(rirG)rjr]r(r1rg)
rJrKrLrPrNr.r5rdrE�
__classcell__r*r*rmr-rh�s
rhc@s6eZdZdZdZedd	d
��Zddd�Zddd�ZdS)�	CodeBlockz&A code block with syntax highlighting.zmarkdown.code_blockr%r&r'rr(�'CodeBlock'cCs(|jpd}|�d�d}||pd|j�S)Nrr� rr7)�info�	partition�
code_theme)r,r%r'�	node_info�
lexer_namer*r*r-r.�s
zCodeBlock.creater|r]�themer1cCs||_||_dSrZ)r|r})r4r|r}r*r*r-rd��
zCodeBlock.__init__r?rrArrccs0�t|j���}t||j|jddd�}|VdS)NTr)r}�	word_wrap�padding)r]r7�rstripr r|r})r4r?rA�code�syntaxr*r*r-rE�s��
zCodeBlock.__rich_console__N)r%r&r'rr(rv)r|r]r}r]r(r1rg)	rJrKrLrPrXrNr.rdrEr*r*r*r-ru�s
ruc@s2eZdZdZdZddd�Zddd
�Zddd�ZdS)�
BlockQuotezA block quote.zmarkdown.block_quoter(r1cC�t�|_dSrZ�r�elements�r4r*r*r-rd�r`zBlockQuote.__init__r/r0r;r)r<cC�|j�|�dS�NF�r�r[r=r*r*r-r>��zBlockQuote.on_child_closer?rrArrc	csd�|j|jdd�}|j|j||jd�}|j}td�}td|�}|D]
}|V|EdH|Vq"dS)N���width�rY�
u▌ )�update�	max_width�render_linesr�rYr)	r4r?rA�render_options�linesrYr$r��liner*r*r-rE�s�

�zBlockQuote.__rich_console__N�r(r1rIrg)rJrKrLrPrXrdr>rEr*r*r*r-r��s

r�c@seZdZdZdZdd	d
�ZdS)
�HorizontalRulez%A horizontal rule to divide sections.Fr?rrArr(rccs �|jddd�}t|d�VdS)Nzmarkdown.hrrR��defaultr�)�	get_styler)r4r?rArYr*r*r-rE�s�zHorizontalRule.__rich_console__Nrg)rJrKrLrPr$rEr*r*r*r-r��sr�c@s.eZdZdZddd�Zddd�Zddd�ZdS)�TableElementz.MarkdownElement corresponding to `table_open`.r(r1cCsd|_d|_dSrZ)�header�bodyr�r*r*r-rd�r~zTableElement.__init__r/r0r;r)r<cCs0t|t�r
||_dSt|t�r||_dStd��)Nz Couldn't process markdown table.F)r\�TableHeaderElementr��TableBodyElementr��RuntimeErrorr=r*r*r-r>�s

��zTableElement.on_child_closer?rrArrccs|�ttjd�}|jdur |jjdur |jjjD]}|�|j�q|jdur9|jj	D]}dd�|jD�}|j
|�q)|VdS)NrcSsg|]}|j�qSr*)�content)�.0�elementr*r*r-�
<listcomp>sz1TableElement.__rich_console__.<locals>.<listcomp>)rr�SIMPLE_HEAVYr��row�cells�
add_columnr�r��rows�add_row)r4r?rA�table�columnr��row_contentr*r*r-rE�s�

zTableElement.__rich_console__Nr�rIrg)rJrKrLrPrdr>rEr*r*r*r-r��s


r�c@�$eZdZdZddd�Zddd�Zd
S)r�z@MarkdownElement corresponding to `thead_open` and `thead_close`.r(r1cCs
d|_dSrZ)r�r�r*r*r-rdrezTableHeaderElement.__init__r/r0r;r)r<cCst|t�sJ�||_dSr�)r\�TableRowElementr�r=r*r*r-r>sz!TableHeaderElement.on_child_closeNr�rI�rJrKrLrPrdr>r*r*r*r-r�
�
r�c@r�)r�z@MarkdownElement corresponding to `tbody_open` and `tbody_close`.r(r1cC�
g|_dSrZ)r�r�r*r*r-rdrezTableBodyElement.__init__r/r0r;r)r<cC�t|t�sJ�|j�|�dSr�)r\r�r�r[r=r*r*r-r>!�zTableBodyElement.on_child_closeNr�rIr�r*r*r*r-r�r�r�c@r�)r�z:MarkdownElement corresponding to `tr_open` and `tr_close`.r(r1cCr�rZ)r�r�r*r*r-rd,rezTableRowElement.__init__r/r0r;r)r<cCr�r�)r\�TableDataElementr�r[r=r*r*r-r>/r�zTableRowElement.on_child_closeNr�rIr�r*r*r*r-r�)r�r�c@s2eZdZdZeddd	��Zdd
d�Zddd�ZdS)r�z[MarkdownElement corresponding to `td_open` and `td_close`
    and `th_open` and `th_close`.r%r&r'rr(r)cCs\t|j�d��p	d}d|vrd}nd|vrd}n	d|vrd}nd	}|tt�vs)J�||d
�S)NrYrrztext-align:right�rightztext-align:centerroztext-align:leftrTr�rU)r]�attrs�getrr)r,r%r'rYrVr*r*r-r.;s
zTableDataElement.createrVrr1cCstd|d�|_||_dS)NrrrU)r!r�rVrcr*r*r-rdLs
zTableDataElement.__init__r/r0r7r"cCs2t|t�r	t|�n|}|�|j�|j�|�dSrZ)r\r]r!�stylizer^r��append_textr8r*r*r-r9PszTableDataElement.on_textNrFrfrH)rJrKrLrPrNr.rdr9r*r*r*r-r�7s
r�c@s<eZdZdZed dd	��Zd!dd�Zd"dd�Zd#dd�ZdS)$�ListElementzA list element.r%r&r'rr(�
'ListElement'cCs||jt|j�dd���S)N�startr)�type�intr�r�r+r*r*r-r.YszListElement.create�	list_typer]�
list_start�
int | Noner1cCsg|_||_||_dSrZ)�itemsr�r�)r4r�r�r*r*r-rd]s
zListElement.__init__r/r0r;r)r<cCr�r�)r\�ListItemr�r[r=r*r*r-r>br�zListElement.on_child_closer?rrArrccs��|jdkr|jD]}|�||�EdHq	dS|jdurdn|j}|t|j�}t|j�D]\}}|�|||||�EdHq-dS)N�bullet_list_openr)r�r��
render_bulletr��len�	enumerate�
render_number)r4r?rA�item�number�last_number�indexr*r*r-rEis�

���zListElement.__rich_console__N)r%r&r'rr(r�)r�r]r�r�r(r1rIrg)	rJrKrLrPrNr.rdr>rEr*r*r*r-r�Vs

r�c@s<eZdZdZdZddd�Zddd
�Zddd�Zddd�ZdS)r�zAn item in a list.z
markdown.itemr(r1cCr�rZr�r�r*r*r-rd}r`zListItem.__init__r/r0r;r)r<cCr�r�r�r=r*r*r-r>�r�zListItem.on_child_closer?rrArrccs��|j|jdd�}|j|j||jd�}|jddd�}td|�}td|�}td	�}t|�D]\}	}
|	r5|n|V|
EdH|Vq-dS)
Nrr�r�zmarkdown.item.bulletrRr�u • z   r�)r�r�r�r�rYr�rr)r4r?rAr�r��bullet_style�bulletr�r$�firstr�r*r*r-r��s�


�zListItem.render_bulletr�r�r�ccs��tt|��d}|j|j|d�}|j|j||jd�}|jddd�}td�}	td||�}
t|��	|d	�d|�}t
|�D]\}}
|rG|n|
V|
EdH|	Vq?dS)
N�r�r�zmarkdown.item.numberrRr�r�rwr)r�r]r�r�r�r�rYr�r�rjustr)r4r?rAr�r��number_widthr�r��number_styler$r��numeralr�r�r*r*r-r��s�
�zListItem.render_numberNr�rIrg)
r?rrArr�r�r�r�r(r)	rJrKrLrPrXrdr>r�r�r*r*r*r-r�xs



r�c@s$eZdZeddd��Zddd
�ZdS)�Linkr%r&r'rr(r)cCs|j�dd�}||jt|��S)N�href�#)r�r�r�r])r,r%r'�urlr*r*r-r.�szLink.creater7r]r�cCst|�|_||_dSrZ)r!r7r�)r4r7r�r*r*r-rd�s

z
Link.__init__NrF)r7r]r�r])rJrKrLrNr.rdr*r*r*r-r��sr�csLeZdZdZdZedd	d
��Zd�fdd�Zd�fdd�Zd dd�Z	�Z
S)!�	ImageItemz#Renders a placeholder for an image.Fr%r&r'rr(r)cCs|t|j�dd��|j�S)z�Factory to create markdown element,

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

        Returns:
            MarkdownElement: A new markdown element
        �srcrr)r]r�r��
hyperlinksr+r*r*r-r.�szImageItem.create�destinationr]r�r<r1cs ||_||_d|_t���dSrZ)r�r��linkrlrd)r4r�r�rmr*r-rd�szImageItem.__init__r/r0cs&|jj|_tdd�|_t��|�dSrS)r^r�r!r7rlr5r3rmr*r-r5�s
zImageItem.on_enterr?rrArrccsf�t|jp	|jp	dd�}|jpt|j�d��dd�d�}|jr%|�|�tj	d|ddd�}|VdS)	N�r��/r���u🌆 rwrr)�end)
rr�r�r7r!�strip�rsplitr�r��assemble)r4r?rA�
link_style�titler7r*r*r-rE�s�"

zImageItem.__rich_console__rF)r�r]r�r<r(r1rGrg)rJrKrLrPr$rNr.rdr5rErtr*r*rmr-r��sr�c@sLeZdZdZ		dddd�Zed dd��Zd!dd�Zd"dd�Zd dd�Z	dS)#�MarkdownContextz!Manages the console render state.N�monokair?rrArrYr�inline_code_lexer�
Optional[str]�inline_code_themer]r(r1cCsD||_||_t|�|_t�|_d|_|dur td||d�|_dSdS)Nrr)r})r?rAr�style_stackr�stack�_syntaxr )r4r?rArYr�r�r*r*r-rd�s
�zMarkdownContext.__init__cCs|jjS)z>Current style which is the product of all styles on the stack.)r��currentr�r*r*r-r^�szMarkdownContext.current_styler7�	node_typecCs\|dvr$|jdur$|j�|�}|��|jj�|tj||jj	d��dS|jj�||�dS)z#Called when the parser visits text.>�fence�code_inlineNr�)
r��	highlightr�r��topr9r!r�r�r�)r4r7r��highlight_textr*r*r-r9�s�zMarkdownContext.on_textrX�Union[str, Style]cCs"|jj|dd�}|j�|�|jS)zEnter a style context.rRr�)r?r�r��pushr^)r4rXrYr*r*r-rW�szMarkdownContext.enter_stylecCs|j��}|S)zLeave a style context.)r��pop)r4rYr*r*r-r_s
zMarkdownContext.leave_style)Nr�)r?rrArrYrr�r�r�r]r(r1)r(r)r7r]r�r]r(r1)rXr�r(r)
rJrKrLrPrd�propertyr^r9rWr_r*r*r*r-r��s�

r�c@s�eZdZUdZide�de�de�de�de�de�de	�d	e	�d
e
�de�de�d
e
�de�de�de�de�Zded<hd�Z						d4d5d'd(�Zd6d+d,�Zd7d2d3�ZdS)8�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��strongr�NrRT�markupr]rzrV�Optional[JustifyMethod]rYr�r�r<r�r�r�r(r1c	CsPt��d��d�}||_|�|�|_||_||_||_||_||_	|p$||_
dS)N�
strikethroughr�)r
�enabler�parse�parsedrzrVrYr�r�r�)	r4rrzrVrYr�r�r��parserr*r*r-rd+s
zMarkdown.__init__�tokens�Iterable[Token]ccsL�|D] }|jdk}|jdk}|jr |s |s |�|j�EdHq|VqdS)zFlattens the token stream.r��imgN)r�rj�children�_flatten_tokens)r4rr'�is_fence�is_imager*r*r-r?s�

�zMarkdown._flatten_tokensr?rrArrccsx�|j|jdd�}|jdd�}t||||j|jd�}|j}|j}d}t�	�}|�
|�D�]�}	|	j}
|	j}|	j
dk}|	j
dk}
|	j
d	k}|
d
krO|�|	j|
�q+|
dkrZ|�d|
�q+|
d
kre|�d|
�q+|
dkr�t|	j�dd��}|jr�|jddd�}|t|d�7}|�|�q+|j�t�||	��q+|
dkr�|jr�|��q+|j��}t|t�s�J�|jddd�}|�|�|�|jj|
�|��|�d|
�|jddd�}|�|�|�|j|
�|��|�d|
�q+||v�r#|
dk�r#|
dk�r#|�r|�d|���q+|
�r|��q+|�d|���|	j�r|�|	j|
�|��q+|j �|	j��p,t!}|�||	�}|�s9|�rD|j�|�|�"|�|
�rq|j��}|j�p\|j�o\|jj#�$||�}|�rp|�rf|V|�%||j&�EdHn:|�r�|j��|	j}|du�r�|�||�|j�p�|j�o�|jj#�$||�}|�r�|�r�|V|�%||j&�EdH|
�s�|�r�|�'|�|j(}q+dS)zRender markdown to the console.rRr�N)�height)r�r�Frr�rr7�	hardbreakr��	softbreakrw�	link_openr�rrzmarkdown.link_urlr��
link_closez
markdown.linkz (�)r�rrk))r�rYr�r�r�r�r�inlinesrr�rr�rj�nestingr9r�r]r�r�r�rrWr�r�r�r.r_r�r\r7�plainr�r�rOr5r�r>�renderrAr:r$)r4r?rArYr/r�inline_style_tagsr$�_new_line_segmentr'r�rj�entering�exiting�self_closingr�r�r��link_url_style�
element_class�
should_renderr7r*r*r-rEIs���





�








��


�
��zMarkdown.__rich_console__)r�NrRTNN)rr]rzr]rVrrYr�r�r<r�r�r�r�r(r1)rrr(rrg)rJrKrLrPrarhrur�r�r�r�r�r�r�r�r�r�r�rMr#rdrrEr*r*r*r-r�sZ
��������	�
���
�����

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_truezforce color for non-terminals)�dest�actionr�r4z-tz--code-themerzr�zpygments code theme)r7r�r4z-iz--inline-code-lexerr�z-yz--hyperlinksr�zenable hyperlinks)r7r8r4z-wz--widthr�z*width of output (default will auto-detect))r�r7r�r4z-jz	--justifyrVzenable full text justifyz-pz--page�pagezuse pager to scroll output)r�-�rtzutf-8)�encoding�fullrT)rVrzr�r�)�file�force_terminalr�T)r?r��record)b�
__future__r�sys�typingrrrrrrr	�markdown_itr
�markdown_it.tokenr�version_infor�typing_extensions�
rich.tablerrrr�_loopr�_stackrr?rrrr�
containersr�jupyterr�panelr�ruler�segmentrrYrrr�r r7r!r"r#rOrQrarhrur�r�r�r�r�r�r�r�r�r�r�r�r�rJ�argparse�ArgumentParserr�add_argumentr��
parse_args�args�rich.consoler1�stdin�read�
markdown_body�open�
markdown_filerVrzr�r�r%r9�io�pydoc�StringIO�fileior5r��print�pager�getvaluer*r*r*r-�<module>s$
;	##",(0
;���������
��
�

��