
    lKjy                        d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZ erddlmZ 	 	 	 	 	 	 d/dd	d
ededee   dz  dee   dz  dee   dz  dedeeed	f      fdZdee   deeed	f      ddfdZd0dd	d
edeed	f   fdZd0dee   dededdfdZdd	dedee   ddfdZ 	 d1dd	dee   dee   dedz  ddf
dZ!dd	ded
edee   dz  dee   dz  dedee   ddfdZ"dee   ddfd Z#d!ed"eed	f   dee   d#e$e   dz  d$e$e   dz  defd%Z%	 	 	 	 	 	 	 	 	 	 	 	 	 d2dd	d&ed
ed'e&d(e&dee   dz  d)ed*edee   dz  dee   dz  d+ed,ed-ededz  defd.Z'y)3z5Documentation generation functions for cyclopts apps.    )TYPE_CHECKING)extract_text)DEFAULT_FORMAT)adjust_filters_for_subcommandapply_usage_namebuild_command_chainextract_descriptionextract_usageformat_usage_linegenerate_anchorget_app_infois_all_builtin_flagsiterate_commandsnormalize_command_filtersshould_include_commandshould_show_commands_listshould_show_usage)AppNappr   include_hiddenprefixcommands_filterexclude_commandsparent_pathskip_filtered_commandreturnc           
      6   g }|g }t        ||      \  }}	t        | |      D ]t  \  }
}t        |
|||	|      s|xr |j                  }|s|r| |
 n|
}|j	                  ||f       ||
gz   }| |
 d}t        ||||||d      }|j                  |       v |S )zoRecursively collect all commands for table of contents.

    Returns a list of (display_name, app) tuples.
     F)r   r   r   r   r   r   )r   r   r   	_commandsappend_collect_commands_for_tocextend)r   r   r   r   r   r   r   commandsnormalized_commands_filternormalized_exclude_commandsnamesubappskip_this_commanddisplay_namenested_pathnested_prefixnesteds                    g/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/cyclopts/docs/markdown.pyr!   r!      s     H>W)?; ; )n=f%+9;VX^
  2Ff6F6F 06fXdV,DLOO\623 "TF*!(4&**) +-#"'
 	7 >: O    linesr#   c           	          i }|D ]w  \  }}|j                  d      dz
  }d|z  }|j                         d   }t        |      }||v r||xx   dz  cc<   | d||    }nd||<   | j                  | d| d| d	       y y
)zGenerate TOC entries with proper indentation.

    Parameters
    ----------
    lines : list[str]
        List to append TOC entries to.
    commands : list[tuple[str, "App"]]
        List of (display_name, app) tuples.
    r      z    _r   z- [``](#)N)countsplitr   r    )	r/   r#   anchor_countsr)   _appdepthindentcmd_nameanchors	            r-   _generate_toc_entriesr>   R   s     %'M&d""3'!+%%%'+ .]"&!Q&!xqv!6 78F$%M&!xtH:T&;< 'r.   c                 T    i }| j                   rt        | |      D ]
  \  }}|||<    |S )a/  Build mapping of command names to App objects.

    Parameters
    ----------
    app : App
        The app to extract commands from.
    include_hidden : bool
        Whether to include hidden commands.

    Returns
    -------
    dict[str, App]
        Mapping of command names to App instances.
    )r   r   )r   r   command_mapr&   r'   s        r-   _build_command_maprA   n   s6     K
}},S.ALD& &K Br.   content	add_blankc                 R    |r| j                  |       |r| j                  d       yy)a  Append content to lines if present, optionally adding blank line.

    Parameters
    ----------
    lines : list[str]
        List to append to.
    content : str
        Content to append (only if non-empty).
    add_blank : bool
        Whether to add a blank line after content.
     N)r    )r/   rB   rC   s      r-   _append_if_presentrF      s'     WR r.   help_formatc                     t        | |      }|rF|dv }t        |d|      }|r1|j                  |j                                |j                  d       yyy)a  Extract and render app description.

    Parameters
    ----------
    app : App
        The app to extract description from.
    help_format : str
        Help format (e.g., "markdown", "rich").
    lines : list[str]
        List to append description to.
    markdownmdNpreserve_markuprE   )r	   r   r    strip)r   rG   r/   descriptionpreserve	desc_texts         r-   _render_description_sectionrR      sX     &c;7K"44 dHM	LL*+LL 	 r.   command_chain
usage_namec                 2   t        |       rt        |       }|r~|j                  d       t        |t              r|}nt        |dd      }t        ||      }t        ||      }|j                  |       |j                  d       |j                  d       yyy)aS  Render usage console block.

    Parameters
    ----------
    app : App
        The app to extract usage from.
    command_chain : list[str]
        Command chain for usage line.
    lines : list[str]
        List to append usage to.
    usage_name : str | None
        Optional replacement for the chain's root in Usage: lines only.
    z
```consoleNFrL   z```rE   )r   r
   r    
isinstancestrr   r   r   )r   rS   r/   rT   usage
usage_textdisplay_chain
usage_lines           r-   _render_usage_sectionr\      s    & c"LL&%%"
)%uM
,]JGM*:}EJLL$LLLL  r.   app_namec                     t        | ||r| dnd|||      }|r@|j                  d       |j                  d       t        ||       |j                  d       yy)a  Generate and render table of contents.

    Parameters
    ----------
    app : App
        The app to generate TOC for.
    app_name : str
        Application name for TOC prefixes.
    include_hidden : bool
        Whether to include hidden commands.
    commands_filter : list[str] | None
        Commands to include.
    exclude_commands : list[str] | None
        Commands to exclude.
    skip_filtered_command : bool
        Whether to skip the single filtered command in TOC.
    lines : list[str]
        List to append TOC to.
    r   rE   )r   r   r   r   r   z## Table of ContentsN)r!   r    r>   )r   r]   r   r   r   r   r/   toc_commandss           r-   _render_tocr`      sc    : -%!)(1~r')3L +,Re\2R	 r.   c                 8   |j                          | j                  d      } |dd|       |j                         j                         }|rN| j                  r|j                  d| j                   d       |j                  |       |j                  d       yy)a  Render a parameter panel as-is.

    Parameters
    ----------
    panel : HelpPanel
        The parameter panel to render.
    formatter : MarkdownFormatter
        Formatter to use for rendering.
    lines : list[str]
        List to append rendered content to.
    rE   )titleN****:
)resetcopy
get_outputrN   rb   r    )panel	formatterr/   
panel_copyoutputs        r-   _render_parameter_panelrl      s     OO"%JdD*%!!#))+F ;;LL2ekk]%01VR	 r.   entriesr@   normalized_filternormalized_excludec                     g }| D ]j  }|j                   s|j                   d   }|j                  |      }||5|8|j                  |       Jt        |||||      sZ|j                  |       l |S )a  Filter command entries based on inclusion/exclusion rules.

    Parameters
    ----------
    entries : list
        Command entries to filter.
    command_map : dict[str, App]
        Mapping of command names to App objects.
    parent_path : list[str]
        Parent command path.
    normalized_filter : set[str] | None
        Normalized filter set.
    normalized_exclude : set[str] | None
        Normalized exclude set.

    Returns
    -------
    list
        Filtered command entries.
    r   )namesgetr    r   )	rm   r@   r   rn   ro   filtered_entriesentryr<   r'   s	            r-   _filter_command_entriesru     s    6 ;;{{1~H __X.F~$,1C1K$++E2 *(KARTfhno$++E2  r.   	recursiveheading_levelmax_heading_levelgenerate_tocflatten_commandsno_root_titlecode_block_titleskip_preamblec                    ddl m} g }|g }d}nd}|xr |duxr t        |      dk(  }t        | |      \  }}}|r|rd| dn|}n|}|s:|
r|s6t	        ||      }|j                  d|z   d	|        |j                  d
       | j                  j                  dt              }|s|st        | |||       |s|st        | ||       |r|s| j                  rt        | ||||	||       |s| j                  | g      5  | j                  g |      }ddd       t        ||	      \  }}g }t        | d      } ||dz   |d      }D ]d  \  }}|s|r|j                   s|j"                  dk(  r|j$                  D  cg c]'  } | j&                  rt)        | | j&                        r&| ) }!} |!sgt+        |!||||      }"|"sy|j,                  r|j                  d|j,                   d       |"D ]  }#|#j&                  s|#j&                  d   }$| d	|$ }%t/        |%      }&|#j0                  rt3        |#j0                  dd      nd
}'|'r|j                  d|$ d|& d|'        t|j                  d|$ d|& d        |j                  d
       G|j"                  dk(  sXt5        |||       g nt        ||	      \  }}g }| j                  rt7        | |      D ]  \  }(})t9        |(||||)      st;        ||(|      }*|r|}+n|
r|s|}+n|dz   }+|duxr t        |      dk(  },|,xr |duxr |(|d   k(  }-|,xr |duxr |d   j=                  |(dz         }.|xr |-}/|xr |xr |.}0|xr |-}1|/sS|0sQd	j?                  |*      }2|rd|2 dn|2}3t	        |+|      }4|j                  d|4z   d	|3        |j                  d
       |1xs |0}5|)j                  | |)g      5  |)j                  j                  d|      }6|6dv }7|5st        |)|*||       t        |)|6|       |r&|)j                  g |6      }8tA        |(||      \  }9}:t        |9|:      \  };}<t        |)d      }=g }>|r|dz   }?n|dz   }? ||?|d      }@|xr |)j                  }A|8D ]  \  }}|s|r|j                   s|j"                  dk(  rstC        |)      rg|j$                  D  cg c]'  } | j&                  rt)        |)| j&                        r&| ) }B} |BssArg }!BD ]  }#|#j&                  s|#j&                  d   }$|=jE                  |$      }C|Crt9        |$|>|;|<C      sB|#j0                  rt3        |#j0                  d|7      nd
}'d	j?                  |*|$gz         }%t/        |%      }&|'r|!j                  d|$ d|& d|'        |!j                  d|$ d|& d        |!s=|j,                  r|j                  d|j,                   d       |jG                  |!       |j                  d
       g }"BD ]R  }#|#j&                  s|#j&                  d   }$|=jE                  |$      }C|Crt9        |$|>|;|<C      sB|"j                  |#       T |"s|j,                  r|j                  d|j,                   d       @jI                          |jK                  d
|"|j"                  |j0                        }D |@dd|D       |@jM                         jO                         }E|Er|j                  E       |j                  d
       |j"                  dk(  st5        |@|        |r1|)j                  r$tA        |(||      \  }F}Gt        |F|G      \  }H}Ig }Jt7        |)|      D ]  \  }K}Lt9        |KJHI|L      st;        |*K|      }M|r|}Nn
|/r|+}Nn|+dz   }NHrtA        KHI      \  }O}Pnd}O|xr Fduxr t        F      dk(  xr KFd   k(  }Q|xr- Fduxr' t        F      dk(  xr Fd   j=                  Kdz         }RLj                  |)|Lg      5  tQ        L||N|Md|OGR|Qxs R|      }Sddd       |j                  S       |j                  d
        ddd        dj?                  |      jS                         dz   }Tddl*}U|UjW                  d d!|T      }T|TS # 1 sw Y   xY wc c} w c c} w # 1 sw Y   xY w# 1 sw Y   xY w)"au  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 #).
    max_heading_level : int
        Maximum heading level to use. Headings deeper than this will be capped
        at this level. Standard Markdown supports levels 1-6.
        Default is 6.
    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.
    commands_filter : list[str] | None
        If specified, only include commands in this list.
        Supports nested command paths like "db.migrate".
        Default is None (include all commands).
    exclude_commands : list[str] | None
        If specified, exclude commands in this list.
        Supports nested command paths like "db.migrate".
        Default is None (no exclusions).
    no_root_title : bool
        If True, skip the root application title. Used for plugin contexts.
        Default is False.
    skip_preamble : bool
        If True, skip the description and usage sections for the target command
        when filtering to a single command via ``commands_filter``.
        Useful when the user provides their own section introduction.
        Default is False.
    usage_name : str | None
        Optional replacement for the root app name used in ``Usage:`` lines
        only. Headings and TOC anchors still use ``app.name[0]``.
        Default is None (use ``app.name[0]`` as before).

    Returns
    -------
    str
        The generated markdown documentation.
    r   )MarkdownFormatterNTFr1   `#r   rE   rG   )fallback)rT   )r   list)rw   r   table_stylecommandrc   rd   rL   z* [`r4   z): r5   	parameter.rI      )rb   rm   formatrO   )rv   r   rw   rx   rS   ry   rz   r   r   r{   r|   r}   rT   
z\n{3,}z

),!cyclopts.help.formatters.markdownr   lenr   minr    	app_stackresolver   r\   rR   r   r`   _assemble_help_panelsr   rA   showr   rm   rq   r   ru   rb   r   rO   r   rl   r   r   r   
startswithjoinr   r   rr   r"   re   	__class__rg   rN   generate_markdown_docsrstripresub)Vr   rv   r   rw   rx   rS   ry   rz   r   r   r{   r|   r}   rT   r   r/   is_rootskip_current_levelr]   full_command
base_titlerb   effective_levelrG   help_panels_with_groupsr$   r%   r   r@   ri   grouprh   ecommand_entriesrs   rt   r<   full_cmd_pathr=   rQ   r&   r'   sub_command_chainsub_heading_levelis_single_filteris_exact_targetis_intermediate_pathskip_this_command_titleskip_intermediateskip_target_preambler)   display_fmteffective_sub_levelskip_this_preamblesub_help_formatpreserve_sub
sub_panelssub_commands_filter_for_panelsub_exclude_commands_for_panelnormalized_sub_filter_panelnormalized_sub_exclude_panelsub_command_mapnested_parent_path_for_panelpanel_heading_levelsub_formatterwill_recursecommand_entries_listsub_cmd_appfiltered_panelrk   sub_commands_filtersub_exclude_commandsnormalized_sub_filternormalized_sub_excludenested_parent_pathnested_name
nested_appnested_command_chainnested_heading_levelnested_commands_filterr3   nested_is_targetnested_is_intermediatenested_docsdocr   sV                                                                                         r-   r   r   ?  s
   L D E !^_D%@^SEY]^E^ *6c=)I&HlJ '7!L>#\  }m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>.XBX+5+K H$ [1R(} 4\a 10g BH ))E

!
!
#d
*C 
&&FC
(CJk
 "!8 #uf4P HGw 10sx    b??'c'cC/c"'c
3c
7c"B1c"A"c")Ac"2Cc"5C:c"/c	,c"?c	c"cc""c,	)FrE   NNNF)T)N)TFr1      NTFNNFFFN)(__doc__typingr   cyclopts._markupr   cyclopts.corer   cyclopts.docs.baser   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   boolrW   r   tupler!   r>   dictrA   rF   rR   r\   r`   rl   setru   intr    r.   r-   <module>r      sf   ;   ) (   " !
 !(,)-$("'3	33 3 #Y%	3
 3i$&3 cT!3  3 
%U

3l=c =d5e;L6M =RV =8E 4 4U
CS ,d3i # $ RV $U  T#Y SW 4 "		9 9 d
	
 
D)	)) ) #Y%	)
 3i$&)  ) 9) 
)XT#Y 4 4((c5j!( c( 3x$	(
 C4( 
(Z  &*"(,)-"!M	MM M 	M
 M 9t#M M M #Y%M 3i$&M M M M d
M 	Mr.   