wiAfddlmZddlZddlmZddlmZmZmZddl m Z ddl m Z ddl mZdd lmZdd lmZdd lmZdd lmZmZmZmZdd lmZddlmZddlmZddl m!Z!ddl"m#Z#m$Z$ddl%m&Z&ddl'm(Z(m)Z)GddZ*Gdde*Z+Gdde*Z,Gdde,Z-eGddZ.Gdde,Z/Gd d!e,Z0Gd"d#e,Z1Gd$d%e*Z2Gd&d'e*Z3Gd(d)e*Z4Gd*d+e*Z5Gd,d-e*Z6Gd.d/e*Z7Gd0d1e*Z8Gd2d3e,Z9Gd4d5e,Z:Gd6d7e,Z;Gd8d9Z<Gd:d;eZ=e>dZAeABd?d@dABeABdCdDdEdFddGHeABdIdJdKdLdMNeABdOdPdQddQNeABdRdSdTdFdUVeABdWdXeCdYddZ[eABd\d]d^dFd_VeABd`dadbdFdcVeADZEdddlFmZeEjGdekrejHIZJn>eKeEjGdfg5ZLeLIZJdddn #1swxYwYe=eJeEjMrdhndieEjNeEjOeEjPjZQeEjRrhddlSZSddlTZTeSjUZVeeVeEjWeEjXkZeYeQeTjZeV[dSeeEjWeEjXdlmZeYeQdSdS)n) annotationsN) dataclass)ClassVarIterableget_args) MarkdownIt)Token)Table)box) loop_first)Stack)ConsoleConsoleOptions JustifyMethod RenderResult) Renderables) JupyterMixin)Rule)Segment)Style StyleStack)Syntax)TextTextTypec^eZdZUdZded<edd Zdd ZddZddZ ddZ d dZ dS)!MarkdownElementTzClassVar[bool]new_linemarkdownMarkdowntokenr returnc|S)zFactory to create markdown element, Args: markdown (Markdown): The parent Markdown object. token (Token): A node from markdown-it. Returns: MarkdownElement: A new markdown element clsrr!s ]/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/rich/markdown.pycreatezMarkdownElement.createssuu contextMarkdownContextNonecdS)zuCalled when the node is entered. Args: context (MarkdownContext): The markdown context. Nr$selfr*s r'on_enterzMarkdownElement.on_enter)r)textrcdS)zpCalled when text is parsed. Args: context (MarkdownContext): The markdown context. Nr$r/r*r2s r'on_textzMarkdownElement.on_text0r1r)cdS)zwCalled when the parser leaves the element. Args: context (MarkdownContext): [description] Nr$r.s r'on_leavezMarkdownElement.on_leave7r1r)childboolcdS)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*r8s r'on_child_closezMarkdownElement.on_child_close>s tr)consoleroptionsrrcdS)Nr$r$r/r=r>s r'__rich_console__z MarkdownElement.__rich_console__Ls rr)Nrr r!r r"rr*r+r"r,r*r+r2rr"r,r*r+r8rr"r9r=rr>rr"r) __name__ __module__ __qualname__r__annotations__ classmethodr(r0r5r7r<rAr$r)r'rrs#H####   [                 r)rceZdZdZdS)UnknownElementzAn unknown element. Hopefully there will be no unknown elements, and we will have a MarkdownElement for everything in the document. N)rGrHrI__doc__r$r)r'rMrMRsr)rMc.eZdZdZdZd dZdd Zd d Zd S) TextElementz)Base class for elements that render text.noner*r+r"r,cn||j|_td|_dSNleftjustify) enter_style style_namestylerr2r.s r'r0zTextElement.on_enter`s/((99 ((( r)r2rct|j|t|tr|jnddSN)r2append isinstancestr current_styler4s r'r5zTextElement.on_textds8  48M8MWw44SWXXXXXr)c.|dSr[) leave_styler.s r'r7zTextElement.on_leavegsr)NrCrD)rGrHrIrNrXr0r5r7r$r)r'rPrP[s_33J))))YYYYr)rPcJeZdZUdZdZded<edd Zdd ZddZ dS) Paragraphz A Paragraph.zmarkdown.paragraphrrVrr r!r r"c(||jpdSrSrUr%s r'r(zParagraph.createqss8+5v6666r)r,c||_dSr[rUr/rVs r'__init__zParagraph.__init__us  r)r=rr>rrc#>K|j|j_|jVdSr[)rVr2r@s r'rAzParagraph.__rich_console__xs#!L ir)N)rr r!r r"rcrVrr"r,rF) rGrHrIrNrXrJrKr(rgrAr$r)r'rcrckss%J777[7r)rcc,eZdZUdZded<dZded<dS) HeadingFormatrTrrVr^rYN)rGrHrIrVrJrYr$r)r'rkrks.#G####EOOOOOOr)rkcjeZdZUdZdddddddZded<edd ZddZdfd Z ddZ xZ S)Headingz A heading.centerrT)h1h2h3h4h5h6z"ClassVar[dict[str, JustifyMethod]] LEVEL_ALIGNrr r!r r"c"||jSr[)tagr%s r'r(zHeading.createss59~~r)r*r+r,c`t|_||jdSr[)rr2rWrXr.s r'r0zHeading.on_enters)FF DO,,,,,r)rxr^cj||_d||_tdS)N markdown.)rxrXsuperrg)r/rx __class__s r'rgzHeading.__init__s5+c++ r)r=rr>rrc#K|j}|j|jd}||_|VdS)NrT)r2copyrvgetrxrV)r/r=r>r2heading_justifys r'rAzHeading.__rich_console__sGy~~*..tx@@&  r))rr r!r r"rnrC)rxr^r"r,rF) rGrHrIrNrvrJrKr(r0rgrA __classcell__r}s@r'rnrns 77K[---- r)rnc>eZdZdZdZeddZdd ZddZdS) CodeBlockz&A code block with syntax highlighting.zmarkdown.code_blockrr r!r r"cp|jpd}|dd}||pd|jS)Nrl rr2)info partition code_theme)r&rr! node_info lexer_names r'r(zCodeBlock.creates@J$" ((--a0 s:')<===r)rr^themer,c"||_||_dSr[)rr)r/rrs r'rgzCodeBlock.__init__s$ r)r=rr>rrc#Kt|j}t||j|jdd}|VdS)NTr )r word_wrappadding)r^r2rstriprrr)r/r=r>codesyntaxs r'rAzCodeBlock.__rich_console__sS49~~$$&& $/tQ    r)N)rr r!r r"r)rr^rr^r"r,rF) rGrHrIrNrXrKr(rgrAr$r)r'rrse00&J>>>[> r)rc.eZdZdZdZddZdd ZddZdS) BlockQuotezA block quote.zmarkdown.block_quoter"r,c,t|_dSr[relementsr/s r'rgzBlockQuote.__init__%0]] r)r*r+r8rr9c:|j|dSNFrr\r;s r'r<zBlockQuote.on_child_close U###ur)r=rr>rrc#K||jdz }||j||j}|j}t d}t d|}|D]}|V|Ed{V|VdS)NwidthrY u▌ )update max_width render_linesrrYr) r/r=r>render_optionslinesrYrrlines r'rAzBlockQuote.__rich_console__s!g.?!.CDD$$T]N$*$UU 4==&%((  DMMMOOOOOOONNNN  r)Nr"r,rErF)rGrHrIrNrXrgr<rAr$r)r'rrs['J3333      r)rceZdZdZdZd d Zd S) HorizontalRulez%A horizontal rule to divide sections.Fr=rr>rr"rc#~K|dd}t|dVtVdS)Nz markdown.hrrQdefault-)rY characters) get_stylerr)r/r=r>rYs r'rAzHorizontalRule.__rich_console__sJ!!-!@@3//////ff r)NrF)rGrHrIrNrrAr$r)r'rrs3//Hr)rc*eZdZdZddZdd ZddZdS) TableElementz.MarkdownElement corresponding to `table_open`.r"r,c"d|_d|_dSr[)headerbodyrs r'rgzTableElement.__init__s15 -1 r)r*r+r8rr9ct|tr||_n,t|tr||_nt ddS)Nz Couldn't process markdown table.F)r]TableHeaderElementrTableBodyElementr RuntimeErrorr;s r'r<zTableElement.on_child_closesP e/ 0 0 CDKK / 0 0 CDIIABB Bur)r=rr>rrc#Kttjdddd}|jc|jjW|jjjD]E}|j}|d| |F|j *|j j D]}d|jD}|j ||VdS)NFzmarkdown.table.borderT)r pad_edgerY show_edgecollapse_paddingzmarkdown.table.headercg|] }|j Sr$)content).0elements r' z1TableElement.__rich_console__.. sHHH7wHHHr)) r r SIMPLErrowcellsrrstylize add_columnrrowsadd_row)r/r=r>tablecolumnheadingr row_contents r'rAzTableElement.__rich_console__s )!     ; "t{'B+// * * .--// 7888  )))) 9 y~ , ,HHciHHH  {+++ r)NrrErF)rGrHrIrNrgr<rAr$r)r'rrsV882222r)rc"eZdZdZd dZd d Zd S)rz@MarkdownElement corresponding to `thead_open` and `thead_close`.r"r,cd|_dSr[)rrs r'rgzTableHeaderElement.__init__s +/r)r*r+r8rr9cBt|tsJ||_dSr)r]TableRowElementrr;s r'r<z!TableHeaderElement.on_child_closes$%11111ur)NrrErGrHrIrNrgr<r$r)r'rrsBJJ0000r)rc"eZdZdZd dZd d Zd S)rz@MarkdownElement corresponding to `tbody_open` and `tbody_close`.r"r,cg|_dSr[)rrs r'rgzTableBodyElement.__init__s +- r)r*r+r8rr9cht|tsJ|j|dSr)r]rrr\r;s r'r<zTableBodyElement.on_child_close"s3%11111 ur)NrrErr$r)r'rrsBJJ....r)rc"eZdZdZd dZd d Zd S)rz:MarkdownElement corresponding to `tr_open` and `tr_close`.r"r,cg|_dSr[)rrs r'rgzTableRowElement.__init__+s -/ r)r*r+r8rr9cht|tsJ|j|dSr)r]TableDataElementrr\r;s r'r<zTableRowElement.on_child_close.s4%!122222 %   ur)NrrErr$r)r'rr(sBDD0000r)rc:eZdZdZeddZdd ZddZdS)rz[MarkdownElement corresponding to `td_open` and `td_close` and `th_open` and `th_close`.rr r!r r"rct|jdpd}d|vrd}nd|vrd}n d|vrd}nd }|ttvsJ|| S) NrYrlztext-align:rightrightztext-align:centerroztext-align:leftrTrrU)r^attrsrrr)r&rr!rYrVs r'r(zTableDataElement.create8sEKOOG,,--3  & &GG E ) )GG % ' 'GGG(=111111s7####r)rVrr,c@td||_||_dS)NrlrU)rrrVrfs r'rgzTableDataElement.__init__Is!!"g666  r)r*r+r2rct|trt|n|}||j|j|dSr[)r]r^rrr_r append_textr4s r'r5zTableDataElement.on_textMsQ'c22#>??@@@r) list_typer^ list_start int | Noner,c0g|_||_||_dSr[)itemsrr)r/rrs r'rgzListElement.__init__Zs%' "$r)r*r+r8rr9cht|tsJ|j|dSr)r]ListItemrr\r;s r'r<zListElement.on_child_close_s3%***** %   ur)r=rr>rrc#4K|jdkr(|jD]}|||Ed{VdS|jdn|j}|t |jz}t |jD]&\}}|||||z|Ed{V'dS)Nbullet_list_openr )rr render_bulletrlen enumerate render_number)r/r=r>itemnumber last_numberindexs r'rAzListElement.__rich_console__ds >/ / /  @ @--gw?????????? @ @/1QQtF 3tz??2K(44   t--Wfunk  r)N)rr r!r r"r)rr^rrr"r,rErF) rGrHrIrNrKr(rgr<rAr$r)r'rrSsxAAA[A%%%%       r)rc6eZdZdZdZddZdd ZddZddZdS)rzAn item in a list.z markdown.itemr"r,c,t|_dSr[rrs r'rgzListItem.__init__xrr)r*r+r8rr9c:|j|dSrrr;s r'r<zListItem.on_child_close{rr)r=rr>rrc#hK||jdz }||j||j}|dd}t d|}t d|}t d }t|D]\} } | r|n|V| Ed{V|VdS) Nrrzmarkdown.item.bulletrQru • z r)rrrrrYrrr ) r/r=r>rr bullet_stylebulletrrfirstrs r'rzListItem.render_bullets g.?!.CDD$$T]N$*$UU(()?(PP ,//'<004==%e,,  KE4!.&&w . . .OOOOOOONNNN  r)rrrc#Ktt|dz}||j|z }||j||j}|dd}td} td|z|} t| |d z dz|} t|D]\} } | r| n| V| Ed{V| VdS) Nrrzmarkdown.item.numberrQrrrr ) rr^rrrrrYrrrjustr )r/r=r>rr number_widthrr number_stylerrnumeralrrs r'rzListItem.render_numbers3{++,,q0  g.?,.NOO$$T]N$*$UU(()?(PP 4==# ,l;;V+++L1,<==C\RR%e,,  KE4"/'' / / /OOOOOOONNNN  r)NrrErF) r=rr>rrrrrr"r) rGrHrIrNrXrgr<rrr$r)r'rrsso J3333    r)rc.eZdZed dZdd Zd S)Linkrr r!r r"rct|jdd}||jt|S)Nhref#)rrrr^)r&rr!urls r'r(z Link.creates1koofc**s5=#c((+++r)r2r^r c<t||_||_dSr[)rr2r )r/r2r s r'rgz Link.__init__sJJ  r)NrB)r2r^r r^)rGrHrIrKr(rgr$r)r'r r sF,,,[,r)r cTeZdZdZdZedd Zdfd Zdfd ZddZ xZ S) ImageItemz#Renders a placeholder for an image.Frr r!r r"rcp|t|jdd|jS)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^rr hyperlinksr%s r'r(zImageItem.creates1s3u{ub1122H4GHHHr) destinationr^rr9r,cr||_||_d|_tdSr[)rrlinkr|rg)r/rrr}s r'rgzImageItem.__init__s5&$ $  r)r*r+c|jj|_td|_t |dSrS)r_rrr2r|r0)r/r*r}s r'r0zImageItem.on_enters@). (((  !!!!!r)r=rr>rrc#FKt|jp|jpd}|jp@t |jdddd}|jr||t j d|dd}|VdS) Nr/r u🌆 rrl)end) rrrr2rstriprsplitrrassemble)r/r=r> link_styletitler2s r'rAzImageItem.__rich_console__s ET-= EFFF  QT$"2"8"8"="="D"DS!"L"LR"PQQ ? & MM* % % %}WeSb999 r)rB)rr^rr9r"r,rCrF) rGrHrIrNrrKr(rgr0rArrs@r'rrs--H I I I[ I """""" r)rcPeZdZdZ dddZeddZddZddZddZ dS)r+z!Manages the console render state.Nmonokair=rr>rrYrinline_code_lexer str | Noneinline_code_themer^r"r,c||_||_t||_t |_d|_|td|||_dSdS)Nrl)r)r=r>r style_stackrstack_syntaxr)r/r=r>rYr&r(s r'rgzMarkdownContext.__init__s^  '1%'8'8-2WW &*  (!"&7?PQQQDLLL ) (r)c|jjS)z>Current style which is the product of all styles on the stack.)r*currentrs r'r_zMarkdownContext.current_styles''r)r2 node_typec8|dvru|jn|j|}||jj|t j||jj dS|jj||dS)z#Called when the parser visits text.>fence code_inlineNr) r, highlightrr+topr5rr!r*r.)r/r2r/highlight_texts r'r5zMarkdownContext.on_texts 0 0 0T\5M!\33D99N  ! ! # # # JN " "dmN$:J:RSSS      JN " "4 . . . . .r)rX str | Stylec||j|d}|j||jS)zEnter a style context.rQr)r=rr*pushr_)r/rXrYs r'rWzMarkdownContext.enter_styles< &&z6&BB e$$$!!r)c8|j}|S)zLeave a style context.)r*pop)r/rYs r'razMarkdownContext.leave_styles $$&& r))Nr%) r=rr>rrYrr&r'r(r^r"r,)r"r)r2r^r/r^r"r,)rXr6r"r) rGrHrIrNrgpropertyr_r5rWrar$r)r'r+r+s++)-!* RRRRR"(((X( / / / /"""" r)r+ceZdZUdZidedededededede d e d e d e d e d e dedededeZded<hdZ d1d2d'Zd3d*Zd4d0ZdS)5r aA Markdown renderable. Args: markup (str): A string containing markdown. code_theme (str, optional): Pygments theme for code blocks. Defaults to "monokai". See https://pygments.org/styles/ for code themes. justify (JustifyMethod, optional): Justify value for paragraphs. Defaults to None. style (Union[str, Style], optional): Optional style to apply to markdown. hyperlinks (bool, optional): Enable hyperlinks. Defaults to ``True``. inline_code_lexer: (str, optional): Lexer to use if inline code highlighting is enabled. Defaults to None. inline_code_theme: (Optional[str], optional): Pygments theme for inline code highlighting, or None for no highlighting. Defaults to None. paragraph_open heading_openr1 code_blockblockquote_openhrrordered_list_openlist_item_openimage table_open tbody_open thead_opentr_opentd_openth_openz*ClassVar[dict[str, type[MarkdownElement]]]r>semrstrongr%NrQTmarkupr^rrVJustifyMethod | NonerYr6rr9r&r'r(r"r,ctdd}||_|||_||_||_||_||_||_ |p||_ dS)N strikethroughr) renablerNparseparsedrrVrYrr&r() r/rNrrVrYrr&r(parsers r'rgzMarkdown.__init__$sz$$_55<rrc#h K||jd}|d}t||||j|j}|j}|j}d}tj }| |D]} | j } | j } | j dk} | j dk} | j d k}| d kr|| j| T| d kr|d | q| d kr|d| | dkrt!| jdd}|jrA|dd}|t)|z }|||jt0|| 9| dkr6|jr|]|j}t9|t0sJ|dd}||||jj| ||d| |dd}||||j| ||d| v| |vr| dkr| dkr| r|d| | r||d| | jr|| j| | |j | j ptB}||| }| s|r/|j||"|| rr|j}|j p&|jo|jj#$||}|r'|r|V|%||j&Ed{Vn|r|j| j}|||||j p&|jo|jj#$||}|r-|r | dkr|V|%||j&Ed{V| s|r|'||j(}dS)zRender markdown to the console.rQrN)height)r&r(Fr rrr2 hardbreakr softbreakr link_openr rlzmarkdown.link_urlr link_closez markdown.linkz ()r1r?r{inline))rrYrr+r&r(rTinlinesrrr[rrxnestingr5rr^rrrrrWr+r8r r(rar:r]r2plainr rrMr0r4r<renderr>r7r)r/r=r>rYr*rVinline_style_tagsr_new_line_segmentr!r/rxenteringexiting self_closingr r"rlink_url_style element_class should_renderr2s r'rAzMarkdown.__rich_console__Bs!!$*f!==...--!   "4"4     L#LNN))&11c 0c 0E I)C})Hmr)G =A-LF"" y9999k))i0000k))Y////k))5;??626677?A!(!2!23FPV!2!W!WJ%T"2"2"22J'' 3333M&&t{{4'?'?@@@@l**?4''))))%m//11G%gt44444!(!2!2?F!2!S!SJ'' 333OOGL$6 BBB'')))OOD)444%,%6%6+V&7&&N''777OOGL)<<<'')))OOC3333(((((-- *''(9C(9(9:::: *''))))''(9C(9(9:::}B yAAA''))))!% 1 1%* = = O '..tU;;.|.M&&w///$$W---L%m//11G(/ $5% O#M-<>'7?#K#KKKKKKKK!LM%%''' =D'666$M)O"=O#M-<>'7?#K#KKKKKKKK0l0$$W---&/HGc 0c 0r))r%NrQTNN)rNr^rr^rVrOrYr6rr9r&r'r(r'r"r,)rVrWr"rWrF)rGrHrIrNrcrnrrrrrrrrrrrrrJrfrgr[rAr$r)r'r r sh  <)<< < i < : < n < K< [< (< < l< &< (< ?< #< #!<H&,++G $(,#(,(,AAAAA(u0u0u0u0u0u0r)r __main__z(Render Markdown to the console with Rich) descriptionpathPATHz%path to markdown file, or - for stdin)metavarhelpz-cz --force-color force_color store_truezforce color for non-terminals)destactionrrwz-tz --code-themerr%zpygments code theme)rzrrwz-iz--inline-code-lexerr&z-yz --hyperlinksrzenable hyperlinks)rzr{rwz-wz--widthrz*width of output (default will auto-detect))rrzrrwz-jz --justifyrVzenable full text justifyz-pz--pagepagezuse pager to scroll output)rrzutf-8)encodingfullrT)rVrrr&)fileforce_terminalrT)rrrecord)\ __future__rsys dataclassesrtypingrrr markdown_itrmarkdown_it.tokenr rich.tabler rlr _loopr _stackrr=rrrr containersrjupyterrrulersegmentrrYrrrrr2rrrrMrPrcrkrnrrrrrrrrrrr rr+r rGargparseArgumentParserrU add_argumentr parse_argsargs rich.consolertstdinread markdown_bodyopen markdown_filerVrrr&rr|iopydocStringIOfileiorxrprintpagergetvaluer$r)r'rs5"""""" !!!!!!//////////""""""######IIIIIIIIIIII######!!!!!!$$$$$$$$ 66666666r_     /     (   kD 24     _   &&&&&?&&&R                     o   ''''''''>/@'''''{'''T;%%%%% %%%P--------`w0w0w0w0w0|w0w0w0t zOOOJJJ $X $>F  4     ,     "              9     '     )      D$$$$$$ yC (( T$)g . . . 1-)..00M 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1x,2F??0 H y   '(8      h FOO%%&&&&&'+4:d     hsK88K<?K<