
    Ki$                     l    d Z ddlZddlmZmZmZ ddlmZmZ erddl	m
Z
mZ ddlmZmZ  G d d      Zy)	zHTML documentation formatter.    N)TYPE_CHECKINGAnyOptional)escape_htmlextract_text)ConsoleConsoleOptions)	HelpEntry	HelpPanelc            
          e Zd ZdZ	 	 	 	 ddedededz  dee   dz  fdZdd	Z	defd
Z
ded   ded   ddddfdZded   ded   ddfdZded   ded   ddfdZded   ded   deddfdZded   ded   deddfdZy)HtmlFormattera  HTML documentation formatter.

    Parameters
    ----------
    heading_level : int
        Starting heading level for panels (default: 2).
        E.g., 2 produces "<h2>Commands</h2>", 3 produces "<h3>Commands</h3>".
    include_hidden : bool
        Include hidden commands/parameters in documentation (default: False).
    app_name : str
        The root application name for generating anchor IDs.
    command_chain : list[str]
        The current command chain for generating anchor IDs.
    Nheading_levelinclude_hiddenapp_namecommand_chainc                 v    || _         || _        || _        |xs g | _        t	        j
                         | _        y N)r   r   r   r   ioStringIO_output)selfr   r   r   r   s        i/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/cyclopts/help/formatters/html.py__init__zHtmlFormatter.__init__   s5     +, *0b{{}    returnc                 6    t        j                         | _        y)z!Reset the internal output buffer.N)r   r   r   r   s    r   resetzHtmlFormatter.reset+   s    {{}r   c                 6    | j                   j                         S )zGet the accumulated HTML output.

        Returns
        -------
        str
            The HTML documentation string.
        )r   getvaluer   s    r   
get_outputzHtmlFormatter.get_output/   s     ||$$&&r   consoler   optionsr	   panelr   c           	         |j                   sy| j                  j                  d       |j                  rXt	        t        |j                  |            }| j                  j                  d| j                   d| d| j                   d       |j                  r@t	        t        |j                  |            }|r| j                  j                  d| d       |j                  d	k(  r| j                  |j                   |       n+|j                  d
k(  r| j                  |j                   |       | j                  j                  d       y)a_  Format and render a help panel as HTML.

        Parameters
        ----------
        console : Optional[Console]
            Console for rendering (used for extracting plain text).
        options : Optional[ConsoleOptions]
            Console rendering options (unused for HTML).
        panel : HelpPanel
            Help panel to render.
        Nz<section class="help-panel">
z<hz class="panel-title">z</hz>
z<div class="panel-description"></div>
command	parameterz</section>
)entriesr   writetitler   r   r   descriptionformat_format_command_panel_format_parameter_panel)r   r"   r#   r$   
title_text	desc_texts         r   __call__zHtmlFormatter.__call__9   s   " }} 	;< ;;$\%++w%GHJLLD$6$6#77LZLX[\`\n\n[oorst #L1B1BG$LMI""%DYKx#XY <<9$&&u}}g>\\[(((@>*r   r)   r
   c                    |sy| j                   j                  d       |D ]  }|j                  }|sd}n| j                  r|d   |dd }}| j                  rB| j                  |gz   }| j                   ddj                  |dd        j                         }	n| j                   d| j                         }	d|	 dt        |       d	}|r\d
j                  d |D              }
| d|
 d}n;|d   |dd }}dt        |       d}|r d
j                  d |D              }
| d|
 d}t        t        |j                  |            }| j                   j                  d| d       |r| j                   j                  d|        | j                   j                  d        | j                   j                  d       y)zFormat command entries as HTML.

        Parameters
        ----------
        entries : list[HelpEntry]
            Command entries to format.
        console : Optional[Console]
            Console for text extraction.
        Nz<ul class="commands-list">
 r      -z
<a href="#z"><code>z</code></a>, c              3   2   K   | ]  }t        |        y wr   r   .0ns     r   	<genexpr>z6HtmlFormatter._format_command_panel.<locals>.<genexpr>        +LqKN+L   z ()<code></code>c              3   2   K   | ]  }t        |        y wr   r9   r:   s     r   r=   z6HtmlFormatter._format_command_panel.<locals>.<genexpr>   r>   r?   <li><strong>	</strong>: </li>
</ul>
)
r   r*   all_optionsr   r   joinlowerr   r   r,   )r   r)   r"   entrynames	name_htmlprimary_namealiases
full_chain	anchor_idaliases_str	desc_htmls               r   r.   z#HtmlFormatter._format_command_panelc   s     	9: 	*E%%E	(-a%)g%%!%!3!3|n!DJ#'==/388JqrN3K2L M S S UI#'==/<. A G G II(8K<U;VVab	"&))+LG+L"LK#,+R}A >I ).a%)g$[%>$?wG	"&))+LG+L"LK#,+R}A >I#L1B1BG$LMILLi[	BC""R	{#34LLy);	*> 	9%r   c                    |sy| j                   j                  d       |D ]  }|j                  x}rdj                  d |D              }nd}| j                   j                  d| d       t	        |j
                  |      }|r'| j                   j                  dt        |              g }|j                  r|j                  d	       |j                  r7dj                  d
 |j                  D              }|j                  d| d       |j                  4t	        |j                  |      }	|j                  dt        |	       d       |j                  r7dj                  d |j                  D              }
|j                  d|
 d       |r.| j                   j                  ddj                  |       d       | j                   j                  d        | j                   j                  d       y)zFormat parameter entries as HTML.

        Parameters
        ----------
        entries : list[HelpEntry]
            Parameter entries to format.
        console : Optional[Console]
            Console for text extraction.
        Nz<ul class="parameters-list">
r7   c              3   :   K   | ]  }d t        |       d  ywrA   rB   Nr9   r:   s     r   r=   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>   s     %V1{1~.>g&F%V   r4   rD   rE   rF   z=<span class="metadata-item metadata-required">Required</span>c              3   L   K   | ]  }d t        t        |             d  ywrW   )r   str)r;   cs     r   r=   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>   s$     'eRS&SV1D0EW(M'es   "$zZ<span class="metadata-item metadata-choices"><span class="metadata-label">choices:</span> z</span>z`<span class="metadata-item metadata-default"><span class="metadata-label">default:</span> <code>z</code></span>c              3   :   K   | ]  }d t        |       d  ywrW   r9   )r;   es     r   r=   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>   s     $]!vk!n-=W%E$]rX   zR<span class="metadata-item metadata-env"><span class="metadata-label">env:</span> z!<span class="parameter-metadata">rG   rH   )r   r*   rI   rJ   r   r,   r   requiredappendchoicesdefaultenv_var)r   r)   r"   rL   rM   rN   descmetadata_itemschoices_strdefault_strenv_htmls              r   r/   z%HtmlFormatter._format_parameter_panel   s     	;< /	*E)))u) II%VPU%VV		 LLi[	BC   1 17;D""RD(9':#;<  N ~~%%&ef }}"ii'eW\WdWd'ee%%pq|p}  ~E  F
 }}(*5=='B%%v  xC  DO  xP  wQ  Q_  `
 }}99$]u}}$]]%%hiqhrryz
 ""%Frww~G^F__f#ghLLy)_/	*b 	9%r   usagec                 b   |rt        t        ||            }|r| j                  j                  d       |j	                         j                  d      s | j                  j                  d| d       n| j                  j                  d| d       | j                  j                  d       yyy)a.  Render the usage line as HTML.

        Parameters
        ----------
        console : Optional[Console]
            Console for text extraction.
        options : Optional[ConsoleOptions]
            Console rendering options (unused).
        usage : Any
            The usage line content.
        z<div class="usage-block">
zUsage:z<pre class="usage">Usage: z</pre>
z<pre class="usage">r&   N)r   r   r   r*   strip
startswith)r   r"   r#   rh   
usage_texts        r   render_usagezHtmlFormatter.render_usage   s    " $\%%ABJ""#@A!'')44X>LL&&)CJ<x'XYLL&&)<ZL'QR"":.  r   r,   c                 x    |r8t        t        ||            }|r | j                  j                  d| d       yyy)a6  Render the description as HTML.

        Parameters
        ----------
        console : Optional[Console]
            Console for text extraction.
        options : Optional[ConsoleOptions]
            Console rendering options (unused).
        description : Any
            The description content.
        z<div class="description">r&   N)r   r   r   r*   )r   r"   r#   r,   r1   s        r   render_descriptionz HtmlFormatter.render_description   sA    " #Lg$FGI""%>yk#RS  r   )   FNN)r   N)__name__
__module____qualname____doc__intboolrZ   listr   r   r!   r   r2   r.   r/   r   rm   ro    r   r   r   r      sX   " $#*.%% % *	%
 Cy4'%%'C '(+)$(+ *+(+ 	(+
 
(+T/&T+-> /&R[I\ /&ae /&bA&tK/@ A&8T]K^ A&cg A&F/)$/ *+/ 	/
 
/8T)$T *+T 	T
 
Tr   r   )rt   r   typingr   r   r   cyclopts._markupr   r   rich.consoler   r	   cyclopts.helpr
   r   r   rx   r   r   <module>r}      s+    # 	 / / 642yT yTr   