o
    i*                  	   @   s   d Z ddlZddlmZmZmZ erddlmZ ddeded d	ed
e	fddZ
de	dB d
e	fddZde	dB d
e	dB fddZde	dB d
e	fddZdS )znMarkup and format conversion utilities.

Pure utility layer for text processing across help and docs systems.
    N)TYPE_CHECKINGAnyOptionalConsoleFobjconsoler   preserve_markupreturnc              	   C   s  | du rdS t | dr(t| dd}|dur(|r!t |dr!|j S t|||dS t | dr2| j S |r>t | dr>| j S t | dr|dd	lm} |t	 |rR|j
nd
dddddd}| }|j| dd W d   n1 sqw   Y  |  S t|  S )a  Extract text from Rich renderables or any object.

    Parameters
    ----------
    obj : Any
        Object to convert to text.
    console : Console | None
        Console for rendering Rich objects.
    preserve_markup : bool
        If True, preserve original markdown/RST markup when available.
        When False, always render to plain text.

    Returns
    -------
    str
        Text representation (plain or with markup preserved).
    N primary_renderablemarkup)r	   plain__rich_console__r   r   x   FT)filewidthforce_terminalno_color	highlightr   emoji)end)hasattrgetattrr   rstripextract_textr   rich.consoler   ioStringIOr   captureprintgetstr)r   r   r	   primaryr   plain_consoler    r%   V/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/cyclopts/_markup.pyr      s8   






	r   textc                 C   s   | sdS |  ddS )zEscape special reStructuredText characters in text.

    Parameters
    ----------
    text : str | None
        Text to escape. Can be None.

    Returns
    -------
    str
        Escaped text safe for RST.
    r   \z\\replacer'   r%   r%   r&   
escape_rstB   s   r,   c                    s2    s S t  fdddD r S  dd  S )a  Escape special markdown characters in text.

    If the text appears to already contain markdown formatting (bold, italic,
    code, links, or headings), it is returned unchanged. Otherwise, pipe
    characters are escaped for table compatibility.

    Parameters
    ----------
    text : str | None
        Text to escape. Can be None.

    Returns
    -------
    str | None
        Escaped text safe for markdown, or None if input was None.
    c                 3   s    | ]}| v V  qd S )Nr%   ).0patternr+   r%   r&   	<genexpr>h   s    z"escape_markdown.<locals>.<genexpr>)z**z```z](#|z\|)anyr*   r+   r%   r+   r&   escape_markdownT   s   r4   c                 C   sH   | sdS |  dd} |  dd} |  dd} |  dd	} |  d
d} | S )zEscape special HTML characters in text.

    Parameters
    ----------
    text : str | None
        Text to escape. Can be None.

    Returns
    -------
    str
        Escaped text safe for HTML.
    r   &z&amp;<z&lt;>z&gt;"z&quot;'z&#x27;r)   r+   r%   r%   r&   escape_htmlo   s   r:   )NF)__doc__r   typingr   r   r   r   r   boolr"   r   r,   r4   r:   r%   r%   r%   r&   <module>   s     5