
    k7iHB                         S r SSKJr  SSKJr  SSKJr  \(       a  SSKJr   SSSS\	S	\
S
\\\
\
S4      4S jjr SS\\
   S\\\
\
S4      S\S\
S-  S
S4
S jjr      SSSS\	S\	S\S\\
   S-  S\	S\	S
\
4S jjrg)z5Documentation generation functions for cyclopts apps.    )TYPE_CHECKING)extract_text)BaseDocGenerator)Appappr   include_hiddenprefixreturnc                 .   / nU R                   (       d  U$ [        R                  " X5       He  u  pEU(       a  U U 3OUnUR                  SS5      R	                  5       nUR                  XgU45        [        XQU S3S9nUR                  U5        Mg     U$ )zoRecursively collect all commands for table of contents.

Returns a list of (display_name, anchor, app) tuples.
 -)r   r	   )	_commandsr   iterate_commandsreplacelowerappend_collect_commands_for_tocextend)	r   r   r	   commandsnamesubappdisplay_nameanchornesteds	            P/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/docs/markdown.pyr   r      s     H==(99#N,2&$(%%c3/557v67 +6\h[iijYkl O O    Nlinesr   levelapp_namec           	      .   U H  u  pEnUR                  S5      nSU-  nUR                  5       S   n	U(       a  US:X  a  U SU 3n
OU(       a  U SU 3n
OUn
U
R                  5       R                  SS5      nU R	                  U SU	 SU S35        M     g	)
z-Generate TOC entries with proper indentation.r   z  r   r   z- [`z`](#)N)countsplitr   r   r   )r   r   r   r   r   r   _appdepthindentcmd_name	full_names              r   _generate_toc_entriesr*   '   s     '/"d""3'  %%'+
 
#*Al^4I#*Al^4I$I "**34xtH:T&;<) '/r   	recursiveheading_levelcommand_chaingenerate_tocflatten_commandsc                 "   SSK Jn  / nUc  / n[        R                  " X5      u  pnU(       a  SU
 S3OUnUR	                  SU-   SU 35        UR	                  S5        U R
                  R                  SS	S
9n[        R                  " X5      nU(       aG  US;   n[        USUS9nU(       a0  UR	                  UR                  5       5        UR	                  S5        U(       ag  U(       d`  U R                  (       aO  [        XS9nU(       a?  UR	                  S5        UR	                  S5        [        UUSU	S9  UR	                  S5        [        R                  " U 5      nU(       a  UR	                  S5        UR	                  S5        UR	                  S5        [        U[        5      (       a  UnO[        USSS9n[        R                   " UUSS9nUR	                  U5        UR	                  S5        UR	                  S5        U R#                  / U5      n[        R$                  " UU5      nUS   nUS   nUS   nUS   nU" US-   USS9nU(       a  UR	                  S5        U H_  u  nnUR'                  5         SUl        U" SSU5        UR+                  5       R                  5       nU(       d  MN  UR	                  U5        Ma     UR	                  S5        U(       a  UR	                  S5        U H_  u  nnUR'                  5         SUl        U" SSU5        UR+                  5       R                  5       nU(       d  MN  UR	                  U5        Ma     UR	                  S5        U(       a  U H  u  nnUR(                  (       d  M  UR	                  SUR(                   S 35        UR'                  5         UR-                  SUR.                  UR0                  UR2                  S!9nU" SSU5        UR+                  5       R                  5       nU(       a  UR	                  U5        UR	                  S5        M     U(       a  UR	                  S"5        U H_  u  nnUR'                  5         SUl        U" SSU5        UR+                  5       R                  5       nU(       d  MN  UR	                  U5        Ma     UR	                  S5        U R                  (       Ga  [        R4                  " X5       GH  u  n n![        R6                  " UU U	5      n"U(       a  Un#OUS-   n#UR	                  SU#-   S#SR9                  U"5       S35        UR	                  S5        U!R                  U!/5         U!R
                  R                  SUS
9n$U$S;   n%[        R                  " U!U$5      n&U&(       aB  [        U&SU%S9n'U'(       a0  UR	                  U'R                  5       5        UR	                  S5        [        R                  " U!5      n(U((       a  UR	                  S5        UR	                  S5        UR	                  S5        [        U([        5      (       a  U(n)O[        U(SSS9n)[        R                   " U)U"SS9nUR	                  U5        UR	                  S5        UR	                  S5        U(       Ga  U!R#                  / U$5      n*[        R$                  " U*U5      n+U+S   n,U+S   n-U+S   n.U+S   n/U(       a  US-   n0OUS$-   n0U" U0USS9n1U,(       a  UR	                  S5        U, HX  u  nnU1R'                  5         U1" SSU5        U1R+                  5       R                  5       nU(       d  MG  UR	                  U5        MZ     UR	                  S5        U-(       a  UR	                  S5        U- HX  u  nnU1R'                  5         U1" SSU5        U1R+                  5       R                  5       nU(       d  MG  UR	                  U5        MZ     UR	                  S5        U.(       a  U. H  u  nnUR(                  (       d  M  UR	                  SUR(                   S 35        U1R'                  5         UR-                  SUR.                  UR0                  UR2                  S!9nU1" SSU5        U1R+                  5       R                  5       nU(       a  UR	                  U5        UR	                  S5        M     U/(       Ga?  U=(       a    U!R                  n2U2(       a  UR	                  S"5        U/ Hz  u  nnUR.                   Hd  n3U3R:                  (       d  M  U3R:                  S   n4U3R2                  (       a  [        U3R2                  SU%S9OSnUR	                  S%U4 S&U 35        Mf     M|     UR	                  S5        OUR	                  S"5        U/ HX  u  nnU1R'                  5         U1" SSU5        U1R+                  5       R                  5       nU(       d  MG  UR	                  U5        MZ     UR	                  S5        SSS5        U(       d  GMR  U!R                  (       d  GMf  [        R4                  " U!U5       H^  u  n5n6[        R6                  " U"U5U	5      n7U(       a  Un8OUS-   n8[=        U6UUU8U7SUS'9n9UR	                  U95        UR	                  S5        M`     GM     S(R9                  U5      R?                  5       S(-   n:U:$ ! , (       d  f       N= f))aR  Generate markdown documentation for a CLI application.

Parameters
----------
app : App
    The cyclopts App instance to document.
recursive : bool
    If True, generate documentation for all subcommands recursively.
    Default is True.
include_hidden : bool
    If True, include hidden commands/parameters in documentation.
    Default is False.
heading_level : int
    Starting heading level for the main application title.
    Default is 1 (single #).
command_chain : list[str]
    Internal parameter to track command hierarchy.
    Default is None.
generate_toc : bool
    If True, generate a table of contents for multi-command apps.
    Default is True.
flatten_commands : bool
    If True, generate all commands at the same heading level instead of nested.
    Default is False.

Returns
-------
str
    The generated markdown documentation.
r   )MarkdownFormatterN`#r    help_formatrestructuredtext)fallback)markdownmd)preserve_markup)r   z## Table of Contents)r   r   z
**Usage**:z
```consoleF$)r	   z```r   	argumentsoptionsgrouped   list)r,   r   table_stylez**Arguments**:
z**Options**:
z**z**:
)titleentriesformatdescriptionz**Commands**:
z `   z* `z`: )r+   r   r,   r-   r.   r/   
) !cyclopts.help.formatters.markdownr1   r   get_app_infor   	app_stackresolveextract_descriptionr   stripr   r   r*   extract_usage
isinstancestrformat_usage_line_assemble_help_panelscategorize_panelsresetrB   
get_output	__class__rC   rD   rE   r   build_command_chainjoinnamesgenerate_markdown_docsrstrip);r   r+   r   r,   r-   r.   r/   r1   r   r   full_command
base_titlerB   r5   rE   preserve	desc_texttoc_commandsusage
usage_text
usage_linehelp_panels_with_groupscategorizedcommand_panelsargument_panelsoption_panelsgrouped_panels	formatter_grouppaneloutput
panel_copyr   r   sub_command_chainsub_heading_levelsub_help_formatpreserve_subsub_descriptionsub_desc_text	sub_usagesub_usage_text
sub_panelssub_categorizedsub_argument_panelssub_option_panelssub_grouped_panelssub_command_panelspanel_heading_levelsub_formatterwill_recurseentryr(   nested_name
nested_appnested_command_chainnested_heading_levelnested_docsdocs;                                                              r   rZ   rZ   B   s	   N D E  *:)F)Fs)Z&HJ#0a~QjE 
LLC-'(%12	LL --''@R'SK"66sHK "44 dHM	LL*+LL Mcmm0TLL/0LL!%QRLL **3/E\"R\"eS!!J%eT5IJ%77
MZ]^
Z UR "77KH #445Ln]K ,N!+.O	*M +N "#a'%I '(,MFEOOEKdD%())+113FvV$ - 	R %&*MFEOOEKdD%())+113FvV$ + 	R +MFE{{{r%++e45!"__!MM << % 1 1	 - 
 $j1"--/557LL(R  ," &'+MFEOOEKdD%())+113FvV$ , 	R }}} -==cRLD& 0 D D]TXZb c  $1!$1A$5! LLC"334Bsxx@Q7R6SSTUVLL !!6(+"("2"2":":=S^":"_.2DD"2"F"Fv"_"$0$Xd$eM$]%8%8%:;R( -::6B	LL.LL$LL.!)S11)2)5iW\)]!1!C!CNTenq!rJLL,LL'LL$ !'!=!=b/!RJ '7&H&HUc&dO*9+*F'(7	(B%)8)C&)8)D& (.;a.?+.;a.?+$5&9.fl%M
 +%78-@MFE)//1)$e<%2%=%=%?%E%E%GF%v %V 4 .A R( )%56->MFE)//1)$e<%2%=%=%?%E%E%GF%v %V 4 .? R( *-?MFE${{{ %r%++e-D E - 3 3 5-2__*,,1MM+0<<050A0A	 .= ."
 !.dD* E)6)A)A)C)I)I)K#)$)LL$8 %R 0 .@" *'0'EV5E5E'!LL):;1C-2]]E',{{{38;;q> 05/@/@ -99J9JDbn,o13 )2
 ).s8*C	{5S(T .; 2D "LL, "LL):;1C - 3 3 5 -dD% @)6)A)A)C)I)I)K#)6$)LL$8 2D "LL,g ,l yV---/?/P/PQWYg/h+K+;+O+O);,( (/<,/<q/@,"8""+'5&:&:%*)9#K LL-LL$- 0iM S~ ))E

!
!
#d
*CJc ,+s/   2G8l .Bl 5Al =Dl B>l &l  
l	)Fr4   )r   N)TFr?   NTF)__doc__typingr   cyclopts._markupr   cyclopts.docs.baser   cyclopts.corer   boolrP   r@   tupler   intr*   rZ    r   r   <module>r      s   ;   ) /! =?	 $69	%S%
 !8 fj=9= $U3U?%; <=EH=X[^bXb=	=:  &*"K	KK K 	K
 9t#K K K 	Kr   