o
    ¤i£€  ã                   @   sj  d Z ddlmZ ddlmZ ddlmZmZ ddlZ	ddl
Z	ddlZ	ddlZ	ddl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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Z+dZ,dZ-e$ƒ  G dd„ deƒZ.dd„ Z/dd„ Z0G dd„ de	j1j2ƒZ3G dd„ deƒZ4e4 Z5 Z6 Z7Z8dS ) zÀ
reStructuredText parser for rich

Initial few lines gotten from: https://github.com/willmcgugan/rich/discussions/1263#discussioncomment-808898
There are a lot of improvements are added by me
é    )ÚStringIO)Ú
HTMLParser)ÚOptionalÚUnionN)Úbox)ÚAlign)ÚConsoleÚConsoleOptionsÚRenderResultÚNewLine)ÚJupyterMixin)ÚPanel)ÚStyle)ÚSyntaxÚSyntaxTheme)ÚText)ÚTable)Úinstall)ÚRule)Úguess_lexer)ÚClassNotFound)ÚRSTÚReStructuredTextÚreStructuredTextÚRestructuredTextz$Arian Mollik Wasi (aka. Wasi Master)z1.3.2c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú
MLStripperz3Utility class to strip out html for raw html sourcec                    s*   t ƒ  ¡  |  ¡  d| _d| _tƒ | _d S )NFT)ÚsuperÚ__init__ÚresetÚstrictÚconvert_charrefsr   Útext©Úself©Ú	__class__© úW/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/rich_rst/__init__.pyr   -   s
   
zMLStripper.__init__c                 C   s   | j  |¡ d S ©N)r!   Úwrite)r#   Údr&   r&   r'   Úhandle_data4   s   zMLStripper.handle_datac                 C   s
   | j  ¡ S r(   )r!   Úgetvaluer"   r&   r&   r'   Úget_data7   ó   
zMLStripper.get_data)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r+   r-   Ú__classcell__r&   r&   r$   r'   r   +   s
    r   c                 C   s   t ƒ }| | ¡ | ¡ S r(   )r   Úfeedr-   )ÚhtmlÚsr&   r&   r'   Ú
strip_tags;   s   
r7   c                     sn   ddl ‰ ddl‰ i g f‡ fdd„	} g d¢}|D ]}ˆ jjj || ¡ tˆ jjjjdƒr4|ˆ jjjjj|< qdS )a9  
    Register common Sphinx roles to gracefully handle Sphinx-specific markup.

    Sphinx roles like :func:, :class:, :meth: are very common in Python docstrings
    but are not available in standard docutils. This function registers them to
    render as inline code/literal text instead of showing errors.
    r   Nc                    sP   |}d|v r|  d¡r| d¡}|d|…  ¡ }	|	r|	}ˆ j ||¡}
|
gg fS )aÆ  
        Generic Sphinx role handler that renders as inline literal text.

        Parameters
        ----------
        name : str
            The role name
        rawtext : str
            The entire role text including role markup
        text : str
            The interpreted text content
        lineno : int
            The line number where the interpreted text begins
        inliner : Inliner
            The inliner instance that called this role function
        options : dict
            Directive options for customization
        content : list
            The directive content for customization

        Returns
        -------
        tuple
            A tuple of (nodes, messages)
        ú<ú>N)ÚendswithÚrfindÚstripÚnodesÚliteral)ÚnameÚrawtextr!   ÚlinenoÚinlinerÚoptionsÚcontentÚdisplay_textÚbracket_posÚpotential_displayÚnode©Údocutilsr&   r'   Úsphinx_roleL   s   

z+_register_sphinx_roles.<locals>.sphinx_role)ÚfuncÚfunctionÚmethÚmethodÚclassÚmodÚmoduleÚattrÚ	attributeÚobjÚobjectÚdataÚconstÚconstantÚexcÚ	exceptionÚvarÚvariableÚtypezpy:funczpy:methzpy:classzpy:modzpy:attrzpy:objzpy:datazpy:constzpy:excÚroles)	Údocutils.parsers.rst.rolesÚ!docutils.parsers.rst.languages.enÚparsersÚrstr_   Úregister_canonical_roleÚhasattrÚ	languagesÚen)rK   Úsphinx_rolesÚroler&   rI   r'   Ú_register_sphinx_rolesA   s   $€ürj   c                       sÎ  e Zd ZdZ			dldejjdedee	e
f dee d	ee	 d
df‡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Z d4d5„ Z!d6d7„ Z"d8d9„ Z#d:d;„ Z$d<d=„ Z%d>d?„ Z&d@dA„ Z'dBdC„ Z(dDdE„ Z)dFdG„ Z*dHdI„ Z+dJdK„ Z,dLdM„ Z-dNdO„ Z.dPdQ„ Z/dRdS„ Z0dTdU„ Z1dVdW„ Z2dXdY„ Z3dZd[„ Z4d\d]„ Z5d^d_„ Z6d`da„ Z7dbdc„ Z8ddde„ Z9dfdg„ Z:dhdi„ Z;djdk„ Z<‡  Z=S )mÚ
RSTVisitorz(A visitor that produces rich renderablesÚmonokaiTÚpythonÚdocumentÚconsoleÚ
code_themer   Údefault_lexerÚreturnNc                    s\   t ƒ  |¡ || _|| _g | _t dd¡| _t dd¡| _g | _	g | _
|| _|| _i | _d S )NuG   1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ=+-*/Ã—Ã·u¹   Â¹Â²Â³â´âµâ¶â·â¸â¹â°áµƒáµ‡á¶œáµˆáµ‰á¶ áµÊ°â±Ê²áµË¡áµâ¿áµ’áµ–á‘«Ê³Ë¢áµ—áµ˜áµ›Ê·Ë£Ê¸á¶»á´¬á´®á¶œá´°á´±á¶ á´³á´´á´µá´¶á´·á´¸á´¹á´ºá´¼á´¾Qá´¿Ë¢áµ€áµâ±½áµ‚Ë£Ê¸á¶»â¼âºâ»*/Ã—Ã·u-   1234567890abcdefghijklmnopqrstuvwxyz=+-*/Ã—Ã·ug   â‚â‚‚â‚ƒâ‚„â‚…â‚†â‚‡â‚ˆâ‚‰â‚€abcdâ‚‘fgâ‚•áµ¢â±¼â‚–â‚—â‚˜â‚™â‚’â‚šqáµ£â‚›â‚œáµ¤áµ¥wâ‚“yzâ‚Œâ‚Šâ‚‹*/Ã—Ã·)r   r   ro   rp   ÚrenderablesÚstrÚ	maketransÚ
supercriptÚ	subscriptÚerrorsÚfooterr   rq   Úrefname_to_renderable)r#   rn   ro   rp   r   rq   r$   r&   r'   r   ‹   s    þÿ
zRSTVisitor.__init__c                 C   s°   t | d¡ƒdkr|d d n
| d¡r|d nd }|d u rJ| jrJzt| ¡ ƒ}W n ty5   | j}Y nw |jr>|jd n| j}|dkrH| jS |S |d u rV| jsV| j}|S |S )NÚclassesé   é   Úformatr   r!   )ÚlenÚgetr   Úastextr   rq   Úaliases)r#   rH   Úlexerr&   r&   r'   Ú_find_lexer¤   s    2ÿ
ÿzRSTVisitor._find_lexerc                 C   sÒ   |j  d¡}| jjddd}|r| |¡}t| ¡  dd¡|dd}| jr@t	| jd	 tƒr@d|_
t| jd	 ƒ}| jd	  |¡ nd
}| j |¡ t| jd	 ƒ}|sd|j  d¡}|rd| jd	 ||f| j|< tj ¡ ‚)NÚrefurizrestructuredtext.referencezblue underline on default©ÚdefaultÚ
ú Ú ©ÚstyleÚendéÿÿÿÿr   Úrefname)Ú
attributesr€   ro   Ú	get_styleÚupdate_linkr   r   Úreplacers   Ú
isinstancer   r   Úappend_textÚappendrz   rJ   r=   ÚSkipChildren)r#   rH   r…   rŒ   Ú
renderableÚstartr   r   r&   r&   r'   Úvisit_reference·   s"   

zRSTVisitor.visit_referencec              	   C   st   |  d¡}|r5|d D ])}z
| j| \}}}W n	 ty    Y qw | | j|¡}| |¡}| |||¡ qtj 	¡ ‚)Nr…   Únames)
r€   rz   ÚKeyErrorÚget_style_at_offsetro   r’   ÚstylizerJ   r=   r—   )r#   rH   Úurir?   r˜   r™   r   rŒ   r&   r&   r'   Úvisit_targetÍ   s   
ÿ

zRSTVisitor.visit_targetc                 C   s2   t |dƒrt|jtjjƒr|  |j¡ d S d S d S )NÚparent)re   r”   r¡   rJ   r=   Úsystem_messageÚvisit_system_message©r#   rH   r&   r&   r'   Úvisit_paragraphÚ   s   ÿzRSTVisitor.visit_paragraphc                 C   sJ   | j rt| j d tƒr!t| j d jƒdkr#| j d  d¡ d S d S d S d S )NrŽ   r   ú

)rs   r”   r   r   r   r–   r¤   r&   r&   r'   Údepart_paragraphÞ   s
   þzRSTVisitor.depart_paragraphc                 C   s<   | j jddd}| j tt| ¡ dƒtj|d¡ t	j
 ¡ ‚)Nzrestructuredtext.titleÚboldr†   Úcenter)r   rŒ   )ro   r‘   rs   r–   r   r   r   r   ÚDOUBLErJ   r=   r—   ©r#   rH   rŒ   r&   r&   r'   Úvisit_titleã   s   "
zRSTVisitor.visit_titlec                 C   sv   | j jddd}| jr(t| jd tƒr(| jd  t| ¡  dd¡|dd¡ d S | j t| ¡  dd¡d|d	¡ d S )
Nzrestructuredtext.textz default on default not underliner†   rŽ   rˆ   r‰   r‹   rŠ   ©r   rŒ   )	ro   r‘   rs   r”   r   r•   r   r“   r–   r«   r&   r&   r'   Ú
visit_Textè   s
   &&zRSTVisitor.visit_Textc                 C   ó
   t j ¡ ‚r(   ©rJ   r=   r—   r¤   r&   r&   r'   Úvisit_commentï   r.   zRSTVisitor.visit_commentc                 C   ó>   | j jddd}| j t| ¡  dd¡d||d¡ tj 	¡ ‚)Nzrestructuredtext.admonitionú
bold whiter†   rˆ   r‰   zAdmonition: ©ÚtitlerŒ   Úborder_style©
ro   r‘   rs   r–   r   r   r“   rJ   r=   r—   r«   r&   r&   r'   Úvisit_admonitionò   ó   $
zRSTVisitor.visit_admonitionc                 C   r²   )Nzrestructuredtext.attentionzbold black on yellowr†   rˆ   r‰   zAttention: r´   r·   r«   r&   r&   r'   Úvisit_attention÷   r¹   zRSTVisitor.visit_attentionc                 C   r²   )Nzrestructuredtext.cautionÚredr†   rˆ   r‰   z	Caution: r´   r·   r«   r&   r&   r'   Úvisit_cautionü   r¹   zRSTVisitor.visit_cautionc                 C   r²   )Nzrestructuredtext.dangerzbold white on redr†   rˆ   r‰   zDANGER: r´   r·   r«   r&   r&   r'   Úvisit_danger  r¹   zRSTVisitor.visit_dangerc                 C   r²   )Nzrestructuredtext.errorúbold redr†   rˆ   r‰   zERROR: r´   r·   r«   r&   r&   r'   Úvisit_error  r¹   zRSTVisitor.visit_errorc                 C   r²   )Nzrestructuredtext.hintÚyellowr†   rˆ   r‰   zHint: r´   r·   r«   r&   r&   r'   Ú
visit_hint  r¹   zRSTVisitor.visit_hintc                 C   r²   )Nzrestructuredtext.importantz	bold bluer†   rˆ   r‰   zIMPORTANT: r´   r·   r«   r&   r&   r'   Úvisit_important  r¹   zRSTVisitor.visit_importantc                 C   r²   )Nzrestructuredtext.noter³   r†   rˆ   r‰   zNote: r´   r·   r«   r&   r&   r'   Ú
visit_note  r¹   zRSTVisitor.visit_notec                 C   r²   )Nzrestructuredtext.tipz
bold greenr†   rˆ   r‰   zTip: r´   r·   r«   r&   r&   r'   Ú	visit_tip  r¹   zRSTVisitor.visit_tipc                 C   r²   )Nzrestructuredtext.warningúbold yellowr†   rˆ   r‰   z	Warning: r´   r·   r«   r&   r&   r'   Úvisit_warning  r¹   zRSTVisitor.visit_warningc                 C   ó‚   | j jddd}| jr+t| jd tƒr+| jd  t| ¡  | j¡|dd¡ t	j
 ¡ ‚| j t| ¡  | j¡d|d¡ t	j
 ¡ ‚)	Nzrestructuredtext.subscriptÚnoner†   rŽ   r‰   r‹   rŠ   r­   )ro   r‘   rs   r”   r   r•   r   Ú	translaterw   rJ   r=   r—   r–   r«   r&   r&   r'   Úvisit_subscript$  ó   &
"
zRSTVisitor.visit_subscriptc                 C   rÇ   )	Nzrestructuredtext.superscriptrÈ   r†   rŽ   r‰   r‹   rŠ   r­   )ro   r‘   rs   r”   r   r•   r   rÉ   rv   rJ   r=   r—   r–   r«   r&   r&   r'   Úvisit_superscript,  rË   zRSTVisitor.visit_superscriptc                 C   ó‚   | j jddd}| jr+t| jd tƒr+| jd  t| ¡  dd¡|dd¡ tj	 
¡ ‚| j t| ¡  dd¡|dd¡ tj	 
¡ ‚)	Nzrestructuredtext.emphasisÚitalicr†   rŽ   rˆ   r‰   r‹   rŠ   ©ro   r‘   rs   r”   r   r•   r   r“   rJ   r=   r—   r–   r«   r&   r&   r'   Úvisit_emphasis4  rË   zRSTVisitor.visit_emphasisc                 C   rÍ   )	Nzrestructuredtext.strongr¨   r†   rŽ   rˆ   r‰   r‹   rŠ   rÏ   r«   r&   r&   r'   Úvisit_strong<  rË   zRSTVisitor.visit_strongc              
   C   s”   d\}}d|j v r|j  d¡d  ¡ }d|j v r"|j  d¡d  ¡ }| j tdƒt| d|p/d¡t| d|p7d¡p=| d	¡d
dd ¡ tj	 
¡ ‚)N)NNz:target:rŽ   z:alt:u   ðŸŒ† ÚaltÚImageÚtargetrŸ   z#6088ff)ÚlinkÚcolor©rŒ   )Ú	rawsourceÚsplitr<   rs   r–   r   r€   r   rJ   r=   r—   )r#   rH   rÒ   rÔ   r&   r&   r'   Úvisit_imageD  s"   

þþÿÿ

zRSTVisitor.visit_imagec                 C   s8  | j jddd}| j jddd}|jD ]|}dd„ |jD ƒ}|rt|jD ]Q}| j tdd	d
tdd	|d ¡ | j t| ¡  dd¡|d¡ t|t	j
jƒrs|jD ]#}| j tdd	d
tdd	|d ¡ | j t| ¡  dd¡|d¡ qOq"| j tdd	|d¡ | j t| ¡  dd¡|d¡ q| j tƒ ¡ t	j
 ¡ ‚)Nz#restructuredtext.bullet_list_markerrÅ   r†   z!restructuredtext.bullet_list_textrÈ   c                 S   s   g | ]}t |tjjƒr|‘qS r&   )r”   rJ   r=   Úbullet_list)Ú.0Úir&   r&   r'   Ú
<listcomp>\  s    z0RSTVisitor.visit_bullet_list.<locals>.<listcomp>z  rŠ   ©r   u    âˆ˜ r­   rˆ   r‰   r×   ú    u    â–ª u    â€¢ )ro   r‘   Úchildrenrs   r–   r   r   r“   r”   rJ   r=   rÛ   r   r—   )r#   rH   Úmarker_styleÚ
text_styleÚ	list_itemÚnested_listr&   r&   r'   Úvisit_bullet_listV  s"   

" 
""€"
zRSTVisitor.visit_bullet_listc                 C   sŠ   | j jddd}| j jddd}t|jdƒD ]"\}}| j td|› d|d¡ | j t| ¡  d	d¡|d
¡ q| j t	ƒ ¡ t
j ¡ ‚)Nz'restructuredtext.enumerated_list_markerrÅ   r†   z restructuredtext.enumerated_textrÈ   r}   r‰   r­   rˆ   r×   )ro   r‘   Ú	enumeraterá   rs   r–   r   r   r“   r   rJ   r=   r—   )r#   rH   râ   rã   rÝ   rä   r&   r&   r'   Úvisit_enumerated_listj  s   "
z RSTVisitor.visit_enumerated_listc                 C   rÍ   )	Nz!restructuredtext.inline_codeblockzgrey78 on grey7r†   rŽ   rˆ   r‰   r‹   rŠ   rÏ   r«   r&   r&   r'   Úvisit_literalt  rË   zRSTVisitor.visit_literalc                 C   s†   | j jddd}| jr$t| jd tƒr$| jd  ¡  | jd  tdƒ¡ |  |¡}| j t	t
| ¡ || jd|tj|d¡ tj ¡ ‚)Nú%restructuredtext.literal_block_borderÚgrey58r†   rŽ   rˆ   ©Útheme©r¶   r   rµ   )ro   r‘   rs   r”   r   Úrstripr•   r„   r–   r   r   r   rp   r   ÚSQUARErJ   r=   r—   )r#   rH   rŒ   rƒ   r&   r&   r'   Úvisit_literal_block|  s   
 ÿ
zRSTVisitor.visit_literal_blockc                 C   s„   | j  t| j | ¡ ¡d|j dd¡› d|j dd¡› d|j dd¡› d|j d	d¡› d
	dddddœ|j d¡ d¡ tj	 
¡ ‚)NzSystem Message: r^   ú?ú/Úlevelz (Úsourcez, line Úlinez);rÈ   z	bold cyanrÅ   r¾   )NÚINFOÚWARNINGÚERROR©rµ   r¶   )rx   r–   r   ro   Ú
render_strr   r   r€   rJ   r=   r—   r¤   r&   r&   r'   r£   ‡  s   D
ÿýÿ
	zRSTVisitor.visit_system_messagec                 C   s  | j jddd}| j jddd}d }t| jd tƒr>| jd }|jd jdkr4|jd	 jd
kr4|}d}ntdd
dd}d}nd}|du rjtdd
dd}| t|j	d  
¡ |dt|j	d	  
¡ |d¡ | j |¡ n| t|j	d  
¡ |dt|j	d	  
¡ |d¡ tj ¡ ‚)Nzrestructuredtext.field_namer¨   r†   zrestructuredtext.field_valuerÈ   rŽ   r   z
Field Namer}   zField ValueT)Ú
show_linesFr×   )ro   r‘   r”   rs   r   ÚcolumnsÚheaderÚadd_rowr   rá   r   r–   rJ   r=   r—   )r#   rH   Úfield_name_styleÚfield_value_styleÚprevious_tableÚpossible_tableÚtabler&   r&   r'   Úvisit_field“  s"   
 00
zRSTVisitor.visit_fieldc           
      C   sÒ  | j jddd}| j jddd}| j jddd}|jD ]È}z|j\}}}W n† ty«   |jd |jd }}t|jƒd	kr||jd	d … D ]5}	t|	tjjƒrT|  	|	¡ qEt|	tjj
ƒra|  |	¡ qEt|	tjjƒrn|  |	¡ qEt|	tjjƒrz|  |	¡ qEn-| j t d
|› d| ¡ › d|› d¡tddd t| ¡  dd¡|d tddd ¡ Y qw | j tdƒt| ¡ |dd tddd t| ¡ |d tddd t| ¡  dd¡|d tddd ¡ qtj ¡ ‚)Nzrestructuredtext.term_stylerÈ   r†   z!restructuredtext.classifier_styleÚcyanz"restructuredtext.definitions_styler   r}   r|   ú[ú]z[/ú
    rŠ   rß   rˆ   r‰   r×   z
      rà   r‹   z : )ro   r‘   rá   Ú
ValueErrorr   r”   rJ   r=   rÛ   ræ   Úliteral_blockrñ   r>   ré   Úblock_quoteÚvisit_block_quoters   r–   r   Úfrom_markupr   r“   r—   )
r#   rH   Ú
term_styleÚclassifier_styleÚdefinitions_styleÚchildÚtermÚ
classifierÚdefinitionsrá   r&   r&   r'   Úvisit_definition_list©  s^   

€ø 
ÿþ
ýÿ€òÿ
þý
üû
úÿ
	z RSTVisitor.visit_definition_listc              
   C   s.  | j jddd}| j jddd}| j jddd}| j jddd}|jD ]n}|j\}}tdd}	|jD ]B}
z|
j\}}W n tyL   |
jd	 d }}Y nw |	t| ¡ |d
|r_t| ¡ |d
ntƒ  t|jƒdkrpt|j|d
nd 7 }	q2|r‡|	tdƒ7 }	|	t| ¡ |d
7 }	| j 	|	tdƒ ¡ q#t
j ¡ ‚)Nzrestructuredtext.option_stringrÈ   r†   z restructuredtext.option_argumentz,restructuredtext.option_child_text_separatorz#restructuredtext.option_descriptionrŠ   rß   r   r×   r}   r	  rˆ   )ro   r‘   rá   r   r
  r   r   Úchild_text_separatorrs   r–   rJ   r=   r—   )r#   rH   Úoption_string_styleÚoption_argument_styleÚ!option_child_text_separator_styleÚoption_description_styleÚoption_list_itemÚoption_groupÚdescriptionÚoption_textÚoptionÚoption_stringÚoption_argumentr&   r&   r'   Úvisit_option_listÐ  s:   ÿ



ÿÿÿûÿ	
zRSTVisitor.visit_option_listc                 C   sB   | j jddd}| j tt| ¡ d| jd|tj	d¡ t
j ¡ ‚)Nrê   rë   r†   Úpyconrì   )r¶   r   )ro   r‘   rs   r–   r   r   r   rp   r   rð   rJ   r=   r—   r«   r&   r&   r'   Úvisit_doctest_blockï  s   ýÿ
zRSTVisitor.visit_doctest_blockc                 C   sÖ   | j jddd}| j jddd}| j jddd}z|j\}}W n& tyE   |jd }| j td	ƒt| ¡  d
d¡|d tdƒ ¡ Y n!w | j td|dt| ¡ |d td
ƒ td| ¡  |d ¡ t	j
 ¡ ‚)Nz restructuredtext.blockquote_textÚwhiter†   z.restructuredtext.blockquote_attribution_markerÚbright_magentaz,restructuredtext.blockquote_attribution_textÚgrey89r   rà   rˆ   r‰   r×   r¦   u   â–Œ z  - )ro   r‘   rá   r
  rs   r–   r   r   r“   rJ   r=   r—   )r#   rH   rã   râ   Úauthor_styleÚ	paragraphÚattributionr&   r&   r'   r  ú  s6   ÿ
ÿþÿþ
ÿþýÿ
zRSTVisitor.visit_block_quotec                 C   s*   |j D ]}| j t| ¡ ƒ¡ qtj ¡ ‚r(   )rá   rs   r–   r   r   rJ   r=   r—   )r#   rH   rö   r&   r&   r'   Úvisit_line_block  s   

zRSTVisitor.visit_line_blockc                 C   sf   t |jƒdkr|j\}}}n|jd d|jd }}}| j t| ¡ | ¡ | ¡ dd¡ tj ¡ ‚)Nr|   r   rŠ   r}   F)rµ   ÚsubtitleÚexpand)	r   rá   rs   r–   r   r   rJ   r=   r—   )r#   rH   rµ   r-  r*  r&   r&   r'   Úvisit_sidebar  s   ÿ
zRSTVisitor.visit_sidebarc                 C   s&   | j jddd}| j t|d¡ d S )Nzrestructuredtext.hrrÀ   r†   r×   )ro   r‘   rs   r–   r   r«   r&   r&   r'   Úvisit_transition#  s   zRSTVisitor.visit_transitionc                 C   s   |   |¡ d S r(   )r¬   r¤   r&   r&   r'   Úvisit_rubric'  s   zRSTVisitor.visit_rubricc                 C   sZ   | j rt| j d tƒr| j d  t| ¡ dd¡ tj ¡ ‚| j  t| ¡ ƒ¡ tj ¡ ‚)NrŽ   r‰   rß   )rs   r”   r   r–   r   rJ   r=   r—   r¤   r&   r&   r'   Úvisit_math_block*  s
   

zRSTVisitor.visit_math_blockc                 C   s4   | j jddd}| j t| ¡ d|d¡ tj ¡ ‚)Nz restructuredtext.citation_borderÚgrey74r†   Úcitationrú   )	ro   r‘   rs   r–   r   r   rJ   r=   r—   )r#   rH   r¶   r&   r&   r'   Úvisit_citation1  s   
zRSTVisitor.visit_citationc                 C   s|   | j jddd}| jr(t| jd tƒr(| jd j| ¡  dd¡|d tj	 
¡ ‚| j t| ¡  dd¡|dd	¡ tj	 
¡ ‚)
Nz#restructuredtext.citation_referencer3  r†   rŽ   rˆ   r‰   r×   rŠ   r‹   )ro   r‘   rs   r”   r   r–   r   r“   rJ   r=   r—   r«   r&   r&   r'   Úvisit_citation_reference6  s    
"
z#RSTVisitor.visit_citation_referencec              	   C   s@   | j jddd}| j dtt| ¡ dƒdtj|d¡ t	j
 ¡ ‚)Nzrestructuredtext.captionr¨   r†   r   r©   Úcaption)rµ   r   rŒ   )ro   r‘   rs   Úinsertr   r   r   r   rª   rJ   r=   r—   r«   r&   r&   r'   Úvisit_header>  s   &
zRSTVisitor.visit_headerc                 C   ó    | j  t| ¡ dƒ¡ tj ¡ ‚©Nr©   ©ry   r–   r   r   rJ   r=   r—   r¤   r&   r&   r'   Úvisit_footerC  ó   
zRSTVisitor.visit_footerc                 C   r:  r;  r<  r¤   r&   r&   r'   Úvisit_footnoteG  r>  zRSTVisitor.visit_footnotec                 C   r:  r;  r<  r¤   r&   r&   r'   Úvisit_generatedK  r>  zRSTVisitor.visit_generatedc                 C   r¯   r(   r°   r¤   r&   r&   r'   Úvisit_pendingsO  r.   zRSTVisitor.visit_pendingsc                 C   s*   | j  tt| ¡ d| jdddd¡ d S )Nrc   )rƒ   rí   z#System Message: Problematic Elementr¾   rú   )rx   r–   r   r   r   rp   r¤   r&   r&   r'   Úvisit_problematicR  s   ýÿzRSTVisitor.visit_problematicc                 C   s   | j jddd}|  |¡}| ¡ }d|dkrdn| }|dkr0t|ƒ}| jr-t|ƒjd n| j}| j 	t
t||| jd|tj|d	¡ tj ¡ ‚)
Nrê   rë   r†   zraw r5   zstripped raw htmlr   rì   rî   )ro   r‘   r„   r   r7   r   r‚   rq   rs   r–   r   r   rp   r   rð   rJ   r=   r—   )r#   rH   rŒ   rƒ   r!   rµ   r&   r&   r'   Ú	visit_raw[  s   
ÿ
zRSTVisitor.visit_raw)rl   Trm   )>r/   r0   r1   r2   rJ   r=   rn   r   r   rt   r   r   Úboolr   r„   rš   r    r¥   r§   r¬   r®   r±   r¸   rº   r¼   r½   r¿   rÁ   rÂ   rÃ   rÄ   rÆ   rÊ   rÌ   rÐ   rÑ   rÚ   ræ   rè   ré   rñ   r£   r  r  r#  r%  r  r,  r/  r0  r1  r2  r5  r6  r9  r=  r?  r@  rA  rB  rC  r3   r&   r&   r$   r'   rk   ˆ   s‚    úþý
üûúù
'	rk   c                   @   s~   e Zd ZdZ						ddedeeeef  d	ee d
ee dee dee dee ddfdd„Z	de
dedefdd„ZdS )r   aõ  A reStructuredText renderable for rich.

    Parameters
    ----------
    markup : str
        A string containing reStructuredText markup.
    code_theme : Optional[Union[str, SyntaxTheme]]
        Pygments theme for code blocks. Defaults to "monokai".
    show_errors : Optional[bool]
        Whether to show system_messages aka errors and warnings.
    guess_lexer : Optional[bool]
        Whether to guess lexers for code blocks without specified language.
    default_lexer : Optional[str]
        Which lexer to use if no lexer is guessed or found. Defaults to "python"
    sphinx_compat : Optional[bool]
        Enable compatibility with Sphinx roles (func, meth, class, etc.) commonly used in
        Python docstrings. When enabled, these roles render as inline code instead of errors.
        Defaults to True for better compatibility with Python documentation.
    filename : Optional[str]
        A file name to use for error messages, useful for debugging purposes. Defaults to "<rst-document>"
    rl   TFrm   ú<rst-document>Úmarkuprp   Úshow_errorsr   rq   Úsphinx_compatÚfilenamerr   Nc                 C   s.   || _ || _|| _|| _|| _|| _|| _d S r(   )rF  rp   Ú
log_errorsr   rq   rH  rI  )r#   rF  rp   rG  r   rq   rH  rI  r&   r&   r'   r   ‚  s   

zRestructuredText.__init__ro   rC   c              	   c   sº   | j rtƒ  ttjdƒrtj tjjj¡}ntjj	tjjjfd 
¡ }d|_tj | j¡}tj | j|¡}tjj ¡ }| | ¡ |¡ t||| j| j| jd}| |¡ |jr‹t|jd tƒry|jd  ¡  d|jd _|jd rsn|j ¡  nt|jd tƒr‡|j ¡  nn|jsX|jD ]}|  ||¡E d H  qŽ| j!r¯|j"r¯|j"D ]}	|  |	|¡E d H  q£|j#ddd	}
|j#d
dd	}d}|j$D ]}|}qÂ|rÛ|  t%|dt&j'||
d¡E d H  d S d S )NÚget_default_settings)Ú
componentséE   )ro   rp   r   rq   rŽ   rˆ   zrestructuredtext.footerrÈ   r†   zrestructuredtext.footer_borderr3  rŠ   ÚFooter)rµ   r   r¶   rŒ   )(rH  rj   re   rJ   ÚfrontendrK  rb   rc   ÚParserÚOptionParserÚget_default_valuesÚreport_levelÚioÚStringInputrF  ÚutilsÚnew_documentrI  ÚparseÚreadrk   rp   r   rq   Ú	walkaboutrs   r”   r   rï   r   Úpopr   ÚrenderrJ  rx   r‘   ry   r   r   rð   )r#   ro   rC   Úsettingsrõ   rn   Ú
rst_parserÚvisitorr˜   ÚerrorrŒ   r¶   Úfooter_textÚelementr&   r&   r'   Ú__rich_console__”  sZ   €û

õ


ÿÿz!RestructuredText.__rich_console__)rl   TFrm   TrE  )r/   r0   r1   r2   rt   r   r   r   rD  r   r   r	   r
   rc  r&   r&   r&   r'   r   k  s4    øþýüûúùø	
÷r   )9r2   rT  r   Úhtml.parserr   Útypingr   r   Údocutils.iorJ   Údocutils.nodesÚdocutils.parsers.rstÚdocutils.utilsÚrichr   Ú
rich.alignr   Úrich.consoler   r	   r
   r   Úrich.jupyterr   Ú
rich.panelr   Ú
rich.styler   Úrich.syntaxr   r   Ú	rich.textr   Ú
rich.tabler   Úrich.tracebackr   Ú	rich.ruler   Úpygments.lexersr   Úpygments.utilr   Ú__all__Ú
__author__Ú__version__r   r7   rj   r=   ÚSparseNodeVisitorrk   r   r   ÚreSTr   r   r&   r&   r&   r'   Ú<module>   sF   G   fb